diff options
Diffstat (limited to 'sys/contrib/dev/acpica/compiler')
60 files changed, 44395 insertions, 0 deletions
diff --git a/sys/contrib/dev/acpica/compiler/aslanalyze.c b/sys/contrib/dev/acpica/compiler/aslanalyze.c new file mode 100644 index 0000000..ea4ee35 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslanalyze.c @@ -0,0 +1,569 @@ +/****************************************************************************** + * + * Module Name: aslanalyze.c - Support functions for parse tree walks + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <string.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslanalyze") + + +/******************************************************************************* + * + * FUNCTION: AnIsInternalMethod + * + * PARAMETERS: Op - Current op + * + * RETURN: Boolean + * + * DESCRIPTION: Check for an internal control method. + * + ******************************************************************************/ + +BOOLEAN +AnIsInternalMethod ( + ACPI_PARSE_OBJECT *Op) +{ + + if ((!ACPI_STRCMP (Op->Asl.ExternalName, "\\_OSI")) || + (!ACPI_STRCMP (Op->Asl.ExternalName, "_OSI"))) + { + return (TRUE); + } + + return (FALSE); +} + + +/******************************************************************************* + * + * FUNCTION: AnGetInternalMethodReturnType + * + * PARAMETERS: Op - Current op + * + * RETURN: Btype + * + * DESCRIPTION: Get the return type of an internal method + * + ******************************************************************************/ + +UINT32 +AnGetInternalMethodReturnType ( + ACPI_PARSE_OBJECT *Op) +{ + + if ((!ACPI_STRCMP (Op->Asl.ExternalName, "\\_OSI")) || + (!ACPI_STRCMP (Op->Asl.ExternalName, "_OSI"))) + { + return (ACPI_BTYPE_STRING); + } + + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: AnCheckId + * + * PARAMETERS: Op - Current parse op + * Type - HID or CID + * + * RETURN: None + * + * DESCRIPTION: Perform various checks on _HID and _CID strings. Only limited + * checks can be performed on _CID strings. + * + ******************************************************************************/ + +void +AnCheckId ( + ACPI_PARSE_OBJECT *Op, + ACPI_NAME Type) +{ + UINT32 i; + ACPI_SIZE Length; + + + /* Only care about string versions of _HID/_CID (integers are legal) */ + + if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL) + { + return; + } + + /* For both _HID and _CID, the string must be non-null */ + + Length = strlen (Op->Asl.Value.String); + if (!Length) + { + AslError (ASL_ERROR, ASL_MSG_NULL_STRING, + Op, NULL); + return; + } + + /* + * One of the things we want to catch here is the use of a leading + * asterisk in the string -- an odd construct that certain platform + * manufacturers are fond of. Technically, a leading asterisk is OK + * for _CID, but a valid use of this has not been seen. + */ + if (*Op->Asl.Value.String == '*') + { + AslError (ASL_ERROR, ASL_MSG_LEADING_ASTERISK, + Op, Op->Asl.Value.String); + return; + } + + /* _CID strings are bus-specific, no more checks can be performed */ + + if (Type == ASL_TYPE_CID) + { + return; + } + + /* For _HID, all characters must be alphanumeric */ + + for (i = 0; Op->Asl.Value.String[i]; i++) + { + if (!isalnum ((int) Op->Asl.Value.String[i])) + { + AslError (ASL_ERROR, ASL_MSG_ALPHANUMERIC_STRING, + Op, Op->Asl.Value.String); + return; + } + } + + /* + * _HID String must be one of these forms: + * + * "AAA####" A is an uppercase letter and # is a hex digit + * "ACPI####" # is a hex digit + * "NNNN####" N is an uppercase letter or decimal digit (0-9) + * # is a hex digit (ACPI 5.0) + */ + if ((Length < 7) || (Length > 8)) + { + AslError (ASL_ERROR, ASL_MSG_HID_LENGTH, + Op, Op->Asl.Value.String); + return; + } + + /* _HID Length is valid (7 or 8), now check the prefix (first 3 or 4 chars) */ + + if (Length == 7) + { + /* AAA####: Ensure the alphabetic prefix is all uppercase */ + + for (i = 0; i < 3; i++) + { + if (!isupper ((int) Op->Asl.Value.String[i])) + { + AslError (ASL_ERROR, ASL_MSG_UPPER_CASE, + Op, &Op->Asl.Value.String[i]); + return; + } + } + } + else /* Length == 8 */ + { + /* + * ACPI#### or NNNN####: + * Ensure the prefix contains only uppercase alpha or decimal digits + */ + for (i = 0; i < 4; i++) + { + if (!isupper ((int) Op->Asl.Value.String[i]) && + !isdigit ((int) Op->Asl.Value.String[i])) + { + AslError (ASL_ERROR, ASL_MSG_HID_PREFIX, + Op, &Op->Asl.Value.String[i]); + return; + } + } + } + + /* Remaining characters (suffix) must be hex digits */ + + for (; i < Length; i++) + { + if (!isxdigit ((int) Op->Asl.Value.String[i])) + { + AslError (ASL_ERROR, ASL_MSG_HID_SUFFIX, + Op, &Op->Asl.Value.String[i]); + break; + } + } +} + + +/******************************************************************************* + * + * FUNCTION: AnLastStatementIsReturn + * + * PARAMETERS: Op - A method parse node + * + * RETURN: TRUE if last statement is an ASL RETURN. False otherwise + * + * DESCRIPTION: Walk down the list of top level statements within a method + * to find the last one. Check if that last statement is in + * fact a RETURN statement. + * + ******************************************************************************/ + +BOOLEAN +AnLastStatementIsReturn ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + + /* Check if last statement is a return */ + + Next = ASL_GET_CHILD_NODE (Op); + while (Next) + { + if ((!Next->Asl.Next) && + (Next->Asl.ParseOpcode == PARSEOP_RETURN)) + { + return (TRUE); + } + + Next = ASL_GET_PEER_NODE (Next); + } + + return (FALSE); +} + + +/******************************************************************************* + * + * FUNCTION: AnCheckMethodReturnValue + * + * PARAMETERS: Op - Parent + * OpInfo - Parent info + * ArgOp - Method invocation op + * RequiredBtypes - What caller requires + * ThisNodeBtype - What this node returns (if anything) + * + * RETURN: None + * + * DESCRIPTION: Check a method invocation for 1) A return value and if it does + * in fact return a value, 2) check the type of the return value. + * + ******************************************************************************/ + +void +AnCheckMethodReturnValue ( + ACPI_PARSE_OBJECT *Op, + const ACPI_OPCODE_INFO *OpInfo, + ACPI_PARSE_OBJECT *ArgOp, + UINT32 RequiredBtypes, + UINT32 ThisNodeBtype) +{ + ACPI_PARSE_OBJECT *OwningOp; + ACPI_NAMESPACE_NODE *Node; + + + Node = ArgOp->Asl.Node; + + + /* Examine the parent op of this method */ + + OwningOp = Node->Op; + if (OwningOp->Asl.CompileFlags & NODE_METHOD_NO_RETVAL) + { + /* Method NEVER returns a value */ + + AslError (ASL_ERROR, ASL_MSG_NO_RETVAL, Op, Op->Asl.ExternalName); + } + else if (OwningOp->Asl.CompileFlags & NODE_METHOD_SOME_NO_RETVAL) + { + /* Method SOMETIMES returns a value, SOMETIMES not */ + + AslError (ASL_WARNING, ASL_MSG_SOME_NO_RETVAL, Op, Op->Asl.ExternalName); + } + else if (!(ThisNodeBtype & RequiredBtypes)) + { + /* Method returns a value, but the type is wrong */ + + AnFormatBtype (StringBuffer, ThisNodeBtype); + AnFormatBtype (StringBuffer2, RequiredBtypes); + + /* + * The case where the method does not return any value at all + * was already handled in the namespace cross reference + * -- Only issue an error if the method in fact returns a value, + * but it is of the wrong type + */ + if (ThisNodeBtype != 0) + { + sprintf (MsgBuffer, + "Method returns [%s], %s operator requires [%s]", + StringBuffer, OpInfo->Name, StringBuffer2); + + AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: AnIsResultUsed + * + * PARAMETERS: Op - Parent op for the operator + * + * RETURN: TRUE if result from this operation is actually consumed + * + * DESCRIPTION: Determine if the function result value from an operator is + * used. + * + ******************************************************************************/ + +BOOLEAN +AnIsResultUsed ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Parent; + + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_INCREMENT: + case PARSEOP_DECREMENT: + + /* These are standalone operators, no return value */ + + return (TRUE); + + default: + break; + } + + /* Examine parent to determine if the return value is used */ + + Parent = Op->Asl.Parent; + switch (Parent->Asl.ParseOpcode) + { + /* If/While - check if the operator is the predicate */ + + case PARSEOP_IF: + case PARSEOP_WHILE: + + /* First child is the predicate */ + + if (Parent->Asl.Child == Op) + { + return (TRUE); + } + return (FALSE); + + /* Not used if one of these is the parent */ + + case PARSEOP_METHOD: + case PARSEOP_DEFINITIONBLOCK: + case PARSEOP_ELSE: + + return (FALSE); + + default: + /* Any other type of parent means that the result is used */ + + return (TRUE); + } +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckForGpeNameConflict + * + * PARAMETERS: Op - Current parse op + * + * RETURN: None + * + * DESCRIPTION: Check for a conflict between GPE names within this scope. + * Conflict means two GPE names with the same GPE number, but + * different types -- such as _L1C and _E1C. + * + ******************************************************************************/ + +void +ApCheckForGpeNameConflict ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *NextOp; + UINT32 GpeNumber; + char Name[ACPI_NAME_SIZE + 1]; + char Target[ACPI_NAME_SIZE]; + + + /* Need a null-terminated string version of NameSeg */ + + ACPI_MOVE_32_TO_32 (Name, &Op->Asl.NameSeg); + Name[ACPI_NAME_SIZE] = 0; + + /* + * For a GPE method: + * 1st char must be underscore + * 2nd char must be L or E + * 3rd/4th chars must be a hex number + */ + if ((Name[0] != '_') || + ((Name[1] != 'L') && (Name[1] != 'E'))) + { + return; + } + + /* Verify 3rd/4th chars are a valid hex value */ + + GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16); + if (GpeNumber == ACPI_UINT32_MAX) + { + return; + } + + /* + * We are now sure we have an _Lxx or _Exx. + * Create the target name that would cause collision (Flip E/L) + */ + ACPI_MOVE_32_TO_32 (Target, Name); + + /* Inject opposite letter ("L" versus "E") */ + + if (Name[1] == 'L') + { + Target[1] = 'E'; + } + else /* Name[1] == 'E' */ + { + Target[1] = 'L'; + } + + /* Search all peers (objects within this scope) for target match */ + + NextOp = Op->Asl.Next; + while (NextOp) + { + /* + * We mostly care about methods, but check Name() constructs also, + * even though they will get another error for not being a method. + * All GPE names must be defined as control methods. + */ + if ((NextOp->Asl.ParseOpcode == PARSEOP_METHOD) || + (NextOp->Asl.ParseOpcode == PARSEOP_NAME)) + { + if (ACPI_COMPARE_NAME (Target, NextOp->Asl.NameSeg)) + { + /* Found both _Exy and _Lxy in the same scope, error */ + + AslError (ASL_ERROR, ASL_MSG_GPE_NAME_CONFLICT, NextOp, + Name); + return; + } + } + + NextOp = NextOp->Asl.Next; + } + + /* OK, no conflict found */ + + return; +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckRegMethod + * + * PARAMETERS: Op - Current parse op + * + * RETURN: None + * + * DESCRIPTION: Ensure that a _REG method has a corresponding Operation + * Region declaration within the same scope. Note: _REG is defined + * to have two arguments and must therefore be defined as a + * control method. + * + ******************************************************************************/ + +void +ApCheckRegMethod ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + ACPI_PARSE_OBJECT *Parent; + + + /* We are only interested in _REG methods */ + + if (!ACPI_COMPARE_NAME (METHOD_NAME__REG, &Op->Asl.NameSeg)) + { + return; + } + + /* Get the start of the current scope */ + + Parent = Op->Asl.Parent; + Next = Parent->Asl.Child; + + /* Search entire scope for an operation region declaration */ + + while (Next) + { + if (Next->Asl.ParseOpcode == PARSEOP_OPERATIONREGION) + { + return; /* Found region, OK */ + } + + Next = Next->Asl.Next; + } + + /* No region found, issue warning */ + + AslError (ASL_WARNING, ASL_MSG_NO_REGION, Op, NULL); +} diff --git a/sys/contrib/dev/acpica/compiler/aslbtypes.c b/sys/contrib/dev/acpica/compiler/aslbtypes.c new file mode 100644 index 0000000..d7140d2 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslbtypes.c @@ -0,0 +1,525 @@ +/****************************************************************************** + * + * Module Name: aslbtypes - Support for bitfield types + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslbtypes") + +/* Local prototypes */ + +static UINT32 +AnMapEtypeToBtype ( + UINT32 Etype); + + +/******************************************************************************* + * + * FUNCTION: AnMapArgTypeToBtype + * + * PARAMETERS: ArgType - The ARGI required type(s) for this + * argument, from the opcode info table + * + * RETURN: The corresponding Bit-encoded types + * + * DESCRIPTION: Convert an encoded ARGI required argument type code into a + * bitfield type code. Implements the implicit source conversion + * rules. + * + ******************************************************************************/ + +UINT32 +AnMapArgTypeToBtype ( + UINT32 ArgType) +{ + + switch (ArgType) + { + + /* Simple types */ + + case ARGI_ANYTYPE: + return (ACPI_BTYPE_OBJECTS_AND_REFS); + + case ARGI_PACKAGE: + return (ACPI_BTYPE_PACKAGE); + + case ARGI_EVENT: + return (ACPI_BTYPE_EVENT); + + case ARGI_MUTEX: + return (ACPI_BTYPE_MUTEX); + + case ARGI_DDBHANDLE: + /* + * DDBHandleObject := SuperName + * ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload + */ + return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE); + + /* Interchangeable types */ + /* + * Source conversion rules: + * Integer, String, and Buffer are all interchangeable + */ + case ARGI_INTEGER: + case ARGI_STRING: + case ARGI_BUFFER: + case ARGI_BUFFER_OR_STRING: + case ARGI_COMPUTEDATA: + return (ACPI_BTYPE_COMPUTE_DATA); + + /* References */ + + case ARGI_INTEGER_REF: + return (ACPI_BTYPE_INTEGER); + + case ARGI_OBJECT_REF: + return (ACPI_BTYPE_ALL_OBJECTS); + + case ARGI_DEVICE_REF: + return (ACPI_BTYPE_DEVICE_OBJECTS); + + case ARGI_REFERENCE: + return (ACPI_BTYPE_REFERENCE); + + case ARGI_TARGETREF: + case ARGI_FIXED_TARGET: + case ARGI_SIMPLE_TARGET: + return (ACPI_BTYPE_OBJECTS_AND_REFS); + + /* Complex types */ + + case ARGI_DATAOBJECT: + + /* + * Buffer, string, package or reference to a Op - + * Used only by SizeOf operator + */ + return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | + ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE); + + case ARGI_COMPLEXOBJ: + + /* Buffer, String, or package */ + + return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE); + + case ARGI_REF_OR_STRING: + return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE); + + case ARGI_REGION_OR_BUFFER: + + /* Used by Load() only. Allow buffers in addition to regions/fields */ + + return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT); + + case ARGI_DATAREFOBJ: + return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | + ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE); + + default: + break; + } + + return (ACPI_BTYPE_OBJECTS_AND_REFS); +} + + +/******************************************************************************* + * + * FUNCTION: AnMapEtypeToBtype + * + * PARAMETERS: Etype - Encoded ACPI Type + * + * RETURN: Btype corresponding to the Etype + * + * DESCRIPTION: Convert an encoded ACPI type to a bitfield type applying the + * operand conversion rules. In other words, returns the type(s) + * this Etype is implicitly converted to during interpretation. + * + ******************************************************************************/ + +static UINT32 +AnMapEtypeToBtype ( + UINT32 Etype) +{ + + + if (Etype == ACPI_TYPE_ANY) + { + return (ACPI_BTYPE_OBJECTS_AND_REFS); + } + + /* Try the standard ACPI data types */ + + if (Etype <= ACPI_TYPE_EXTERNAL_MAX) + { + /* + * This switch statement implements the allowed operand conversion + * rules as per the "ASL Data Types" section of the ACPI + * specification. + */ + switch (Etype) + { + case ACPI_TYPE_INTEGER: + return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DDB_HANDLE); + + case ACPI_TYPE_STRING: + case ACPI_TYPE_BUFFER: + return (ACPI_BTYPE_COMPUTE_DATA); + + case ACPI_TYPE_PACKAGE: + return (ACPI_BTYPE_PACKAGE); + + case ACPI_TYPE_FIELD_UNIT: + return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT); + + case ACPI_TYPE_BUFFER_FIELD: + return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_BUFFER_FIELD); + + case ACPI_TYPE_DDB_HANDLE: + return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE); + + case ACPI_BTYPE_DEBUG_OBJECT: + + /* Cannot be used as a source operand */ + + return (0); + + default: + return (1 << (Etype - 1)); + } + } + + /* Try the internal data types */ + + switch (Etype) + { + case ACPI_TYPE_LOCAL_REGION_FIELD: + case ACPI_TYPE_LOCAL_BANK_FIELD: + case ACPI_TYPE_LOCAL_INDEX_FIELD: + + /* Named fields can be either Integer/Buffer/String */ + + return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_FIELD_UNIT); + + case ACPI_TYPE_LOCAL_ALIAS: + + return (ACPI_BTYPE_INTEGER); + + + case ACPI_TYPE_LOCAL_RESOURCE: + case ACPI_TYPE_LOCAL_RESOURCE_FIELD: + + return (ACPI_BTYPE_REFERENCE); + + default: + printf ("Unhandled encoded type: %X\n", Etype); + return (0); + } +} + + +/******************************************************************************* + * + * FUNCTION: AnFormatBtype + * + * PARAMETERS: Btype - Bitfield of ACPI types + * Buffer - Where to put the ascii string + * + * RETURN: None. + * + * DESCRIPTION: Convert a Btype to a string of ACPI types + * + ******************************************************************************/ + +void +AnFormatBtype ( + char *Buffer, + UINT32 Btype) +{ + UINT32 Type; + BOOLEAN First = TRUE; + + + *Buffer = 0; + + if (Btype == 0) + { + strcat (Buffer, "NoReturnValue"); + return; + } + + for (Type = 1; Type <= ACPI_TYPE_EXTERNAL_MAX; Type++) + { + if (Btype & 0x00000001) + { + if (!First) + { + strcat (Buffer, "|"); + } + First = FALSE; + strcat (Buffer, AcpiUtGetTypeName (Type)); + } + Btype >>= 1; + } + + if (Btype & 0x00000001) + { + if (!First) + { + strcat (Buffer, "|"); + } + First = FALSE; + strcat (Buffer, "Reference"); + } + + Btype >>= 1; + if (Btype & 0x00000001) + { + if (!First) + { + strcat (Buffer, "|"); + } + First = FALSE; + strcat (Buffer, "Resource"); + } +} + + +/******************************************************************************* + * + * FUNCTION: AnGetBtype + * + * PARAMETERS: Op - Parse node whose type will be returned. + * + * RETURN: The Btype associated with the Op. + * + * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node. + * Handles the case where the node is a name or method call and + * the actual type must be obtained from the namespace node. + * + ******************************************************************************/ + +UINT32 +AnGetBtype ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_NAMESPACE_NODE *Node; + ACPI_PARSE_OBJECT *ReferencedNode; + UINT32 ThisNodeBtype = 0; + + + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || + (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) + { + Node = Op->Asl.Node; + if (!Node) + { + DbgPrint (ASL_DEBUG_OUTPUT, + "No attached Nsnode: [%s] at line %u name [%s], ignoring typecheck\n", + Op->Asl.ParseOpName, Op->Asl.LineNumber, + Op->Asl.ExternalName); + return (ACPI_UINT32_MAX); + } + + ThisNodeBtype = AnMapEtypeToBtype (Node->Type); + if (!ThisNodeBtype) + { + AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, + "could not map type"); + } + + /* + * Since it was a named reference, enable the + * reference bit also + */ + ThisNodeBtype |= ACPI_BTYPE_REFERENCE; + + if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL) + { + ReferencedNode = Node->Op; + if (!ReferencedNode) + { + /* Check for an internal method */ + + if (AnIsInternalMethod (Op)) + { + return (AnGetInternalMethodReturnType (Op)); + } + + AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, + "null Op pointer"); + return (ACPI_UINT32_MAX); + } + + if (ReferencedNode->Asl.CompileFlags & NODE_METHOD_TYPED) + { + ThisNodeBtype = ReferencedNode->Asl.AcpiBtype; + } + else + { + return (ACPI_UINT32_MAX -1); + } + } + } + else + { + ThisNodeBtype = Op->Asl.AcpiBtype; + } + + return (ThisNodeBtype); +} + + +/******************************************************************************* + * + * FUNCTION: AnMapObjTypeToBtype + * + * PARAMETERS: Op - A parse node + * + * RETURN: A Btype + * + * DESCRIPTION: Map object to the associated "Btype" + * + ******************************************************************************/ + +UINT32 +AnMapObjTypeToBtype ( + ACPI_PARSE_OBJECT *Op) +{ + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_OBJECTTYPE_BFF: /* "BuffFieldObj" */ + return (ACPI_BTYPE_BUFFER_FIELD); + + case PARSEOP_OBJECTTYPE_BUF: /* "BuffObj" */ + return (ACPI_BTYPE_BUFFER); + + case PARSEOP_OBJECTTYPE_DDB: /* "DDBHandleObj" */ + return (ACPI_BTYPE_DDB_HANDLE); + + case PARSEOP_OBJECTTYPE_DEV: /* "DeviceObj" */ + return (ACPI_BTYPE_DEVICE); + + case PARSEOP_OBJECTTYPE_EVT: /* "EventObj" */ + return (ACPI_BTYPE_EVENT); + + case PARSEOP_OBJECTTYPE_FLD: /* "FieldUnitObj" */ + return (ACPI_BTYPE_FIELD_UNIT); + + case PARSEOP_OBJECTTYPE_INT: /* "IntObj" */ + return (ACPI_BTYPE_INTEGER); + + case PARSEOP_OBJECTTYPE_MTH: /* "MethodObj" */ + return (ACPI_BTYPE_METHOD); + + case PARSEOP_OBJECTTYPE_MTX: /* "MutexObj" */ + return (ACPI_BTYPE_MUTEX); + + case PARSEOP_OBJECTTYPE_OPR: /* "OpRegionObj" */ + return (ACPI_BTYPE_REGION); + + case PARSEOP_OBJECTTYPE_PKG: /* "PkgObj" */ + return (ACPI_BTYPE_PACKAGE); + + case PARSEOP_OBJECTTYPE_POW: /* "PowerResObj" */ + return (ACPI_BTYPE_POWER); + + case PARSEOP_OBJECTTYPE_STR: /* "StrObj" */ + return (ACPI_BTYPE_STRING); + + case PARSEOP_OBJECTTYPE_THZ: /* "ThermalZoneObj" */ + return (ACPI_BTYPE_THERMAL); + + case PARSEOP_OBJECTTYPE_UNK: /* "UnknownObj" */ + return (ACPI_BTYPE_OBJECTS_AND_REFS); + + default: + return (0); + } +} + + +#ifdef ACPI_OBSOLETE_FUNCTIONS +/******************************************************************************* + * + * FUNCTION: AnMapBtypeToEtype + * + * PARAMETERS: Btype - Bitfield of ACPI types + * + * RETURN: The Etype corresponding the the Btype + * + * DESCRIPTION: Convert a bitfield type to an encoded type + * + ******************************************************************************/ + +UINT32 +AnMapBtypeToEtype ( + UINT32 Btype) +{ + UINT32 i; + UINT32 Etype; + + + if (Btype == 0) + { + return (0); + } + + Etype = 1; + for (i = 1; i < Btype; i *= 2) + { + Etype++; + } + + return (Etype); +} +#endif diff --git a/sys/contrib/dev/acpica/compiler/aslcodegen.c b/sys/contrib/dev/acpica/compiler/aslcodegen.c new file mode 100644 index 0000000..d5ecdb3 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslcodegen.c @@ -0,0 +1,593 @@ + +/****************************************************************************** + * + * Module Name: aslcodegen - AML code generation + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslcodegen") + +/* Local prototypes */ + +static ACPI_STATUS +CgAmlWriteWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static void +CgLocalWriteAmlData ( + ACPI_PARSE_OBJECT *Op, + void *Buffer, + UINT32 Length); + +static void +CgWriteAmlOpcode ( + ACPI_PARSE_OBJECT *Op); + +static void +CgWriteTableHeader ( + ACPI_PARSE_OBJECT *Op); + +static void +CgCloseTable ( + void); + +static void +CgWriteNode ( + ACPI_PARSE_OBJECT *Op); + + +/******************************************************************************* + * + * FUNCTION: CgGenerateAmlOutput + * + * PARAMETERS: None. + * + * RETURN: None + * + * DESCRIPTION: Generate AML code. Currently generates the listing file + * simultaneously. + * + ******************************************************************************/ + +void +CgGenerateAmlOutput ( + void) +{ + + DbgPrint (ASL_DEBUG_OUTPUT, "\nWriting AML\n\n"); + + /* Generate the AML output file */ + + FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0); + Gbl_SourceLine = 0; + Gbl_NextError = Gbl_ErrorLog; + + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, + CgAmlWriteWalk, NULL, NULL); + CgCloseTable (); +} + + +/******************************************************************************* + * + * FUNCTION: CgAmlWriteWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Parse tree walk to generate the AML code. + * + ******************************************************************************/ + +static ACPI_STATUS +CgAmlWriteWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + + /* + * Print header at level 0. Alignment assumes 32-bit pointers + */ + if (!Level) + { + DbgPrint (ASL_TREE_OUTPUT, + "Final parse tree used for AML output:\n"); + DbgPrint (ASL_TREE_OUTPUT, + "%*s Value P_Op A_Op OpLen PByts Len SubLen PSubLen OpPtr Child Parent Flags AcTyp Final Col L\n", + 76, " "); + } + + /* Debug output */ + + DbgPrint (ASL_TREE_OUTPUT, + "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level); + UtPrintFormattedName (Op->Asl.ParseOpcode, Level); + + if (Op->Asl.ParseOpcode == PARSEOP_NAMESEG || + Op->Asl.ParseOpcode == PARSEOP_NAMESTRING || + Op->Asl.ParseOpcode == PARSEOP_METHODCALL) + { + DbgPrint (ASL_TREE_OUTPUT, + "%10.32s ", Op->Asl.ExternalName); + } + else + { + DbgPrint (ASL_TREE_OUTPUT, " "); + } + + DbgPrint (ASL_TREE_OUTPUT, + "%08X %04X %04X %01X %04X %04X %04X %04X %08X %08X %08X %08X %08X %04X %02d %02d\n", + /* 1 */ (UINT32) Op->Asl.Value.Integer, + /* 2 */ Op->Asl.ParseOpcode, + /* 3 */ Op->Asl.AmlOpcode, + /* 4 */ Op->Asl.AmlOpcodeLength, + /* 5 */ Op->Asl.AmlPkgLenBytes, + /* 6 */ Op->Asl.AmlLength, + /* 7 */ Op->Asl.AmlSubtreeLength, + /* 8 */ Op->Asl.Parent ? Op->Asl.Parent->Asl.AmlSubtreeLength : 0, + /* 9 */ Op, + /* 10 */ Op->Asl.Child, + /* 11 */ Op->Asl.Parent, + /* 12 */ Op->Asl.CompileFlags, + /* 13 */ Op->Asl.AcpiBtype, + /* 14 */ Op->Asl.FinalAmlLength, + /* 15 */ Op->Asl.Column, + /* 16 */ Op->Asl.LineNumber); + + /* Generate the AML for this node */ + + CgWriteNode (Op); + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: CgLocalWriteAmlData + * + * PARAMETERS: Op - Current parse op + * Buffer - Buffer to write + * Length - Size of data in buffer + * + * RETURN: None + * + * DESCRIPTION: Write a buffer of AML data to the AML output file. + * + ******************************************************************************/ + +static void +CgLocalWriteAmlData ( + ACPI_PARSE_OBJECT *Op, + void *Buffer, + UINT32 Length) +{ + + /* Write the raw data to the AML file */ + + FlWriteFile (ASL_FILE_AML_OUTPUT, Buffer, Length); + + /* Update the final AML length for this node (used for listings) */ + + if (Op) + { + Op->Asl.FinalAmlLength += Length; + } +} + + +/******************************************************************************* + * + * FUNCTION: CgWriteAmlOpcode + * + * PARAMETERS: Op - Parse node with an AML opcode + * + * RETURN: None. + * + * DESCRIPTION: Write the AML opcode corresponding to a parse node. + * + ******************************************************************************/ + +static void +CgWriteAmlOpcode ( + ACPI_PARSE_OBJECT *Op) +{ + UINT8 PkgLenFirstByte; + UINT32 i; + union { + UINT16 Opcode; + UINT8 OpcodeBytes[2]; + } Aml; + union { + UINT32 Len; + UINT8 LenBytes[4]; + } PkgLen; + + + /* We expect some DEFAULT_ARGs, just ignore them */ + + if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + return; + } + + switch (Op->Asl.AmlOpcode) + { + case AML_UNASSIGNED_OPCODE: + + /* These opcodes should not get here */ + + printf ("Found a node with an unassigned AML opcode\n"); + FlPrintFile (ASL_FILE_STDERR, "Found a node with an unassigned AML opcode\n"); + return; + + case AML_INT_RESERVEDFIELD_OP: + + /* Special opcodes for within a field definition */ + + Aml.Opcode = AML_FIELD_OFFSET_OP; + break; + + case AML_INT_ACCESSFIELD_OP: + + Aml.Opcode = AML_FIELD_ACCESS_OP; + break; + + case AML_INT_CONNECTION_OP: + + Aml.Opcode = AML_FIELD_CONNECTION_OP; + break; + + default: + Aml.Opcode = Op->Asl.AmlOpcode; + break; + } + + + switch (Aml.Opcode) + { + case AML_PACKAGE_LENGTH: + + /* Value is the length to be encoded (Used in field definitions) */ + + PkgLen.Len = (UINT32) Op->Asl.Value.Integer; + break; + + default: + + /* Check for two-byte opcode */ + + if (Aml.Opcode > 0x00FF) + { + /* Write the high byte first */ + + CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[1], 1); + } + + CgLocalWriteAmlData (Op, &Aml.OpcodeBytes[0], 1); + + /* Subtreelength doesn't include length of package length bytes */ + + PkgLen.Len = Op->Asl.AmlSubtreeLength + Op->Asl.AmlPkgLenBytes; + break; + } + + /* Does this opcode have an associated "PackageLength" field? */ + + if (Op->Asl.CompileFlags & NODE_AML_PACKAGE) + { + if (Op->Asl.AmlPkgLenBytes == 1) + { + /* Simplest case -- no bytes to follow, just write the count */ + + CgLocalWriteAmlData (Op, &PkgLen.LenBytes[0], 1); + } + else if (Op->Asl.AmlPkgLenBytes != 0) + { + /* + * Encode the "bytes to follow" in the first byte, top two bits. + * The low-order nybble of the length is in the bottom 4 bits + */ + PkgLenFirstByte = (UINT8) + (((UINT32) (Op->Asl.AmlPkgLenBytes - 1) << 6) | + (PkgLen.LenBytes[0] & 0x0F)); + + CgLocalWriteAmlData (Op, &PkgLenFirstByte, 1); + + /* + * Shift the length over by the 4 bits we just stuffed + * in the first byte + */ + PkgLen.Len >>= 4; + + /* Now we can write the remaining bytes - either 1, 2, or 3 bytes */ + + for (i = 0; i < (UINT32) (Op->Asl.AmlPkgLenBytes - 1); i++) + { + CgLocalWriteAmlData (Op, &PkgLen.LenBytes[i], 1); + } + } + } + + switch (Aml.Opcode) + { + case AML_BYTE_OP: + + CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 1); + break; + + case AML_WORD_OP: + + CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 2); + break; + + case AML_DWORD_OP: + + CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 4); + break; + + case AML_QWORD_OP: + + CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, 8); + break; + + case AML_STRING_OP: + + CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength); + break; + + default: + /* All data opcodes must appear above */ + break; + } +} + + +/******************************************************************************* + * + * FUNCTION: CgWriteTableHeader + * + * PARAMETERS: Op - The DEFINITIONBLOCK node + * + * RETURN: None + * + * DESCRIPTION: Write a table header corresponding to the DEFINITIONBLOCK + * + ******************************************************************************/ + +static void +CgWriteTableHeader ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Child; + + + /* AML filename */ + + Child = Op->Asl.Child; + + /* Signature */ + + Child = Child->Asl.Next; + strncpy (TableHeader.Signature, Child->Asl.Value.String, 4); + + /* Revision */ + + Child = Child->Asl.Next; + TableHeader.Revision = (UINT8) Child->Asl.Value.Integer; + + /* Command-line Revision override */ + + if (Gbl_RevisionOverride) + { + TableHeader.Revision = Gbl_RevisionOverride; + } + + /* OEMID */ + + Child = Child->Asl.Next; + strncpy (TableHeader.OemId, Child->Asl.Value.String, 6); + + /* OEM TableID */ + + Child = Child->Asl.Next; + strncpy (TableHeader.OemTableId, Child->Asl.Value.String, 8); + + /* OEM Revision */ + + Child = Child->Asl.Next; + TableHeader.OemRevision = (UINT32) Child->Asl.Value.Integer; + + /* Compiler ID */ + + strncpy (TableHeader.AslCompilerId, ASL_CREATOR_ID, 4); + + /* Compiler version */ + + TableHeader.AslCompilerRevision = ASL_REVISION; + + /* Table length. Checksum zero for now, will rewrite later */ + + TableHeader.Length = Gbl_TableLength; + TableHeader.Checksum = 0; + + CgLocalWriteAmlData (Op, &TableHeader, sizeof (ACPI_TABLE_HEADER)); +} + + +/******************************************************************************* + * + * FUNCTION: CgCloseTable + * + * PARAMETERS: None. + * + * RETURN: None. + * + * DESCRIPTION: Complete the ACPI table by calculating the checksum and + * re-writing the header. + * + ******************************************************************************/ + +static void +CgCloseTable ( + void) +{ + signed char Sum; + UINT8 FileByte; + + + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + Sum = 0; + + /* Calculate the checksum over the entire file */ + + while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1) == AE_OK) + { + Sum = (signed char) (Sum + FileByte); + } + + /* Re-write the table header with the checksum */ + + TableHeader.Checksum = (UINT8) (0 - Sum); + + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + CgLocalWriteAmlData (NULL, &TableHeader, sizeof (ACPI_TABLE_HEADER)); +} + + +/******************************************************************************* + * + * FUNCTION: CgWriteNode + * + * PARAMETERS: Op - Parse node to write. + * + * RETURN: None. + * + * DESCRIPTION: Write the AML that corresponds to a parse node. + * + ******************************************************************************/ + +static void +CgWriteNode ( + ACPI_PARSE_OBJECT *Op) +{ + ASL_RESOURCE_NODE *Rnode; + + + /* Always check for DEFAULT_ARG and other "Noop" nodes */ + /* TBD: this may not be the best place for this check */ + + if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) || + (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) || + (Op->Asl.ParseOpcode == PARSEOP_INCLUDE) || + (Op->Asl.ParseOpcode == PARSEOP_INCLUDE_END)) + { + return; + } + + Op->Asl.FinalAmlLength = 0; + + switch (Op->Asl.AmlOpcode) + { + case AML_RAW_DATA_BYTE: + case AML_RAW_DATA_WORD: + case AML_RAW_DATA_DWORD: + case AML_RAW_DATA_QWORD: + + CgLocalWriteAmlData (Op, &Op->Asl.Value.Integer, Op->Asl.AmlLength); + return; + + + case AML_RAW_DATA_BUFFER: + + CgLocalWriteAmlData (Op, Op->Asl.Value.Buffer, Op->Asl.AmlLength); + return; + + + case AML_RAW_DATA_CHAIN: + + Rnode = ACPI_CAST_PTR (ASL_RESOURCE_NODE, Op->Asl.Value.Buffer); + while (Rnode) + { + CgLocalWriteAmlData (Op, Rnode->Buffer, Rnode->BufferLength); + Rnode = Rnode->Next; + } + return; + + default: + /* Internal data opcodes must all appear above */ + break; + } + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_DEFAULT_ARG: + + break; + + case PARSEOP_DEFINITIONBLOCK: + + CgWriteTableHeader (Op); + break; + + case PARSEOP_NAMESEG: + case PARSEOP_NAMESTRING: + case PARSEOP_METHODCALL: + + CgLocalWriteAmlData (Op, Op->Asl.Value.String, Op->Asl.AmlLength); + break; + + default: + + CgWriteAmlOpcode (Op); + break; + } +} + + diff --git a/sys/contrib/dev/acpica/compiler/aslcompile.c b/sys/contrib/dev/acpica/compiler/aslcompile.c new file mode 100644 index 0000000..50eaf4e --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslcompile.c @@ -0,0 +1,890 @@ + +/****************************************************************************** + * + * Module Name: aslcompile - top level compile module + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> + +#include <stdio.h> +#include <time.h> +#include <contrib/dev/acpica/include/acapps.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslcompile") + +/* Local prototypes */ + +static void +CmFlushSourceCode ( + void); + +static void +FlConsumeAnsiComment ( + ASL_FILE_INFO *FileInfo, + ASL_FILE_STATUS *Status); + +static void +FlConsumeNewComment ( + ASL_FILE_INFO *FileInfo, + ASL_FILE_STATUS *Status); + + +/******************************************************************************* + * + * FUNCTION: AslCompilerSignon + * + * PARAMETERS: FileId - ID of the output file + * + * RETURN: None + * + * DESCRIPTION: Display compiler signon + * + ******************************************************************************/ + +void +AslCompilerSignon ( + UINT32 FileId) +{ + char *Prefix = ""; + char *UtilityName; + + + /* Set line prefix depending on the destination file type */ + + switch (FileId) + { + case ASL_FILE_ASM_SOURCE_OUTPUT: + case ASL_FILE_ASM_INCLUDE_OUTPUT: + + Prefix = "; "; + break; + + case ASL_FILE_HEX_OUTPUT: + + if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) + { + Prefix = "; "; + } + else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) || + (Gbl_HexOutputFlag == HEX_OUTPUT_ASL)) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n"); + Prefix = " * "; + } + break; + + case ASL_FILE_C_SOURCE_OUTPUT: + case ASL_FILE_C_INCLUDE_OUTPUT: + + Prefix = " * "; + break; + + default: + /* No other output types supported */ + break; + } + + /* Running compiler or disassembler? */ + + if (Gbl_DisasmFlag) + { + UtilityName = AML_DISASSEMBLER_NAME; + } + else + { + UtilityName = ASL_COMPILER_NAME; + } + + /* Compiler signon with copyright */ + + FlPrintFile (FileId, "%s\n", Prefix); + FlPrintFile (FileId, ACPI_COMMON_HEADER (UtilityName, Prefix)); +} + + +/******************************************************************************* + * + * FUNCTION: AslCompilerFileHeader + * + * PARAMETERS: FileId - ID of the output file + * + * RETURN: None + * + * DESCRIPTION: Header used at the beginning of output files + * + ******************************************************************************/ + +void +AslCompilerFileHeader ( + UINT32 FileId) +{ + struct tm *NewTime; + time_t Aclock; + char *Prefix = ""; + + + /* Set line prefix depending on the destination file type */ + + switch (FileId) + { + case ASL_FILE_ASM_SOURCE_OUTPUT: + case ASL_FILE_ASM_INCLUDE_OUTPUT: + + Prefix = "; "; + break; + + case ASL_FILE_HEX_OUTPUT: + + if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) + { + Prefix = "; "; + } + else if ((Gbl_HexOutputFlag == HEX_OUTPUT_C) || + (Gbl_HexOutputFlag == HEX_OUTPUT_ASL)) + { + Prefix = " * "; + } + break; + + case ASL_FILE_C_SOURCE_OUTPUT: + case ASL_FILE_C_INCLUDE_OUTPUT: + + Prefix = " * "; + break; + + default: + /* No other output types supported */ + break; + } + + /* Compilation header with timestamp */ + + (void) time (&Aclock); + NewTime = localtime (&Aclock); + + FlPrintFile (FileId, + "%sCompilation of \"%s\" - %s%s\n", + Prefix, Gbl_Files[ASL_FILE_INPUT].Filename, asctime (NewTime), + Prefix); + + switch (FileId) + { + case ASL_FILE_C_SOURCE_OUTPUT: + case ASL_FILE_C_INCLUDE_OUTPUT: + FlPrintFile (FileId, " */\n"); + break; + + default: + /* Nothing to do for other output types */ + break; + } +} + + +/******************************************************************************* + * + * FUNCTION: CmFlushSourceCode + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Read in any remaining source code after the parse tree + * has been constructed. + * + ******************************************************************************/ + +static void +CmFlushSourceCode ( + void) +{ + char Buffer; + + + while (FlReadFile (ASL_FILE_INPUT, &Buffer, 1) != AE_ERROR) + { + AslInsertLineBuffer ((int) Buffer); + } + + AslResetCurrentLineBuffer (); +} + + +/******************************************************************************* + * + * FUNCTION: FlConsume* + * + * PARAMETERS: FileInfo - Points to an open input file + * + * RETURN: Number of lines consumed + * + * DESCRIPTION: Step over both types of comment during check for ascii chars + * + ******************************************************************************/ + +static void +FlConsumeAnsiComment ( + ASL_FILE_INFO *FileInfo, + ASL_FILE_STATUS *Status) +{ + UINT8 Byte; + BOOLEAN ClosingComment = FALSE; + + + while (fread (&Byte, 1, 1, FileInfo->Handle)) + { + /* Scan until comment close is found */ + + if (ClosingComment) + { + if (Byte == '/') + { + return; + } + + if (Byte != '*') + { + /* Reset */ + + ClosingComment = FALSE; + } + } + else if (Byte == '*') + { + ClosingComment = TRUE; + } + + /* Maintain line count */ + + if (Byte == 0x0A) + { + Status->Line++; + } + + Status->Offset++; + } +} + + +static void +FlConsumeNewComment ( + ASL_FILE_INFO *FileInfo, + ASL_FILE_STATUS *Status) +{ + UINT8 Byte; + + + while (fread (&Byte, 1, 1, FileInfo->Handle)) + { + Status->Offset++; + + /* Comment ends at newline */ + + if (Byte == 0x0A) + { + Status->Line++; + return; + } + } +} + + +/******************************************************************************* + * + * FUNCTION: FlCheckForAscii + * + * PARAMETERS: FileInfo - Points to an open input file + * + * RETURN: Status + * + * DESCRIPTION: Verify that the input file is entirely ASCII. Ignores characters + * within comments. Note: does not handle nested comments and does + * not handle comment delimiters within string literals. However, + * on the rare chance this happens and an invalid character is + * missed, the parser will catch the error by failing in some + * spectactular manner. + * + ******************************************************************************/ + +ACPI_STATUS +FlCheckForAscii ( + ASL_FILE_INFO *FileInfo) +{ + UINT8 Byte; + ACPI_SIZE BadBytes = 0; + BOOLEAN OpeningComment = FALSE; + ASL_FILE_STATUS Status; + + + Status.Line = 1; + Status.Offset = 0; + + /* Read the entire file */ + + while (fread (&Byte, 1, 1, FileInfo->Handle)) + { + /* Ignore comment fields (allow non-ascii within) */ + + if (OpeningComment) + { + /* Check for second comment open delimiter */ + + if (Byte == '*') + { + FlConsumeAnsiComment (FileInfo, &Status); + } + + if (Byte == '/') + { + FlConsumeNewComment (FileInfo, &Status); + } + + /* Reset */ + + OpeningComment = FALSE; + } + else if (Byte == '/') + { + OpeningComment = TRUE; + } + + /* Check for an ASCII character */ + + if (!ACPI_IS_ASCII (Byte)) + { + if (BadBytes < 10) + { + AcpiOsPrintf ( + "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n", + Byte, Status.Line, Status.Offset); + } + + BadBytes++; + } + + /* Update line counter */ + + else if (Byte == 0x0A) + { + Status.Line++; + } + + Status.Offset++; + } + + /* Seek back to the beginning of the source file */ + + fseek (FileInfo->Handle, 0, SEEK_SET); + + /* Were there any non-ASCII characters in the file? */ + + if (BadBytes) + { + AcpiOsPrintf ( + "%u non-ASCII characters found in input source text, could be a binary file\n", + BadBytes); + AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, FileInfo->Filename); + return (AE_BAD_CHARACTER); + } + + /* File is OK */ + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: CmDoCompile + * + * PARAMETERS: None + * + * RETURN: Status (0 = OK) + * + * DESCRIPTION: This procedure performs the entire compile + * + ******************************************************************************/ + +int +CmDoCompile ( + void) +{ + ACPI_STATUS Status; + UINT8 FullCompile; + UINT8 Event; + + + FullCompile = UtBeginEvent ("*** Total Compile time ***"); + Event = UtBeginEvent ("Open input and output files"); + UtEndEvent (Event); + + Event = UtBeginEvent ("Preprocess input file"); + if (Gbl_PreprocessFlag) + { + /* Preprocessor */ + + PrDoPreprocess (); + if (Gbl_PreprocessOnly) + { + UtEndEvent (Event); + CmCleanupAndExit (); + return 0; + } + } + UtEndEvent (Event); + + /* Build the parse tree */ + + Event = UtBeginEvent ("Parse source code and build parse tree"); + AslCompilerparse(); + UtEndEvent (Event); + + /* Flush out any remaining source after parse tree is complete */ + + Event = UtBeginEvent ("Flush source input"); + CmFlushSourceCode (); + + /* Did the parse tree get successfully constructed? */ + + if (!RootNode) + { + /* + * If there are no errors, then we have some sort of + * internal problem. + */ + Status = AslCheckForErrorExit (); + if (Status == AE_OK) + { + AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, + NULL, "- Could not resolve parse tree root node"); + } + + goto ErrorExit; + } + + /* Optional parse tree dump, compiler debug output only */ + + LsDumpParseTree (); + + OpcGetIntegerWidth (RootNode); + UtEndEvent (Event); + + /* Pre-process parse tree for any operator transforms */ + + Event = UtBeginEvent ("Parse tree transforms"); + DbgPrint (ASL_DEBUG_OUTPUT, "\nParse tree transforms\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, + TrAmlTransformWalk, NULL, NULL); + UtEndEvent (Event); + + /* Generate AML opcodes corresponding to the parse tokens */ + + Event = UtBeginEvent ("Generate AML opcodes"); + DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating AML opcodes\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, + OpcAmlOpcodeWalk, NULL); + UtEndEvent (Event); + + /* + * Now that the input is parsed, we can open the AML output file. + * Note: by default, the name of this file comes from the table descriptor + * within the input file. + */ + Event = UtBeginEvent ("Open AML output file"); + Status = FlOpenAmlOutputFile (Gbl_OutputFilenamePrefix); + UtEndEvent (Event); + if (ACPI_FAILURE (Status)) + { + AePrintErrorLog (ASL_FILE_STDERR); + return -1; + } + + /* Interpret and generate all compile-time constants */ + + Event = UtBeginEvent ("Constant folding via AML interpreter"); + DbgPrint (ASL_DEBUG_OUTPUT, + "\nInterpreting compile-time constant expressions\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, + OpcAmlConstantWalk, NULL, NULL); + UtEndEvent (Event); + + /* Update AML opcodes if necessary, after constant folding */ + + Event = UtBeginEvent ("Updating AML opcodes after constant folding"); + DbgPrint (ASL_DEBUG_OUTPUT, + "\nUpdating AML opcodes after constant folding\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, + NULL, OpcAmlOpcodeUpdateWalk, NULL); + UtEndEvent (Event); + + /* Calculate all AML package lengths */ + + Event = UtBeginEvent ("Generate AML package lengths"); + DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, + LnPackageLengthWalk, NULL); + UtEndEvent (Event); + + if (Gbl_ParseOnlyFlag) + { + AePrintErrorLog (ASL_FILE_STDERR); + UtDisplaySummary (ASL_FILE_STDERR); + if (Gbl_DebugFlag) + { + /* Print error summary to the stdout also */ + + AePrintErrorLog (ASL_FILE_STDOUT); + UtDisplaySummary (ASL_FILE_STDOUT); + } + UtEndEvent (FullCompile); + return 0; + } + + /* + * Create an internal namespace and use it as a symbol table + */ + + /* Namespace loading */ + + Event = UtBeginEvent ("Create ACPI Namespace"); + Status = LdLoadNamespace (RootNode); + UtEndEvent (Event); + if (ACPI_FAILURE (Status)) + { + goto ErrorExit; + } + + /* Namespace cross-reference */ + + AslGbl_NamespaceEvent = UtBeginEvent ("Cross reference parse tree and Namespace"); + Status = LkCrossReferenceNamespace (); + if (ACPI_FAILURE (Status)) + { + goto ErrorExit; + } + + /* Namespace - Check for non-referenced objects */ + + LkFindUnreferencedObjects (); + UtEndEvent (AslGbl_NamespaceEvent); + + /* + * Semantic analysis. This can happen only after the + * namespace has been loaded and cross-referenced. + * + * part one - check control methods + */ + Event = UtBeginEvent ("Analyze control method return types"); + AnalysisWalkInfo.MethodStack = NULL; + + DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method analysis\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, + AnMethodAnalysisWalkBegin, + AnMethodAnalysisWalkEnd, &AnalysisWalkInfo); + UtEndEvent (Event); + + /* Semantic error checking part two - typing of method returns */ + + Event = UtBeginEvent ("Determine object types returned by methods"); + DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Method typing\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, + NULL, AnMethodTypingWalkEnd, NULL); + UtEndEvent (Event); + + /* Semantic error checking part three - operand type checking */ + + Event = UtBeginEvent ("Analyze AML operand types"); + DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - Operand type checking\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, + NULL, AnOperandTypecheckWalkEnd, &AnalysisWalkInfo); + UtEndEvent (Event); + + /* Semantic error checking part four - other miscellaneous checks */ + + Event = UtBeginEvent ("Miscellaneous analysis"); + DbgPrint (ASL_DEBUG_OUTPUT, "\nSemantic analysis - miscellaneous\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, + AnOtherSemanticAnalysisWalkBegin, + NULL, &AnalysisWalkInfo); + UtEndEvent (Event); + + /* Calculate all AML package lengths */ + + Event = UtBeginEvent ("Finish AML package length generation"); + DbgPrint (ASL_DEBUG_OUTPUT, "\nGenerating Package lengths\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, + LnInitLengthsWalk, NULL); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, + LnPackageLengthWalk, NULL); + UtEndEvent (Event); + + /* Code generation - emit the AML */ + + Event = UtBeginEvent ("Generate AML code and write output files"); + CgGenerateAmlOutput (); + UtEndEvent (Event); + + Event = UtBeginEvent ("Write optional output files"); + CmDoOutputFiles (); + UtEndEvent (Event); + + UtEndEvent (FullCompile); + CmCleanupAndExit (); + return 0; + +ErrorExit: + UtEndEvent (FullCompile); + CmCleanupAndExit (); + return (-1); +} + + +/******************************************************************************* + * + * FUNCTION: CmDoOutputFiles + * + * PARAMETERS: None + * + * RETURN: None. + * + * DESCRIPTION: Create all "listing" type files + * + ******************************************************************************/ + +void +CmDoOutputFiles ( + void) +{ + + /* Create listings and hex files */ + + LsDoListings (); + LsDoHexOutput (); + + /* Dump the namespace to the .nsp file if requested */ + + (void) LsDisplayNamespace (); +} + + +/******************************************************************************* + * + * FUNCTION: CmDumpEvent + * + * PARAMETERS: Event - A compiler event struct + * + * RETURN: None. + * + * DESCRIPTION: Dump a compiler event struct + * + ******************************************************************************/ + +static void +CmDumpEvent ( + ASL_EVENT_INFO *Event) +{ + UINT32 Delta; + UINT32 USec; + UINT32 MSec; + + if (!Event->Valid) + { + return; + } + + /* Delta will be in 100-nanosecond units */ + + Delta = (UINT32) (Event->EndTime - Event->StartTime); + + USec = Delta / 10; + MSec = Delta / 10000; + + /* Round milliseconds up */ + + if ((USec - (MSec * 1000)) >= 500) + { + MSec++; + } + + DbgPrint (ASL_DEBUG_OUTPUT, "%8u usec %8u msec - %s\n", + USec, MSec, Event->EventName); +} + + +/******************************************************************************* + * + * FUNCTION: CmCleanupAndExit + * + * PARAMETERS: None + * + * RETURN: None. + * + * DESCRIPTION: Close all open files and exit the compiler + * + ******************************************************************************/ + +void +CmCleanupAndExit ( + void) +{ + UINT32 i; + + + AePrintErrorLog (ASL_FILE_STDERR); + if (Gbl_DebugFlag) + { + /* Print error summary to stdout also */ + + AePrintErrorLog (ASL_FILE_STDOUT); + } + + DbgPrint (ASL_DEBUG_OUTPUT, "\n\nElapsed time for major events\n\n"); + for (i = 0; i < AslGbl_NextEvent; i++) + { + CmDumpEvent (&AslGbl_Events[i]); + } + + if (Gbl_CompileTimesFlag) + { + printf ("\nElapsed time for major events\n\n"); + for (i = 0; i < AslGbl_NextEvent; i++) + { + CmDumpEvent (&AslGbl_Events[i]); + } + + printf ("\nMiscellaneous compile statistics\n\n"); + printf ("%11u : %s\n", TotalParseNodes, "Parse nodes"); + printf ("%11u : %s\n", Gbl_NsLookupCount, "Namespace searches"); + printf ("%11u : %s\n", TotalNamedObjects, "Named objects"); + printf ("%11u : %s\n", TotalMethods, "Control methods"); + printf ("%11u : %s\n", TotalAllocations, "Memory Allocations"); + printf ("%11u : %s\n", TotalAllocated, "Total allocated memory"); + printf ("%11u : %s\n", TotalFolds, "Constant subtrees folded"); + printf ("\n"); + } + + if (Gbl_NsLookupCount) + { + DbgPrint (ASL_DEBUG_OUTPUT, + "\n\nMiscellaneous compile statistics\n\n"); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%32s : %u\n", "Total Namespace searches", + Gbl_NsLookupCount); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%32s : %u usec\n", "Time per search", ((UINT32) + (AslGbl_Events[AslGbl_NamespaceEvent].EndTime - + AslGbl_Events[AslGbl_NamespaceEvent].StartTime) / 10) / + Gbl_NsLookupCount); + } + + if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) + { + printf ("\nMaximum error count (%u) exceeded\n", + ASL_MAX_ERROR_COUNT); + } + + UtDisplaySummary (ASL_FILE_STDOUT); + + /* Close all open files */ + + Gbl_Files[ASL_FILE_PREPROCESSOR].Handle = NULL; /* the .i file is same as source file */ + + for (i = ASL_FILE_INPUT; i < ASL_MAX_FILE_TYPE; i++) + { + FlCloseFile (i); + } + + /* Delete AML file if there are errors */ + + if ((Gbl_ExceptionCount[ASL_ERROR] > 0) && (!Gbl_IgnoreErrors) && + Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) + { + if (remove (Gbl_Files[ASL_FILE_AML_OUTPUT].Filename)) + { + printf ("%s: ", + Gbl_Files[ASL_FILE_AML_OUTPUT].Filename); + perror ("Could not delete AML file"); + } + } + + /* Delete the preprocessor output file (.i) unless -li flag is set */ + + if (!Gbl_PreprocessorOutputFlag && + Gbl_PreprocessFlag && + Gbl_Files[ASL_FILE_PREPROCESSOR].Filename) + { + if (remove (Gbl_Files[ASL_FILE_PREPROCESSOR].Filename)) + { + printf ("%s: ", + Gbl_Files[ASL_FILE_PREPROCESSOR].Filename); + perror ("Could not delete preprocessor .i file"); + } + } + + /* + * Delete intermediate ("combined") source file (if -ls flag not set) + * This file is created during normal ASL/AML compiles. It is not + * created by the data table compiler. + * + * If the -ls flag is set, then the .SRC file should not be deleted. + * In this case, Gbl_SourceOutputFlag is set to TRUE. + * + * Note: Handles are cleared by FlCloseFile above, so we look at the + * filename instead, to determine if the .SRC file was actually + * created. + * + * TBD: SourceOutput should be .TMP, then rename if we want to keep it? + */ + if (!Gbl_SourceOutputFlag && Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename) + { + if (remove (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename)) + { + printf ("%s: ", + Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); + perror ("Could not delete SRC file"); + } + } +} + + diff --git a/sys/contrib/dev/acpica/compiler/aslcompiler.h b/sys/contrib/dev/acpica/compiler/aslcompiler.h new file mode 100644 index 0000000..bb29468 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslcompiler.h @@ -0,0 +1,1111 @@ + +/****************************************************************************** + * + * Module Name: aslcompiler.h - common include file for iASL + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#ifndef __ASLCOMPILER_H +#define __ASLCOMPILER_H + +#include <contrib/dev/acpica/include/acpi.h> +#include <contrib/dev/acpica/include/accommon.h> +#include <contrib/dev/acpica/include/amlresrc.h> +#include <contrib/dev/acpica/include/acdebug.h> + +/* Microsoft-specific */ + +#if (defined WIN32 || defined WIN64) + +/* warn : used #pragma pack */ +#pragma warning(disable:4103) + +/* warn : named type definition in parentheses */ +#pragma warning(disable:4115) +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <errno.h> +#include <ctype.h> + +/* Compiler headers */ + +#include <contrib/dev/acpica/compiler/asldefine.h> +#include <contrib/dev/acpica/compiler/asltypes.h> +#include <contrib/dev/acpica/compiler/aslmessages.h> +#include <contrib/dev/acpica/compiler/aslglobal.h> +#include <contrib/dev/acpica/compiler/preprocess.h> + + +/******************************************************************************* + * + * Compiler prototypes + * + ******************************************************************************/ + +/* + * Main ASL parser - generated from flex/bison, lex/yacc, etc. + */ +int +AslCompilerparse( + void); + +ACPI_PARSE_OBJECT * +AslDoError ( + void); + +int +AslCompilerlex( + void); + +void +AslResetCurrentLineBuffer ( + void); + +void +AslInsertLineBuffer ( + int SourceChar); + +int +AslPopInputFileStack ( + void); + +void +AslPushInputFileStack ( + FILE *InputFile, + char *Filename); + +/* + * aslstartup - entered from main() + */ +void +AslInitializeGlobals ( + void); + +typedef +ACPI_STATUS (*ASL_PATHNAME_CALLBACK) ( + char *); + +ACPI_STATUS +AslDoOnePathname ( + char *Pathname, + ASL_PATHNAME_CALLBACK Callback); + +ACPI_STATUS +AslDoOneFile ( + char *Filename); + +ACPI_STATUS +AslCheckForErrorExit ( + void); + + +/* + * aslcompile - compile mainline + */ +void +AslCompilerSignon ( + UINT32 FileId); + +void +AslCompilerFileHeader ( + UINT32 FileId); + +int +CmDoCompile ( + void); + +void +CmDoOutputFiles ( + void); + +void +CmCleanupAndExit ( + void); + +ACPI_STATUS +FlCheckForAscii ( + ASL_FILE_INFO *FileInfo); + + +/* + * aslwalks - semantic analysis and parse tree walks + */ +ACPI_STATUS +AnOtherSemanticAnalysisWalkBegin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +ACPI_STATUS +AnOtherSemanticAnalysisWalkEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +ACPI_STATUS +AnOperandTypecheckWalkEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +ACPI_STATUS +AnMethodAnalysisWalkBegin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +ACPI_STATUS +AnMethodAnalysisWalkEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +ACPI_STATUS +AnMethodTypingWalkEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + + +/* + * aslbtypes - bitfield data types + */ +UINT32 +AnMapObjTypeToBtype ( + ACPI_PARSE_OBJECT *Op); + +UINT32 +AnMapArgTypeToBtype ( + UINT32 ArgType); + +UINT32 +AnGetBtype ( + ACPI_PARSE_OBJECT *Op); + +void +AnFormatBtype ( + char *Buffer, + UINT32 Btype); + + +/* + * aslanalyze - Support functions for parse tree walks + */ +void +AnCheckId ( + ACPI_PARSE_OBJECT *Op, + ACPI_NAME Type); + +/* Values for Type argument above */ + +#define ASL_TYPE_HID 0 +#define ASL_TYPE_CID 1 + +BOOLEAN +AnIsInternalMethod ( + ACPI_PARSE_OBJECT *Op); + +UINT32 +AnGetInternalMethodReturnType ( + ACPI_PARSE_OBJECT *Op); + +BOOLEAN +AnLastStatementIsReturn ( + ACPI_PARSE_OBJECT *Op); + +void +AnCheckMethodReturnValue ( + ACPI_PARSE_OBJECT *Op, + const ACPI_OPCODE_INFO *OpInfo, + ACPI_PARSE_OBJECT *ArgOp, + UINT32 RequiredBtypes, + UINT32 ThisNodeBtype); + +BOOLEAN +AnIsResultUsed ( + ACPI_PARSE_OBJECT *Op); + +void +ApCheckForGpeNameConflict ( + ACPI_PARSE_OBJECT *Op); + +void +ApCheckRegMethod ( + ACPI_PARSE_OBJECT *Op); + + +/* + * aslerror - error handling/reporting + */ +void +AslError ( + UINT8 Level, + UINT8 MessageId, + ACPI_PARSE_OBJECT *Op, + char *ExtraMessage); + +void +AslCoreSubsystemError ( + ACPI_PARSE_OBJECT *Op, + ACPI_STATUS Status, + char *ExtraMessage, + BOOLEAN Abort); + +int +AslCompilererror( + const char *s); + +void +AslCommonError ( + UINT8 Level, + UINT8 MessageId, + UINT32 CurrentLineNumber, + UINT32 LogicalLineNumber, + UINT32 LogicalByteOffset, + UINT32 Column, + char *Filename, + char *ExtraMessage); + +void +AslCommonError2 ( + UINT8 Level, + UINT8 MessageId, + UINT32 LineNumber, + UINT32 Column, + char *SourceLine, + char *Filename, + char *ExtraMessage); + +void +AePrintException ( + UINT32 FileId, + ASL_ERROR_MSG *Enode, + char *Header); + +void +AePrintErrorLog ( + UINT32 FileId); + +void +AeClearErrorLog ( + void); + +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void); + + +/* + * asllisting - generate all "listing" type files + */ +void +LsDoListings ( + void); + +void +LsWriteNodeToAsmListing ( + ACPI_PARSE_OBJECT *Op); + +void +LsWriteNode ( + ACPI_PARSE_OBJECT *Op, + UINT32 FileId); + +void +LsDoHexOutput ( + void); + +void +LsDumpParseTree ( + void); + +/* + * aslfold - constant folding + */ +ACPI_STATUS +OpcAmlConstantWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + + +/* + * aslopcodes - generate AML opcodes + */ +ACPI_STATUS +OpcAmlOpcodeWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +ACPI_STATUS +OpcAmlOpcodeUpdateWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +void +OpcGenerateAmlOpcode ( + ACPI_PARSE_OBJECT *Op); + +UINT32 +OpcSetOptimalIntegerSize ( + ACPI_PARSE_OBJECT *Op); + +void +OpcGetIntegerWidth ( + ACPI_PARSE_OBJECT *Op); + + +/* + * asloperands - generate AML operands for the AML opcodes + */ +ACPI_PARSE_OBJECT * +UtGetArg ( + ACPI_PARSE_OBJECT *Op, + UINT32 Argn); + +void +OpnGenerateAmlOperands ( + ACPI_PARSE_OBJECT *Op); + +void +OpnDoPackage ( + ACPI_PARSE_OBJECT *Op); + + +/* + * aslopt - optmization + */ +void +OptOptimizeNamePath ( + ACPI_PARSE_OBJECT *Op, + UINT32 Flags, + ACPI_WALK_STATE *WalkState, + char *AmlNameString, + ACPI_NAMESPACE_NODE *TargetNode); + + +/* + * aslcodegen - code generation + */ +void +CgGenerateAmlOutput ( + void); + + +/* + * aslfile + */ +void +FlOpenFile ( + UINT32 FileId, + char *Filename, + char *Mode); + + +/* + * asllength - calculate/adjust AML package lengths + */ +ACPI_STATUS +LnPackageLengthWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +ACPI_STATUS +LnInitLengthsWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +void +CgGenerateAmlLengths ( + ACPI_PARSE_OBJECT *Op); + + +/* + * aslmap - opcode mappings and reserved method names + */ +ACPI_OBJECT_TYPE +AslMapNamedOpcodeToDataType ( + UINT16 Opcode); + + +/* + * aslpredef - ACPI predefined names support + */ +BOOLEAN +ApCheckForPredefinedMethod ( + ACPI_PARSE_OBJECT *Op, + ASL_METHOD_INFO *MethodInfo); + +void +ApCheckPredefinedReturnValue ( + ACPI_PARSE_OBJECT *Op, + ASL_METHOD_INFO *MethodInfo); + +UINT32 +ApCheckForPredefinedName ( + ACPI_PARSE_OBJECT *Op, + char *Name); + +void +ApCheckForPredefinedObject ( + ACPI_PARSE_OBJECT *Op, + char *Name); + +void +ApDisplayReservedNames ( + void); + + +/* + * asltransform - parse tree transformations + */ +ACPI_STATUS +TrAmlTransformWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + + +/* + * asltree - parse tree support + */ +ACPI_STATUS +TrWalkParseTree ( + ACPI_PARSE_OBJECT *Op, + UINT32 Visitation, + ASL_WALK_CALLBACK DescendingCallback, + ASL_WALK_CALLBACK AscendingCallback, + void *Context); + +/* Values for "Visitation" parameter above */ + +#define ASL_WALK_VISIT_DOWNWARD 0x01 +#define ASL_WALK_VISIT_UPWARD 0x02 +#define ASL_WALK_VISIT_TWICE (ASL_WALK_VISIT_DOWNWARD | ASL_WALK_VISIT_UPWARD) + + +ACPI_PARSE_OBJECT * +TrAllocateNode ( + UINT32 ParseOpcode); + +void +TrReleaseNode ( + ACPI_PARSE_OBJECT *Op); + +ACPI_PARSE_OBJECT * +TrUpdateNode ( + UINT32 ParseOpcode, + ACPI_PARSE_OBJECT *Op); + +ACPI_PARSE_OBJECT * +TrCreateNode ( + UINT32 ParseOpcode, + UINT32 NumChildren, + ...); + +ACPI_PARSE_OBJECT * +TrCreateLeafNode ( + UINT32 ParseOpcode); + +ACPI_PARSE_OBJECT * +TrCreateValuedLeafNode ( + UINT32 ParseOpcode, + UINT64 Value); + +ACPI_PARSE_OBJECT * +TrCreateConstantLeafNode ( + UINT32 ParseOpcode); + +ACPI_PARSE_OBJECT * +TrLinkChildren ( + ACPI_PARSE_OBJECT *Op, + UINT32 NumChildren, + ...); + +void +TrSetEndLineNumber ( + ACPI_PARSE_OBJECT *Op); + +void +TrWalkTree ( + void); + +ACPI_PARSE_OBJECT * +TrLinkPeerNode ( + ACPI_PARSE_OBJECT *Op1, + ACPI_PARSE_OBJECT *Op2); + +ACPI_PARSE_OBJECT * +TrLinkChildNode ( + ACPI_PARSE_OBJECT *Op1, + ACPI_PARSE_OBJECT *Op2); + +ACPI_PARSE_OBJECT * +TrSetNodeFlags ( + ACPI_PARSE_OBJECT *Op, + UINT32 Flags); + +ACPI_PARSE_OBJECT * +TrLinkPeerNodes ( + UINT32 NumPeers, + ...); + + +/* + * aslfiles - File I/O support + */ +void +AslAbort ( + void); + +void +FlAddIncludeDirectory ( + char *Dir); + +void +FlOpenIncludeFile ( + ACPI_PARSE_OBJECT *Op); + +void +FlFileError ( + UINT32 FileId, + UINT8 ErrorId); + +UINT32 +FlGetFileSize ( + UINT32 FileId); + +ACPI_STATUS +FlReadFile ( + UINT32 FileId, + void *Buffer, + UINT32 Length); + +void +FlWriteFile ( + UINT32 FileId, + void *Buffer, + UINT32 Length); + +void +FlSeekFile ( + UINT32 FileId, + long Offset); + +void +FlCloseFile ( + UINT32 FileId); + +void +FlPrintFile ( + UINT32 FileId, + char *Format, + ...); + +void +FlSetLineNumber ( + UINT32 LineNumber); + +void +FlSetFilename ( + char *Filename); + +ACPI_STATUS +FlOpenInputFile ( + char *InputFilename); + +ACPI_STATUS +FlOpenAmlOutputFile ( + char *InputFilename); + +ACPI_STATUS +FlOpenMiscOutputFiles ( + char *InputFilename); + + +/* + * asload - load namespace in prep for cross reference + */ +ACPI_STATUS +LdLoadNamespace ( + ACPI_PARSE_OBJECT *RootOp); + + +/* + * asllookup - namespace cross reference + */ +ACPI_STATUS +LkCrossReferenceNamespace ( + void); + +void +LkFindUnreferencedObjects ( + void); + +ACPI_STATUS +LsDisplayNamespace ( + void); + +void +LsSetupNsList ( + void *Handle); + + +/* + * aslutils - common compiler utilites + */ +void +DbgPrint ( + UINT32 Type, + char *Format, + ...); + +/* Type values for above */ + +#define ASL_DEBUG_OUTPUT 0 +#define ASL_PARSE_OUTPUT 1 +#define ASL_TREE_OUTPUT 2 + +void +UtDisplaySupportedTables ( + void); + +void +UtDisplayConstantOpcodes ( + void); + +UINT8 +UtBeginEvent ( + char *Name); + +void +UtEndEvent ( + UINT8 Event); + +void * +UtLocalCalloc ( + UINT32 Size); + +void +UtPrintFormattedName ( + UINT16 ParseOpcode, + UINT32 Level); + +void +UtDisplaySummary ( + UINT32 FileId); + +UINT8 +UtHexCharToValue ( + int HexChar); + +void +UtConvertByteToHex ( + UINT8 RawByte, + UINT8 *Buffer); + +void +UtConvertByteToAsmHex ( + UINT8 RawByte, + UINT8 *Buffer); + +char * +UtGetOpName ( + UINT32 ParseOpcode); + +void +UtSetParseOpName ( + ACPI_PARSE_OBJECT *Op); + +char * +UtGetStringBuffer ( + UINT32 Length); + +ACPI_STATUS +UtInternalizeName ( + char *ExternalName, + char **ConvertedName); + +void +UtAttachNamepathToOwner ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *NameNode); + +ACPI_PARSE_OBJECT * +UtCheckIntegerRange ( + ACPI_PARSE_OBJECT *Op, + UINT32 LowValue, + UINT32 HighValue); + +UINT64 +UtDoConstant ( + char *String); + +ACPI_STATUS +UtStrtoul64 ( + char *String, + UINT32 Base, + UINT64 *RetInteger); + + +/* + * asluuid - UUID support + */ +ACPI_STATUS +AuValidateUuid ( + char *InString); + +ACPI_STATUS +AuConvertStringToUuid ( + char *InString, + char *UuIdBuffer); + +ACPI_STATUS +AuConvertUuidToString ( + char *UuIdBuffer, + char *OutString); + +/* + * aslresource - Resource template generation utilities + */ +void +RsSmallAddressCheck ( + UINT8 Type, + UINT32 Minimum, + UINT32 Maximum, + UINT32 Length, + UINT32 Alignment, + ACPI_PARSE_OBJECT *MinOp, + ACPI_PARSE_OBJECT *MaxOp, + ACPI_PARSE_OBJECT *LengthOp, + ACPI_PARSE_OBJECT *AlignOp, + ACPI_PARSE_OBJECT *Op); + +void +RsLargeAddressCheck ( + UINT64 Minimum, + UINT64 Maximum, + UINT64 Length, + UINT64 Granularity, + UINT8 Flags, + ACPI_PARSE_OBJECT *MinOp, + ACPI_PARSE_OBJECT *MaxOp, + ACPI_PARSE_OBJECT *LengthOp, + ACPI_PARSE_OBJECT *GranOp, + ACPI_PARSE_OBJECT *Op); + +UINT16 +RsGetStringDataLength ( + ACPI_PARSE_OBJECT *InitializerOp); + +ASL_RESOURCE_NODE * +RsAllocateResourceNode ( + UINT32 Size); + +void +RsCreateResourceField ( + ACPI_PARSE_OBJECT *Op, + char *Name, + UINT32 ByteOffset, + UINT32 BitOffset, + UINT32 BitLength); + +void +RsSetFlagBits ( + UINT8 *Flags, + ACPI_PARSE_OBJECT *Op, + UINT8 Position, + UINT8 DefaultBit); + +void +RsSetFlagBits16 ( + UINT16 *Flags, + ACPI_PARSE_OBJECT *Op, + UINT8 Position, + UINT8 DefaultBit); + +ACPI_PARSE_OBJECT * +RsCompleteNodeAndGetNext ( + ACPI_PARSE_OBJECT *Op); + +void +RsCheckListForDuplicates ( + ACPI_PARSE_OBJECT *Op); + +ASL_RESOURCE_NODE * +RsDoOneResourceDescriptor ( + ACPI_PARSE_OBJECT *DescriptorTypeOp, + UINT32 CurrentByteOffset, + UINT8 *State); + +/* Values for State above */ + +#define ACPI_RSTATE_NORMAL 0 +#define ACPI_RSTATE_START_DEPENDENT 1 +#define ACPI_RSTATE_DEPENDENT_LIST 2 + +UINT32 +RsLinkDescriptorChain ( + ASL_RESOURCE_NODE **PreviousRnode, + ASL_RESOURCE_NODE *Rnode); + +void +RsDoResourceTemplate ( + ACPI_PARSE_OBJECT *Op); + + +/* + * aslrestype1 - Miscellaneous Small descriptors + */ +ASL_RESOURCE_NODE * +RsDoEndTagDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoEndDependentDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoMemory24Descriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoMemory32Descriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoMemory32FixedDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoStartDependentDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoStartDependentNoPriDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoVendorSmallDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + + +/* + * aslrestype1i - I/O-related Small descriptors + */ +ASL_RESOURCE_NODE * +RsDoDmaDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoFixedDmaDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoFixedIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoIrqDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoIrqNoFlagsDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + + +/* + * aslrestype2 - Large resource descriptors + */ +ASL_RESOURCE_NODE * +RsDoInterruptDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoVendorLargeDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoGeneralRegisterDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoGpioIntDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoGpioIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoI2cSerialBusDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoSpiSerialBusDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoUartSerialBusDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +/* + * aslrestype2d - DWord address descriptors + */ +ASL_RESOURCE_NODE * +RsDoDwordIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoDwordMemoryDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoDwordSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + + +/* + * aslrestype2e - Extended address descriptors + */ +ASL_RESOURCE_NODE * +RsDoExtendedIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoExtendedMemoryDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoExtendedSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + + +/* + * aslrestype2q - QWord address descriptors + */ +ASL_RESOURCE_NODE * +RsDoQwordIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoQwordMemoryDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoQwordSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + + +/* + * aslrestype2w - Word address descriptors + */ +ASL_RESOURCE_NODE * +RsDoWordIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoWordSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +ASL_RESOURCE_NODE * +RsDoWordBusNumberDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset); + +/* + * Entry to data table compiler subsystem + */ +ACPI_STATUS +DtDoCompile( + void); + +ACPI_STATUS +DtCreateTemplates ( + char *Signature); + +#endif /* __ASLCOMPILER_H */ + diff --git a/sys/contrib/dev/acpica/compiler/aslcompiler.l b/sys/contrib/dev/acpica/compiler/aslcompiler.l new file mode 100644 index 0000000..6839126 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslcompiler.l @@ -0,0 +1,652 @@ +%{ +/****************************************************************************** + * + * Module Name: aslcompiler.l - Flex/lex input file + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#include <stdlib.h> +#include <string.h> +YYSTYPE AslCompilerlval; + +/* + * Generation: Use the following command line: + * + * flex.exe -PAslCompiler -i -o$(InputPath).c $(InputPath) + * + * -i: Scanner must be case-insensitive + */ + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslscanner") + + +/* Local prototypes */ + +static void +AslDoLineDirective (void); + +static char +AslDoComment (void); + +static char +AslDoCommentType2 (void); + +static char +AslDoStringLiteral (void); + +static void +count (int type); + + +/*! [Begin] no source code translation */ + +%} + /* Definitions */ + +LeadNameChar [A-Za-z_] +DigitChar [0-9] +HexDigitChar [A-Fa-f0-9] +RootChar [\\] +Nothing [] + +NameChar [A-Za-z_0-9] +NameSeg1 {LeadNameChar}{NameChar} +NameSeg2 {LeadNameChar}{NameChar}{NameChar} +NameSeg3 {LeadNameChar}{NameChar}{NameChar}{NameChar} +NameSeg {LeadNameChar}|{NameSeg1}|{NameSeg2}|{NameSeg3} + +NameString {RootChar}|{RootChar}{NamePath}|[\^]+{NamePath}|{NonEmptyNamePath} +NamePath {NonEmptyNamePath}? +NonEmptyNamePath {NameSeg}{NamePathTail}* +NamePathTail [.]{NameSeg} + +%% + /* Rules */ + +[ ] { count (0); } +[\n] { count (0); } /* Handle files with both LF and CR/LF */ +[\r] { count (0); } /* termination on both Unix and Windows */ +[ \t] { count (0); } + + +"/*" { if (!AslDoComment ()) yyterminate (); } +"//" { if (!AslDoCommentType2 ()) yyterminate (); } + +"\"" { if (AslDoStringLiteral ()) return (PARSEOP_STRING_LITERAL); else yyterminate (); } +";" { count (0); return(';'); } + + +0[xX]{HexDigitChar}+ | +{DigitChar}+ { AslCompilerlval.i = UtDoConstant ((char *) AslCompilertext); + count (1); return (PARSEOP_INTEGER); } + +"Include" { count (1); return (PARSEOP_INCLUDE); } +"External" { count (1); return (PARSEOP_EXTERNAL); } + + /* + * The #line directive is emitted by the preprocessor and handled + * here in the main iASL lexer - simply set the line number and + * optionally the current filename. + */ +"#line" { AslDoLineDirective ();} + + + /**************************************************************************** + * + * Main ASL operators + * + ****************************************************************************/ + +"AccessAs" { count (1); return (PARSEOP_ACCESSAS); } +"Acquire" { count (3); return (PARSEOP_ACQUIRE); } +"Add" { count (3); return (PARSEOP_ADD); } +"Alias" { count (2); return (PARSEOP_ALIAS); } +"And" { count (3); return (PARSEOP_AND); } +"BankField" { count (2); return (PARSEOP_BANKFIELD); } +"Break" { count (3); return (PARSEOP_BREAK); } +"BreakPoint" { count (3); return (PARSEOP_BREAKPOINT); } +"Buffer" { count (1); return (PARSEOP_BUFFER); } +"Case" { count (3); return (PARSEOP_CASE); } +"Concatenate" { count (3); return (PARSEOP_CONCATENATE); } +"ConcatenateResTemplate" { count (3); return (PARSEOP_CONCATENATERESTEMPLATE); } +"CondRefOf" { count (3); return (PARSEOP_CONDREFOF); } +"Connection" { count (2); return (PARSEOP_CONNECTION); } +"Continue" { count (3); return (PARSEOP_CONTINUE); } +"CopyObject" { count (3); return (PARSEOP_COPYOBJECT); } +"CreateBitField" { count (2); return (PARSEOP_CREATEBITFIELD); } +"CreateByteField" { count (2); return (PARSEOP_CREATEBYTEFIELD); } +"CreateDWordField" { count (2); return (PARSEOP_CREATEDWORDFIELD); } +"CreateField" { count (2); return (PARSEOP_CREATEFIELD); } +"CreateQWordField" { count (2); return (PARSEOP_CREATEQWORDFIELD); } +"CreateWordField" { count (2); return (PARSEOP_CREATEWORDFIELD); } +"DataTableRegion" { count (2); return (PARSEOP_DATATABLEREGION); } +"Debug" { count (1); return (PARSEOP_DEBUG); } +"Decrement" { count (3); return (PARSEOP_DECREMENT); } +"Default" { count (3); return (PARSEOP_DEFAULT); } +"DefinitionBlock" { count (1); return (PARSEOP_DEFINITIONBLOCK); } +"DeRefOf" { count (3); return (PARSEOP_DEREFOF); } +"Device" { count (2); return (PARSEOP_DEVICE); } +"Divide" { count (3); return (PARSEOP_DIVIDE); } +"Eisaid" { count (1); return (PARSEOP_EISAID); } +"Else" { count (3); return (PARSEOP_ELSE); } +"ElseIf" { count (3); return (PARSEOP_ELSEIF); } +"Event" { count (2); return (PARSEOP_EVENT); } +"Fatal" { count (3); return (PARSEOP_FATAL); } +"Field" { count (2); return (PARSEOP_FIELD); } +"FindSetLeftBit" { count (3); return (PARSEOP_FINDSETLEFTBIT); } +"FindSetRightBit" { count (3); return (PARSEOP_FINDSETRIGHTBIT); } +"FromBcd" { count (3); return (PARSEOP_FROMBCD); } +"Function" { count (2); return (PARSEOP_FUNCTION); } +"If" { count (3); return (PARSEOP_IF); } +"Increment" { count (3); return (PARSEOP_INCREMENT); } +"Index" { count (3); return (PARSEOP_INDEX); } +"IndexField" { count (2); return (PARSEOP_INDEXFIELD); } +"LAnd" { count (3); return (PARSEOP_LAND); } +"LEqual" { count (3); return (PARSEOP_LEQUAL); } +"LGreater" { count (3); return (PARSEOP_LGREATER); } +"LGreaterEqual" { count (3); return (PARSEOP_LGREATEREQUAL); } +"LLess" { count (3); return (PARSEOP_LLESS); } +"LLessEqual" { count (3); return (PARSEOP_LLESSEQUAL); } +"LNot" { count (3); return (PARSEOP_LNOT); } +"LNotEqual" { count (3); return (PARSEOP_LNOTEQUAL); } +"Load" { count (3); return (PARSEOP_LOAD); } +"LoadTable" { count (3); return (PARSEOP_LOADTABLE); } +"LOr" { count (3); return (PARSEOP_LOR); } +"Match" { count (3); return (PARSEOP_MATCH); } +"Method" { count (2); return (PARSEOP_METHOD); } +"Mid" { count (3); return (PARSEOP_MID); } +"Mod" { count (3); return (PARSEOP_MOD); } +"Multiply" { count (3); return (PARSEOP_MULTIPLY); } +"Mutex" { count (2); return (PARSEOP_MUTEX); } +"Name" { count (2); return (PARSEOP_NAME); } +"NAnd" { count (3); return (PARSEOP_NAND); } +"Noop" { count (3); return (PARSEOP_NOOP); } +"NOr" { count (3); return (PARSEOP_NOR); } +"Not" { count (3); return (PARSEOP_NOT); } +"Notify" { count (3); return (PARSEOP_NOTIFY); } +"ObjectType" { count (3); return (PARSEOP_OBJECTTYPE); } +"Offset" { count (1); return (PARSEOP_OFFSET); } +"One" { count (1); return (PARSEOP_ONE); } +"Ones" { count (1); return (PARSEOP_ONES); } +"OperationRegion" { count (2); return (PARSEOP_OPERATIONREGION); } +"Or" { count (3); return (PARSEOP_OR); } +"Package" { count (1); return (PARSEOP_PACKAGE); } +"PowerResource" { count (2); return (PARSEOP_POWERRESOURCE); } +"Processor" { count (2); return (PARSEOP_PROCESSOR); } +"RefOf" { count (3); return (PARSEOP_REFOF); } +"Release" { count (3); return (PARSEOP_RELEASE); } +"Reset" { count (3); return (PARSEOP_RESET); } +"Return" { count (3); return (PARSEOP_RETURN); } +"Revision" { count (1); return (PARSEOP_REVISION); } +"Scope" { count (2); return (PARSEOP_SCOPE); } +"ShiftLeft" { count (3); return (PARSEOP_SHIFTLEFT); } +"ShiftRight" { count (3); return (PARSEOP_SHIFTRIGHT); } +"Signal" { count (3); return (PARSEOP_SIGNAL); } +"SizeOf" { count (3); return (PARSEOP_SIZEOF); } +"Sleep" { count (3); return (PARSEOP_SLEEP); } +"Stall" { count (3); return (PARSEOP_STALL); } +"Store" { count (3); return (PARSEOP_STORE); } +"Subtract" { count (3); return (PARSEOP_SUBTRACT); } +"Switch" { count (3); return (PARSEOP_SWITCH); } +"ThermalZone" { count (2); return (PARSEOP_THERMALZONE); } +"Timer" { count (3); return (PARSEOP_TIMER); } +"ToBcd" { count (3); return (PARSEOP_TOBCD); } +"ToBuffer" { count (3); return (PARSEOP_TOBUFFER); } +"ToDecimalString" { count (3); return (PARSEOP_TODECIMALSTRING); } +"ToHexString" { count (3); return (PARSEOP_TOHEXSTRING); } +"ToInteger" { count (3); return (PARSEOP_TOINTEGER); } +"ToString" { count (3); return (PARSEOP_TOSTRING); } +"ToUuid" { count (1); return (PARSEOP_TOUUID); } +"Unicode" { count (1); return (PARSEOP_UNICODE); } +"Unload" { count (3); return (PARSEOP_UNLOAD); } +"Wait" { count (3); return (PARSEOP_WAIT); } +"While" { count (3); return (PARSEOP_WHILE); } +"XOr" { count (3); return (PARSEOP_XOR); } +"Zero" { count (1); return (PARSEOP_ZERO); } + + /* Control method arguments and locals */ + +"Arg0" { count (1); return (PARSEOP_ARG0); } +"Arg1" { count (1); return (PARSEOP_ARG1); } +"Arg2" { count (1); return (PARSEOP_ARG2); } +"Arg3" { count (1); return (PARSEOP_ARG3); } +"Arg4" { count (1); return (PARSEOP_ARG4); } +"Arg5" { count (1); return (PARSEOP_ARG5); } +"Arg6" { count (1); return (PARSEOP_ARG6); } +"Local0" { count (1); return (PARSEOP_LOCAL0); } +"Local1" { count (1); return (PARSEOP_LOCAL1); } +"Local2" { count (1); return (PARSEOP_LOCAL2); } +"Local3" { count (1); return (PARSEOP_LOCAL3); } +"Local4" { count (1); return (PARSEOP_LOCAL4); } +"Local5" { count (1); return (PARSEOP_LOCAL5); } +"Local6" { count (1); return (PARSEOP_LOCAL6); } +"Local7" { count (1); return (PARSEOP_LOCAL7); } + + + /**************************************************************************** + * + * Resource Descriptor macros + * + ****************************************************************************/ + +"ResourceTemplate" { count (1); return (PARSEOP_RESOURCETEMPLATE); } +"RawDataBuffer" { count (1); return (PARSEOP_DATABUFFER); } + +"DMA" { count (1); return (PARSEOP_DMA); } +"DWordIO" { count (1); return (PARSEOP_DWORDIO); } +"DWordMemory" { count (1); return (PARSEOP_DWORDMEMORY); } +"DWordSpace" { count (1); return (PARSEOP_DWORDSPACE); } +"EndDependentFn" { count (1); return (PARSEOP_ENDDEPENDENTFN); } +"ExtendedIO" { count (1); return (PARSEOP_EXTENDEDIO); } +"ExtendedMemory" { count (1); return (PARSEOP_EXTENDEDMEMORY); } +"ExtendedSpace" { count (1); return (PARSEOP_EXTENDEDSPACE); } +"FixedDma" { count (1); return (PARSEOP_FIXEDDMA); } +"FixedIO" { count (1); return (PARSEOP_FIXEDIO); } +"GpioInt" { count (1); return (PARSEOP_GPIO_INT); } +"GpioIo" { count (1); return (PARSEOP_GPIO_IO); } +"I2cSerialBus" { count (1); return (PARSEOP_I2C_SERIALBUS); } +"Interrupt" { count (1); return (PARSEOP_INTERRUPT); } +"IO" { count (1); return (PARSEOP_IO); } +"IRQ" { count (1); return (PARSEOP_IRQ); } +"IRQNoFlags" { count (1); return (PARSEOP_IRQNOFLAGS); } +"Memory24" { count (1); return (PARSEOP_MEMORY24); } +"Memory32" { count (1); return (PARSEOP_MEMORY32); } +"Memory32Fixed" { count (1); return (PARSEOP_MEMORY32FIXED); } +"QWordIO" { count (1); return (PARSEOP_QWORDIO); } +"QWordMemory" { count (1); return (PARSEOP_QWORDMEMORY); } +"QWordSpace" { count (1); return (PARSEOP_QWORDSPACE); } +"Register" { count (1); return (PARSEOP_REGISTER); } +"SpiSerialBus" { count (1); return (PARSEOP_SPI_SERIALBUS); } +"StartDependentFn" { count (1); return (PARSEOP_STARTDEPENDENTFN); } +"StartDependentFnNoPri" { count (1); return (PARSEOP_STARTDEPENDENTFN_NOPRI); } +"UartSerialBus" { count (1); return (PARSEOP_UART_SERIALBUS); } +"VendorLong" { count (1); return (PARSEOP_VENDORLONG); } +"VendorShort" { count (1); return (PARSEOP_VENDORSHORT); } +"WordBusNumber" { count (1); return (PARSEOP_WORDBUSNUMBER); } +"WordIO" { count (1); return (PARSEOP_WORDIO); } +"WordSpace" { count (1); return (PARSEOP_WORDSPACE); } + + + /**************************************************************************** + * + * Keywords used as arguments to ASL operators and macros + * + ****************************************************************************/ + + /* AccessAttribKeyword: Serial Bus Attributes (ACPI 5.0) */ + +"AttribQuick" { count (0); return (PARSEOP_ACCESSATTRIB_QUICK); } +"AttribSendReceive" { count (0); return (PARSEOP_ACCESSATTRIB_SND_RCV); } +"AttribByte" { count (0); return (PARSEOP_ACCESSATTRIB_BYTE); } +"AttribWord" { count (0); return (PARSEOP_ACCESSATTRIB_WORD); } +"AttribBlock" { count (0); return (PARSEOP_ACCESSATTRIB_BLOCK); } +"AttribProcessCall" { count (0); return (PARSEOP_ACCESSATTRIB_WORD_CALL); } +"AttribBlockProcessCall" { count (0); return (PARSEOP_ACCESSATTRIB_BLOCK_CALL); } + + /* AccessAttribKeyword: Legacy synonyms for above (pre-ACPI 5.0) */ + +"SMBQuick" { count (0); return (PARSEOP_ACCESSATTRIB_QUICK); } +"SMBSendReceive" { count (0); return (PARSEOP_ACCESSATTRIB_SND_RCV); } +"SMBByte" { count (0); return (PARSEOP_ACCESSATTRIB_BYTE); } +"SMBWord" { count (0); return (PARSEOP_ACCESSATTRIB_WORD); } +"SMBBlock" { count (0); return (PARSEOP_ACCESSATTRIB_BLOCK); } +"SMBProcessCall" { count (0); return (PARSEOP_ACCESSATTRIB_WORD_CALL); } +"SMBBlockProcessCall" { count (0); return (PARSEOP_ACCESSATTRIB_BLOCK_CALL); } + + /* AccessTypeKeyword: Field Access Types */ + +"AnyAcc" { count (0); return (PARSEOP_ACCESSTYPE_ANY); } +"ByteAcc" { count (0); return (PARSEOP_ACCESSTYPE_BYTE); } +"WordAcc" { count (0); return (PARSEOP_ACCESSTYPE_WORD); } +"DWordAcc" { count (0); return (PARSEOP_ACCESSTYPE_DWORD); } +"QWordAcc" { count (0); return (PARSEOP_ACCESSTYPE_QWORD); } +"BufferAcc" { count (0); return (PARSEOP_ACCESSTYPE_BUF); } + + /* AddressingModeKeyword: Mode - Resource Descriptors (ACPI 5.0) */ + +"AddressingMode7Bit" { count (0); return (PARSEOP_ADDRESSINGMODE_7BIT); } +"AddressingMode10Bit" { count (0); return (PARSEOP_ADDRESSINGMODE_10BIT); } + + /* AddressKeyword: ACPI memory range types */ + +"AddressRangeMemory" { count (0); return (PARSEOP_ADDRESSTYPE_MEMORY); } +"AddressRangeReserved" { count (0); return (PARSEOP_ADDRESSTYPE_RESERVED); } +"AddressRangeNVS" { count (0); return (PARSEOP_ADDRESSTYPE_NVS); } +"AddressRangeACPI" { count (0); return (PARSEOP_ADDRESSTYPE_ACPI); } + + /* BusMasterKeyword: DMA Bus Mastering */ + +"BusMaster" { count (0); return (PARSEOP_BUSMASTERTYPE_MASTER); } +"NotBusMaster" { count (0); return (PARSEOP_BUSMASTERTYPE_NOTMASTER); } + + /* ByteLengthKeyword: Bits per Byte - Resource Descriptors (ACPI 5.0) */ + +"DataBitsFive" { count (0); return (PARSEOP_BITSPERBYTE_FIVE); } +"DataBitsSix" { count (0); return (PARSEOP_BITSPERBYTE_SIX); } +"DataBitsSeven" { count (0); return (PARSEOP_BITSPERBYTE_SEVEN); } +"DataBitsEight" { count (0); return (PARSEOP_BITSPERBYTE_EIGHT); } +"DataBitsNine" { count (0); return (PARSEOP_BITSPERBYTE_NINE); } + + /* ClockPhaseKeyword: Resource Descriptors (ACPI 5.0) */ + +"ClockPhaseFirst" { count (0); return (PARSEOP_CLOCKPHASE_FIRST); } +"ClockPhaseSecond" { count (0); return (PARSEOP_CLOCKPHASE_SECOND); } + + /* ClockPolarityKeyword: Resource Descriptors (ACPI 5.0) */ + +"ClockPolarityLow" { count (0); return (PARSEOP_CLOCKPOLARITY_LOW); } +"ClockPolarityHigh" { count (0); return (PARSEOP_CLOCKPOLARITY_HIGH); } + + /* DecodeKeyword: Type of Memory Decoding - Resource Descriptors */ + +"PosDecode" { count (0); return (PARSEOP_DECODETYPE_POS); } +"SubDecode" { count (0); return (PARSEOP_DECODETYPE_SUB); } + + /* DmaTypeKeyword: DMA Types - DMA Resource Descriptor */ + +"Compatibility" { count (0); return (PARSEOP_DMATYPE_COMPATIBILITY); } +"TypeA" { count (0); return (PARSEOP_DMATYPE_A); } +"TypeB" { count (0); return (PARSEOP_DMATYPE_B); } +"TypeF" { count (0); return (PARSEOP_DMATYPE_F); } + + /* EndianKeyword: Endian type - Resource Descriptor (ACPI 5.0) */ + +"LittleEndian" { count (0); return (PARSEOP_ENDIAN_LITTLE); } +"BigEndian" { count (0); return (PARSEOP_ENDIAN_BIG); } + + /* ExtendedAttribKeyword: Bus attributes, AccessAs operator (ACPI 5.0) */ + +"AttribBytes" { count (0); return (PARSEOP_ACCESSATTRIB_MULTIBYTE); } +"AttribRawBytes" { count (0); return (PARSEOP_ACCESSATTRIB_RAW_BYTES); } +"AttribRawProcessBytes" { count (0); return (PARSEOP_ACCESSATTRIB_RAW_PROCESS); } + + /* FlowControlKeyword: Resource Descriptors (ACPI 5.0) */ + +"FlowControlHardware" { count (0); return (PARSEOP_FLOWCONTROL_HW); } +"FlowControlNone" { count (0); return (PARSEOP_FLOWCONTROL_NONE); } +"FlowControlXon" { count (0); return (PARSEOP_FLOWCONTROL_SW); } + + /* InterruptLevelKeyword: Interrupt Active Types */ + +"ActiveBoth" { count (0); return (PARSEOP_INTLEVEL_ACTIVEBOTH); } +"ActiveHigh" { count (0); return (PARSEOP_INTLEVEL_ACTIVEHIGH); } +"ActiveLow" { count (0); return (PARSEOP_INTLEVEL_ACTIVELOW); } + + /* InterruptTypeKeyword: Interrupt Types */ + +"Edge" { count (0); return (PARSEOP_INTTYPE_EDGE); } +"Level" { count (0); return (PARSEOP_INTTYPE_LEVEL); } + + /* IoDecodeKeyword: Type of Memory Decoding - Resource Descriptors */ + +"Decode10" { count (0); return (PARSEOP_IODECODETYPE_10); } +"Decode16" { count (0); return (PARSEOP_IODECODETYPE_16); } + + /* IoRestrictionKeyword: I/O Restriction - GPIO Resource Descriptors (ACPI 5.0) */ + +"IoRestrictionNone" { count (0); return (PARSEOP_IORESTRICT_NONE); } +"IoRestrictionInputOnly" { count (0); return (PARSEOP_IORESTRICT_IN); } +"IoRestrictionOutputOnly" { count (0); return (PARSEOP_IORESTRICT_OUT); } +"IoRestrictionNoneAndPreserve" { count (0); return (PARSEOP_IORESTRICT_PRESERVE); } + + /* LockRuleKeyword: Global Lock use for Field Operator */ + +"Lock" { count (0); return (PARSEOP_LOCKRULE_LOCK); } +"NoLock" { count (0); return (PARSEOP_LOCKRULE_NOLOCK); } + + /* MatchOpKeyword: Types for Match Operator */ + +"MTR" { count (0); return (PARSEOP_MATCHTYPE_MTR); } +"MEQ" { count (0); return (PARSEOP_MATCHTYPE_MEQ); } +"MLE" { count (0); return (PARSEOP_MATCHTYPE_MLE); } +"MLT" { count (0); return (PARSEOP_MATCHTYPE_MLT); } +"MGE" { count (0); return (PARSEOP_MATCHTYPE_MGE); } +"MGT" { count (0); return (PARSEOP_MATCHTYPE_MGT); } + + /* MaxKeyword: Max Range Type - Resource Descriptors */ + +"MaxFixed" { count (0); return (PARSEOP_MAXTYPE_FIXED); } +"MaxNotFixed" { count (0); return (PARSEOP_MAXTYPE_NOTFIXED); } + + /* MemTypeKeyword: Memory Types - Resource Descriptors */ + +"Cacheable" { count (0); return (PARSEOP_MEMTYPE_CACHEABLE); } +"WriteCombining" { count (0); return (PARSEOP_MEMTYPE_WRITECOMBINING); } +"Prefetchable" { count (0); return (PARSEOP_MEMTYPE_PREFETCHABLE); } +"NonCacheable" { count (0); return (PARSEOP_MEMTYPE_NONCACHEABLE); } + + /* MinKeyword: Min Range Type - Resource Descriptors */ + +"MinFixed" { count (0); return (PARSEOP_MINTYPE_FIXED); } +"MinNotFixed" { count (0); return (PARSEOP_MINTYPE_NOTFIXED); } + + /* ObjectTypeKeyword: ACPI Object Types */ + +"UnknownObj" { count (0); return (PARSEOP_OBJECTTYPE_UNK); } +"IntObj" { count (0); return (PARSEOP_OBJECTTYPE_INT); } +"StrObj" { count (0); return (PARSEOP_OBJECTTYPE_STR); } +"BuffObj" { count (0); return (PARSEOP_OBJECTTYPE_BUF); } +"PkgObj" { count (0); return (PARSEOP_OBJECTTYPE_PKG); } +"FieldUnitObj" { count (0); return (PARSEOP_OBJECTTYPE_FLD); } +"DeviceObj" { count (0); return (PARSEOP_OBJECTTYPE_DEV); } +"EventObj" { count (0); return (PARSEOP_OBJECTTYPE_EVT); } +"MethodObj" { count (0); return (PARSEOP_OBJECTTYPE_MTH); } +"MutexObj" { count (0); return (PARSEOP_OBJECTTYPE_MTX); } +"OpRegionObj" { count (0); return (PARSEOP_OBJECTTYPE_OPR); } +"PowerResObj" { count (0); return (PARSEOP_OBJECTTYPE_POW); } +"ProcessorObj" { count (0); return (PARSEOP_OBJECTTYPE_PRO); } +"ThermalZoneObj" { count (0); return (PARSEOP_OBJECTTYPE_THZ); } +"BuffFieldObj" { count (0); return (PARSEOP_OBJECTTYPE_BFF); } +"DDBHandleObj" { count (0); return (PARSEOP_OBJECTTYPE_DDB); } + + /* ParityKeyword: Resource Descriptors (ACPI 5.0) */ + +"ParityTypeSpace" { count (0); return (PARSEOP_PARITYTYPE_SPACE); } +"ParityTypeMark" { count (0); return (PARSEOP_PARITYTYPE_MARK); } +"ParityTypeOdd" { count (0); return (PARSEOP_PARITYTYPE_ODD); } +"ParityTypeEven" { count (0); return (PARSEOP_PARITYTYPE_EVEN); } +"ParityTypeNone" { count (0); return (PARSEOP_PARITYTYPE_NONE); } + + /* PinConfigKeyword: Pin Configuration - GPIO Resource Descriptors (ACPI 5.0) */ + +"PullDefault" { count (0); return (PARSEOP_PIN_PULLDEFAULT); } +"PullUp" { count (0); return (PARSEOP_PIN_PULLUP); } +"PullDown" { count (0); return (PARSEOP_PIN_PULLDOWN); } +"PullNone" { count (0); return (PARSEOP_PIN_NOPULL); } + + /* PolarityKeyword: Resource Descriptors (ACPI 5.0) */ + +"PolarityLow" { count (0); return (PARSEOP_DEVICEPOLARITY_LOW); } +"PolarityHigh" { count (0); return (PARSEOP_DEVICEPOLARITY_HIGH); } + + /* RangeTypeKeyword: I/O Range Types - Resource Descriptors */ + +"ISAOnlyRanges" { count (0); return (PARSEOP_RANGETYPE_ISAONLY); } +"NonISAOnlyRanges" { count (0); return (PARSEOP_RANGETYPE_NONISAONLY); } +"EntireRange" { count (0); return (PARSEOP_RANGETYPE_ENTIRE); } + + /* ReadWriteKeyword: Memory Access Types - Resource Descriptors */ + +"ReadWrite" { count (0); return (PARSEOP_READWRITETYPE_BOTH); } +"ReadOnly" { count (0); return (PARSEOP_READWRITETYPE_READONLY); } + + /* RegionSpaceKeyword: Operation Region Address Space Types */ + +"SystemIO" { count (0); return (PARSEOP_REGIONSPACE_IO); } +"SystemMemory" { count (0); return (PARSEOP_REGIONSPACE_MEM); } +"PCI_Config" { count (0); return (PARSEOP_REGIONSPACE_PCI); } +"EmbeddedControl" { count (0); return (PARSEOP_REGIONSPACE_EC); } +"SMBus" { count (0); return (PARSEOP_REGIONSPACE_SMBUS); } +"SystemCMOS" { count (0); return (PARSEOP_REGIONSPACE_CMOS); } +"PciBarTarget" { count (0); return (PARSEOP_REGIONSPACE_PCIBAR); } +"IPMI" { count (0); return (PARSEOP_REGIONSPACE_IPMI); } +"GeneralPurposeIo" { count (0); return (PARSEOP_REGIONSPACE_GPIO); } /* ACPI 5.0 */ +"GenericSerialBus" { count (0); return (PARSEOP_REGIONSPACE_GSBUS); } /* ACPI 5.0 */ +"FFixedHW" { count (0); return (PARSEOP_REGIONSPACE_FFIXEDHW); } + + /* ResourceTypeKeyword: Resource Usage - Resource Descriptors */ + +"ResourceConsumer" { count (0); return (PARSEOP_RESOURCETYPE_CONSUMER); } +"ResourceProducer" { count (0); return (PARSEOP_RESOURCETYPE_PRODUCER); } + + /* SerializeRuleKeyword: Control Method Serialization */ + +"Serialized" { count (0); return (PARSEOP_SERIALIZERULE_SERIAL); } +"NotSerialized" { count (0); return (PARSEOP_SERIALIZERULE_NOTSERIAL); } + + /* ShareTypeKeyword: Interrupt Sharing - Resource Descriptors */ + +"Shared" { count (0); return (PARSEOP_SHARETYPE_SHARED); } +"Exclusive" { count (0); return (PARSEOP_SHARETYPE_EXCLUSIVE); } +"SharedAndWake" { count (0); return (PARSEOP_SHARETYPE_SHAREDWAKE); } /* ACPI 5.0 */ +"ExclusiveAndWake" { count (0); return (PARSEOP_SHARETYPE_EXCLUSIVEWAKE); } /* ACPI 5.0 */ + + /* SlaveModeKeyword: Resource Descriptors (ACPI 5.0) */ + +"ControllerInitiated" { count (0); return (PARSEOP_SLAVEMODE_CONTROLLERINIT); } +"DeviceInitiated" { count (0); return (PARSEOP_SLAVEMODE_DEVICEINIT); } + + /* StopBitsKeyword: Resource Descriptors (ACPI 5.0) */ + +"StopBitsOne" { count (0); return (PARSEOP_STOPBITS_ONE); } +"StopBitsOnePlusHalf" { count (0); return (PARSEOP_STOPBITS_ONEPLUSHALF); } +"StopBitsTwo" { count (0); return (PARSEOP_STOPBITS_TWO); } +"StopBitsZero" { count (0); return (PARSEOP_STOPBITS_ZERO); } + + /* TransferWidthKeyword: DMA Widths - Fixed DMA Resource Descriptor (ACPI 5.0) */ + +"Width8bit" { count (0); return (PARSEOP_XFERSIZE_8); } +"Width16bit" { count (0); return (PARSEOP_XFERSIZE_16); } +"Width32bit" { count (0); return (PARSEOP_XFERSIZE_32); } +"Width64bit" { count (0); return (PARSEOP_XFERSIZE_64); } +"Width128bit" { count (0); return (PARSEOP_XFERSIZE_128); } +"Width256bit" { count (0); return (PARSEOP_XFERSIZE_256); } + + /* TranslationKeyword: Translation Density Types - Resource Descriptors */ + +"SparseTranslation" { count (0); return (PARSEOP_TRANSLATIONTYPE_SPARSE); } +"DenseTranslation" { count (0); return (PARSEOP_TRANSLATIONTYPE_DENSE); } + + /* TypeKeyword: Translation Types - Resource Descriptors */ + +"TypeTranslation" { count (0); return (PARSEOP_TYPE_TRANSLATION); } +"TypeStatic" { count (0); return (PARSEOP_TYPE_STATIC); } + + /* UpdateRuleKeyword: Field Update Rules */ + +"Preserve" { count (0); return (PARSEOP_UPDATERULE_PRESERVE); } +"WriteAsOnes" { count (0); return (PARSEOP_UPDATERULE_ONES); } +"WriteAsZeros" { count (0); return (PARSEOP_UPDATERULE_ZEROS); } + + /* WireModeKeyword: SPI Wire Mode - Resource Descriptors (ACPI 5.0) */ + +"FourWireMode" { count (0); return (PARSEOP_WIREMODE_FOUR); } +"ThreeWireMode" { count (0); return (PARSEOP_WIREMODE_THREE); } + + /* XferTypeKeyword: DMA Transfer Types */ + +"Transfer8" { count (0); return (PARSEOP_XFERTYPE_8); } +"Transfer8_16" { count (0); return (PARSEOP_XFERTYPE_8_16); } +"Transfer16" { count (0); return (PARSEOP_XFERTYPE_16); } + + /* Predefined compiler names */ + +"__DATE__" { count (0); return (PARSEOP___DATE__); } +"__FILE__" { count (0); return (PARSEOP___FILE__); } +"__LINE__" { count (0); return (PARSEOP___LINE__); } +"__PATH__" { count (0); return (PARSEOP___PATH__); } + + +"{" { count (0); return('{'); } +"}" { count (0); return('}'); } +"," { count (0); return(','); } +"(" { count (0); return('('); } +")" { count (0); return(')'); } + +{NameSeg} { char *s; + count (0); + s=malloc (ACPI_NAME_SIZE + 1); + if (strcmp (AslCompilertext, "\\")) + { + strcpy (s, "____"); + AcpiUtStrupr (AslCompilertext); + } + memcpy (s, AslCompilertext, strlen (AslCompilertext)); + AslCompilerlval.s = s; + DbgPrint (ASL_PARSE_OUTPUT, "NameSeg: %s\n", s); + return (PARSEOP_NAMESEG); } + +{NameString} { char *s; + count (0); + s=malloc (strlen (AslCompilertext)+1); + AcpiUtStrupr (AslCompilertext); + strcpy (s, AslCompilertext); + s[strlen (AslCompilertext)] = 0; + AslCompilerlval.s = s; + DbgPrint (ASL_PARSE_OUTPUT, "NameString: %s\n", s); + return (PARSEOP_NAMESTRING); } + +"*" | +"/" { count (1); + AslCompilererror ("Parse error, expecting ASL keyword or name");} + +. { count (1); + sprintf (MsgBuffer, + "Invalid character (0x%2.2X), expecting ASL keyword or name", + *AslCompilertext); + AslCompilererror (MsgBuffer);} + +<<EOF>> { if (AslPopInputFileStack ()) + yyterminate(); + else + return (PARSEOP_INCLUDE_END);}; + +%% + +/*! [End] no source code translation !*/ + +/* + * Bring in the scanner support routines + */ +#include <contrib/dev/acpica/compiler/aslsupport.l> diff --git a/sys/contrib/dev/acpica/compiler/aslcompiler.y b/sys/contrib/dev/acpica/compiler/aslcompiler.y new file mode 100644 index 0000000..0c53c23 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslcompiler.y @@ -0,0 +1,3564 @@ +%{ +/****************************************************************************** + * + * Module Name: aslcompiler.y - Bison/Yacc input file (ASL grammar and actions) + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <contrib/dev/acpica/include/acpi.h> +#include <contrib/dev/acpica/include/accommon.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslparse") + +/* + * Global Notes: + * + * October 2005: The following list terms have been optimized (from the + * original ASL grammar in the ACPI specification) to force the immediate + * reduction of each list item so that the parse stack use doesn't increase on + * each list element and possibly overflow on very large lists (>4000 items). + * This dramatically reduces use of the parse stack overall. + * + * ArgList, TermList, Objectlist, ByteList, DWordList, PackageList, + * ResourceMacroList, and FieldUnitList + */ + +void * AslLocalAllocate (unsigned int Size); + +/* Bison/yacc configuration */ + +#define static +#undef alloca +#define alloca AslLocalAllocate +#define yytname AslCompilername + +#define YYINITDEPTH 600 /* State stack depth */ +#define YYDEBUG 1 /* Enable debug output */ +#define YYERROR_VERBOSE 1 /* Verbose error messages */ + +/* Define YYMALLOC/YYFREE to prevent redefinition errors */ + +#define YYMALLOC malloc +#define YYFREE free + +/* + * The windows version of bison defines this incorrectly as "32768" (Not negative). + * We use a custom (edited binary) version of bison that defines YYFLAG as YYFBAD + * instead (#define YYFBAD 32768), so we can define it correctly here. + * + * The problem is that if YYFLAG is positive, the extended syntax error messages + * are disabled. + */ +#define YYFLAG -32768 + +%} + +/* + * Declare the type of values in the grammar + */ +%union { + UINT64 i; + char *s; + ACPI_PARSE_OBJECT *n; +} + +/*! [Begin] no source code translation */ + +/* + * These shift/reduce conflicts are expected. There should be zero + * reduce/reduce conflicts. + */ +%expect 86 + +/****************************************************************************** + * + * Token types: These are returned by the lexer + * + * NOTE: This list MUST match the AslKeywordMapping table found + * in aslmap.c EXACTLY! Double check any changes! + * + *****************************************************************************/ + +%token <i> PARSEOP_ACCESSAS +%token <i> PARSEOP_ACCESSATTRIB_BLOCK +%token <i> PARSEOP_ACCESSATTRIB_BLOCK_CALL +%token <i> PARSEOP_ACCESSATTRIB_BYTE +%token <i> PARSEOP_ACCESSATTRIB_MULTIBYTE +%token <i> PARSEOP_ACCESSATTRIB_QUICK +%token <i> PARSEOP_ACCESSATTRIB_RAW_BYTES +%token <i> PARSEOP_ACCESSATTRIB_RAW_PROCESS +%token <i> PARSEOP_ACCESSATTRIB_SND_RCV +%token <i> PARSEOP_ACCESSATTRIB_WORD +%token <i> PARSEOP_ACCESSATTRIB_WORD_CALL +%token <i> PARSEOP_ACCESSTYPE_ANY +%token <i> PARSEOP_ACCESSTYPE_BUF +%token <i> PARSEOP_ACCESSTYPE_BYTE +%token <i> PARSEOP_ACCESSTYPE_DWORD +%token <i> PARSEOP_ACCESSTYPE_QWORD +%token <i> PARSEOP_ACCESSTYPE_WORD +%token <i> PARSEOP_ACQUIRE +%token <i> PARSEOP_ADD +%token <i> PARSEOP_ADDRESSINGMODE_7BIT +%token <i> PARSEOP_ADDRESSINGMODE_10BIT +%token <i> PARSEOP_ADDRESSTYPE_ACPI +%token <i> PARSEOP_ADDRESSTYPE_MEMORY +%token <i> PARSEOP_ADDRESSTYPE_NVS +%token <i> PARSEOP_ADDRESSTYPE_RESERVED +%token <i> PARSEOP_ALIAS +%token <i> PARSEOP_AND +%token <i> PARSEOP_ARG0 +%token <i> PARSEOP_ARG1 +%token <i> PARSEOP_ARG2 +%token <i> PARSEOP_ARG3 +%token <i> PARSEOP_ARG4 +%token <i> PARSEOP_ARG5 +%token <i> PARSEOP_ARG6 +%token <i> PARSEOP_BANKFIELD +%token <i> PARSEOP_BITSPERBYTE_EIGHT +%token <i> PARSEOP_BITSPERBYTE_FIVE +%token <i> PARSEOP_BITSPERBYTE_NINE +%token <i> PARSEOP_BITSPERBYTE_SEVEN +%token <i> PARSEOP_BITSPERBYTE_SIX +%token <i> PARSEOP_BREAK +%token <i> PARSEOP_BREAKPOINT +%token <i> PARSEOP_BUFFER +%token <i> PARSEOP_BUSMASTERTYPE_MASTER +%token <i> PARSEOP_BUSMASTERTYPE_NOTMASTER +%token <i> PARSEOP_BYTECONST +%token <i> PARSEOP_CASE +%token <i> PARSEOP_CLOCKPHASE_FIRST +%token <i> PARSEOP_CLOCKPHASE_SECOND +%token <i> PARSEOP_CLOCKPOLARITY_HIGH +%token <i> PARSEOP_CLOCKPOLARITY_LOW +%token <i> PARSEOP_CONCATENATE +%token <i> PARSEOP_CONCATENATERESTEMPLATE +%token <i> PARSEOP_CONDREFOF +%token <i> PARSEOP_CONNECTION +%token <i> PARSEOP_CONTINUE +%token <i> PARSEOP_COPYOBJECT +%token <i> PARSEOP_CREATEBITFIELD +%token <i> PARSEOP_CREATEBYTEFIELD +%token <i> PARSEOP_CREATEDWORDFIELD +%token <i> PARSEOP_CREATEFIELD +%token <i> PARSEOP_CREATEQWORDFIELD +%token <i> PARSEOP_CREATEWORDFIELD +%token <i> PARSEOP_DATABUFFER +%token <i> PARSEOP_DATATABLEREGION +%token <i> PARSEOP_DEBUG +%token <i> PARSEOP_DECODETYPE_POS +%token <i> PARSEOP_DECODETYPE_SUB +%token <i> PARSEOP_DECREMENT +%token <i> PARSEOP_DEFAULT +%token <i> PARSEOP_DEFAULT_ARG +%token <i> PARSEOP_DEFINITIONBLOCK +%token <i> PARSEOP_DEREFOF +%token <i> PARSEOP_DEVICE +%token <i> PARSEOP_DEVICEPOLARITY_HIGH +%token <i> PARSEOP_DEVICEPOLARITY_LOW +%token <i> PARSEOP_DIVIDE +%token <i> PARSEOP_DMA +%token <i> PARSEOP_DMATYPE_A +%token <i> PARSEOP_DMATYPE_COMPATIBILITY +%token <i> PARSEOP_DMATYPE_B +%token <i> PARSEOP_DMATYPE_F +%token <i> PARSEOP_DWORDCONST +%token <i> PARSEOP_DWORDIO +%token <i> PARSEOP_DWORDMEMORY +%token <i> PARSEOP_DWORDSPACE +%token <i> PARSEOP_EISAID +%token <i> PARSEOP_ELSE +%token <i> PARSEOP_ELSEIF +%token <i> PARSEOP_ENDDEPENDENTFN +%token <i> PARSEOP_ENDIAN_BIG +%token <i> PARSEOP_ENDIAN_LITTLE +%token <i> PARSEOP_ENDTAG +%token <i> PARSEOP_ERRORNODE +%token <i> PARSEOP_EVENT +%token <i> PARSEOP_EXTENDEDIO +%token <i> PARSEOP_EXTENDEDMEMORY +%token <i> PARSEOP_EXTENDEDSPACE +%token <i> PARSEOP_EXTERNAL +%token <i> PARSEOP_FATAL +%token <i> PARSEOP_FIELD +%token <i> PARSEOP_FINDSETLEFTBIT +%token <i> PARSEOP_FINDSETRIGHTBIT +%token <i> PARSEOP_FIXEDDMA +%token <i> PARSEOP_FIXEDIO +%token <i> PARSEOP_FLOWCONTROL_HW +%token <i> PARSEOP_FLOWCONTROL_NONE +%token <i> PARSEOP_FLOWCONTROL_SW +%token <i> PARSEOP_FROMBCD +%token <i> PARSEOP_FUNCTION +%token <i> PARSEOP_GPIO_INT +%token <i> PARSEOP_GPIO_IO +%token <i> PARSEOP_I2C_SERIALBUS +%token <i> PARSEOP_IF +%token <i> PARSEOP_INCLUDE +%token <i> PARSEOP_INCLUDE_END +%token <i> PARSEOP_INCREMENT +%token <i> PARSEOP_INDEX +%token <i> PARSEOP_INDEXFIELD +%token <i> PARSEOP_INTEGER +%token <i> PARSEOP_INTERRUPT +%token <i> PARSEOP_INTLEVEL_ACTIVEBOTH +%token <i> PARSEOP_INTLEVEL_ACTIVEHIGH +%token <i> PARSEOP_INTLEVEL_ACTIVELOW +%token <i> PARSEOP_INTTYPE_EDGE +%token <i> PARSEOP_INTTYPE_LEVEL +%token <i> PARSEOP_IO +%token <i> PARSEOP_IODECODETYPE_10 +%token <i> PARSEOP_IODECODETYPE_16 +%token <i> PARSEOP_IORESTRICT_IN +%token <i> PARSEOP_IORESTRICT_NONE +%token <i> PARSEOP_IORESTRICT_OUT +%token <i> PARSEOP_IORESTRICT_PRESERVE +%token <i> PARSEOP_IRQ +%token <i> PARSEOP_IRQNOFLAGS +%token <i> PARSEOP_LAND +%token <i> PARSEOP_LEQUAL +%token <i> PARSEOP_LGREATER +%token <i> PARSEOP_LGREATEREQUAL +%token <i> PARSEOP_LLESS +%token <i> PARSEOP_LLESSEQUAL +%token <i> PARSEOP_LNOT +%token <i> PARSEOP_LNOTEQUAL +%token <i> PARSEOP_LOAD +%token <i> PARSEOP_LOADTABLE +%token <i> PARSEOP_LOCAL0 +%token <i> PARSEOP_LOCAL1 +%token <i> PARSEOP_LOCAL2 +%token <i> PARSEOP_LOCAL3 +%token <i> PARSEOP_LOCAL4 +%token <i> PARSEOP_LOCAL5 +%token <i> PARSEOP_LOCAL6 +%token <i> PARSEOP_LOCAL7 +%token <i> PARSEOP_LOCKRULE_LOCK +%token <i> PARSEOP_LOCKRULE_NOLOCK +%token <i> PARSEOP_LOR +%token <i> PARSEOP_MATCH +%token <i> PARSEOP_MATCHTYPE_MEQ +%token <i> PARSEOP_MATCHTYPE_MGE +%token <i> PARSEOP_MATCHTYPE_MGT +%token <i> PARSEOP_MATCHTYPE_MLE +%token <i> PARSEOP_MATCHTYPE_MLT +%token <i> PARSEOP_MATCHTYPE_MTR +%token <i> PARSEOP_MAXTYPE_FIXED +%token <i> PARSEOP_MAXTYPE_NOTFIXED +%token <i> PARSEOP_MEMORY24 +%token <i> PARSEOP_MEMORY32 +%token <i> PARSEOP_MEMORY32FIXED +%token <i> PARSEOP_MEMTYPE_CACHEABLE +%token <i> PARSEOP_MEMTYPE_NONCACHEABLE +%token <i> PARSEOP_MEMTYPE_PREFETCHABLE +%token <i> PARSEOP_MEMTYPE_WRITECOMBINING +%token <i> PARSEOP_METHOD +%token <i> PARSEOP_METHODCALL +%token <i> PARSEOP_MID +%token <i> PARSEOP_MINTYPE_FIXED +%token <i> PARSEOP_MINTYPE_NOTFIXED +%token <i> PARSEOP_MOD +%token <i> PARSEOP_MULTIPLY +%token <i> PARSEOP_MUTEX +%token <i> PARSEOP_NAME +%token <s> PARSEOP_NAMESEG +%token <s> PARSEOP_NAMESTRING +%token <i> PARSEOP_NAND +%token <i> PARSEOP_NOOP +%token <i> PARSEOP_NOR +%token <i> PARSEOP_NOT +%token <i> PARSEOP_NOTIFY +%token <i> PARSEOP_OBJECTTYPE +%token <i> PARSEOP_OBJECTTYPE_BFF +%token <i> PARSEOP_OBJECTTYPE_BUF +%token <i> PARSEOP_OBJECTTYPE_DDB +%token <i> PARSEOP_OBJECTTYPE_DEV +%token <i> PARSEOP_OBJECTTYPE_EVT +%token <i> PARSEOP_OBJECTTYPE_FLD +%token <i> PARSEOP_OBJECTTYPE_INT +%token <i> PARSEOP_OBJECTTYPE_MTH +%token <i> PARSEOP_OBJECTTYPE_MTX +%token <i> PARSEOP_OBJECTTYPE_OPR +%token <i> PARSEOP_OBJECTTYPE_PKG +%token <i> PARSEOP_OBJECTTYPE_POW +%token <i> PARSEOP_OBJECTTYPE_PRO +%token <i> PARSEOP_OBJECTTYPE_STR +%token <i> PARSEOP_OBJECTTYPE_THZ +%token <i> PARSEOP_OBJECTTYPE_UNK +%token <i> PARSEOP_OFFSET +%token <i> PARSEOP_ONE +%token <i> PARSEOP_ONES +%token <i> PARSEOP_OPERATIONREGION +%token <i> PARSEOP_OR +%token <i> PARSEOP_PACKAGE +%token <i> PARSEOP_PACKAGE_LENGTH +%token <i> PARSEOP_PARITYTYPE_EVEN +%token <i> PARSEOP_PARITYTYPE_MARK +%token <i> PARSEOP_PARITYTYPE_NONE +%token <i> PARSEOP_PARITYTYPE_ODD +%token <i> PARSEOP_PARITYTYPE_SPACE +%token <i> PARSEOP_PIN_NOPULL +%token <i> PARSEOP_PIN_PULLDEFAULT +%token <i> PARSEOP_PIN_PULLDOWN +%token <i> PARSEOP_PIN_PULLUP +%token <i> PARSEOP_POWERRESOURCE +%token <i> PARSEOP_PROCESSOR +%token <i> PARSEOP_QWORDCONST +%token <i> PARSEOP_QWORDIO +%token <i> PARSEOP_QWORDMEMORY +%token <i> PARSEOP_QWORDSPACE +%token <i> PARSEOP_RANGETYPE_ENTIRE +%token <i> PARSEOP_RANGETYPE_ISAONLY +%token <i> PARSEOP_RANGETYPE_NONISAONLY +%token <i> PARSEOP_RAW_DATA +%token <i> PARSEOP_READWRITETYPE_BOTH +%token <i> PARSEOP_READWRITETYPE_READONLY +%token <i> PARSEOP_REFOF +%token <i> PARSEOP_REGIONSPACE_CMOS +%token <i> PARSEOP_REGIONSPACE_EC +%token <i> PARSEOP_REGIONSPACE_FFIXEDHW +%token <i> PARSEOP_REGIONSPACE_GPIO +%token <i> PARSEOP_REGIONSPACE_GSBUS +%token <i> PARSEOP_REGIONSPACE_IO +%token <i> PARSEOP_REGIONSPACE_IPMI +%token <i> PARSEOP_REGIONSPACE_MEM +%token <i> PARSEOP_REGIONSPACE_PCI +%token <i> PARSEOP_REGIONSPACE_PCIBAR +%token <i> PARSEOP_REGIONSPACE_SMBUS +%token <i> PARSEOP_REGISTER +%token <i> PARSEOP_RELEASE +%token <i> PARSEOP_RESERVED_BYTES +%token <i> PARSEOP_RESET +%token <i> PARSEOP_RESOURCETEMPLATE +%token <i> PARSEOP_RESOURCETYPE_CONSUMER +%token <i> PARSEOP_RESOURCETYPE_PRODUCER +%token <i> PARSEOP_RETURN +%token <i> PARSEOP_REVISION +%token <i> PARSEOP_SCOPE +%token <i> PARSEOP_SERIALIZERULE_NOTSERIAL +%token <i> PARSEOP_SERIALIZERULE_SERIAL +%token <i> PARSEOP_SHARETYPE_EXCLUSIVE +%token <i> PARSEOP_SHARETYPE_EXCLUSIVEWAKE +%token <i> PARSEOP_SHARETYPE_SHARED +%token <i> PARSEOP_SHARETYPE_SHAREDWAKE +%token <i> PARSEOP_SHIFTLEFT +%token <i> PARSEOP_SHIFTRIGHT +%token <i> PARSEOP_SIGNAL +%token <i> PARSEOP_SIZEOF +%token <i> PARSEOP_SLAVEMODE_CONTROLLERINIT +%token <i> PARSEOP_SLAVEMODE_DEVICEINIT +%token <i> PARSEOP_SLEEP +%token <i> PARSEOP_SPI_SERIALBUS +%token <i> PARSEOP_STALL +%token <i> PARSEOP_STARTDEPENDENTFN +%token <i> PARSEOP_STARTDEPENDENTFN_NOPRI +%token <i> PARSEOP_STOPBITS_ONE +%token <i> PARSEOP_STOPBITS_ONEPLUSHALF +%token <i> PARSEOP_STOPBITS_TWO +%token <i> PARSEOP_STOPBITS_ZERO +%token <i> PARSEOP_STORE +%token <s> PARSEOP_STRING_LITERAL +%token <i> PARSEOP_SUBTRACT +%token <i> PARSEOP_SWITCH +%token <i> PARSEOP_THERMALZONE +%token <i> PARSEOP_TIMER +%token <i> PARSEOP_TOBCD +%token <i> PARSEOP_TOBUFFER +%token <i> PARSEOP_TODECIMALSTRING +%token <i> PARSEOP_TOHEXSTRING +%token <i> PARSEOP_TOINTEGER +%token <i> PARSEOP_TOSTRING +%token <i> PARSEOP_TOUUID +%token <i> PARSEOP_TRANSLATIONTYPE_DENSE +%token <i> PARSEOP_TRANSLATIONTYPE_SPARSE +%token <i> PARSEOP_TYPE_STATIC +%token <i> PARSEOP_TYPE_TRANSLATION +%token <i> PARSEOP_UART_SERIALBUS +%token <i> PARSEOP_UNICODE +%token <i> PARSEOP_UNLOAD +%token <i> PARSEOP_UPDATERULE_ONES +%token <i> PARSEOP_UPDATERULE_PRESERVE +%token <i> PARSEOP_UPDATERULE_ZEROS +%token <i> PARSEOP_VAR_PACKAGE +%token <i> PARSEOP_VENDORLONG +%token <i> PARSEOP_VENDORSHORT +%token <i> PARSEOP_WAIT +%token <i> PARSEOP_WHILE +%token <i> PARSEOP_WIREMODE_FOUR +%token <i> PARSEOP_WIREMODE_THREE +%token <i> PARSEOP_WORDBUSNUMBER +%token <i> PARSEOP_WORDCONST +%token <i> PARSEOP_WORDIO +%token <i> PARSEOP_WORDSPACE +%token <i> PARSEOP_XFERSIZE_8 +%token <i> PARSEOP_XFERSIZE_16 +%token <i> PARSEOP_XFERSIZE_32 +%token <i> PARSEOP_XFERSIZE_64 +%token <i> PARSEOP_XFERSIZE_128 +%token <i> PARSEOP_XFERSIZE_256 +%token <i> PARSEOP_XFERTYPE_8 +%token <i> PARSEOP_XFERTYPE_8_16 +%token <i> PARSEOP_XFERTYPE_16 +%token <i> PARSEOP_XOR +%token <i> PARSEOP_ZERO + +/* + * Special functions. These should probably stay at the end of this + * table. + */ +%token <i> PARSEOP___DATE__ +%token <i> PARSEOP___FILE__ +%token <i> PARSEOP___LINE__ +%token <i> PARSEOP___PATH__ + + +/****************************************************************************** + * + * Production names + * + *****************************************************************************/ + +%type <n> ArgList +%type <n> ASLCode +%type <n> BufferData +%type <n> BufferTermData +%type <n> CompilerDirective +%type <n> DataObject +%type <n> DefinitionBlockTerm +%type <n> IntegerData +%type <n> NamedObject +%type <n> NameSpaceModifier +%type <n> Object +%type <n> ObjectList +%type <n> PackageData +%type <n> ParameterTypePackage +%type <n> ParameterTypePackageList +%type <n> ParameterTypesPackage +%type <n> ParameterTypesPackageList +%type <n> RequiredTarget +%type <n> SimpleTarget +%type <n> StringData +%type <n> Target +%type <n> Term +%type <n> TermArg +%type <n> TermList +%type <n> UserTerm + +/* Type4Opcode is obsolete */ + +%type <n> Type1Opcode +%type <n> Type2BufferOpcode +%type <n> Type2BufferOrStringOpcode +%type <n> Type2IntegerOpcode +%type <n> Type2Opcode +%type <n> Type2StringOpcode +%type <n> Type3Opcode +%type <n> Type5Opcode +%type <n> Type6Opcode + +%type <n> AccessAsTerm +%type <n> ExternalTerm +%type <n> FieldUnit +%type <n> FieldUnitEntry +%type <n> FieldUnitList +%type <n> IncludeTerm +%type <n> OffsetTerm +%type <n> OptionalAccessAttribTerm + +/* Named Objects */ + +%type <n> BankFieldTerm +%type <n> CreateBitFieldTerm +%type <n> CreateByteFieldTerm +%type <n> CreateDWordFieldTerm +%type <n> CreateFieldTerm +%type <n> CreateQWordFieldTerm +%type <n> CreateWordFieldTerm +%type <n> DataRegionTerm +%type <n> DeviceTerm +%type <n> EventTerm +%type <n> FieldTerm +%type <n> FunctionTerm +%type <n> IndexFieldTerm +%type <n> MethodTerm +%type <n> MutexTerm +%type <n> OpRegionTerm +%type <n> OpRegionSpaceIdTerm +%type <n> PowerResTerm +%type <n> ProcessorTerm +%type <n> ThermalZoneTerm + +/* Namespace modifiers */ + +%type <n> AliasTerm +%type <n> NameTerm +%type <n> ScopeTerm + +/* Type 1 opcodes */ + +%type <n> BreakPointTerm +%type <n> BreakTerm +%type <n> CaseDefaultTermList +%type <n> CaseTerm +%type <n> ContinueTerm +%type <n> DefaultTerm +%type <n> ElseTerm +%type <n> FatalTerm +%type <n> IfElseTerm +%type <n> IfTerm +%type <n> LoadTerm +%type <n> NoOpTerm +%type <n> NotifyTerm +%type <n> ReleaseTerm +%type <n> ResetTerm +%type <n> ReturnTerm +%type <n> SignalTerm +%type <n> SleepTerm +%type <n> StallTerm +%type <n> SwitchTerm +%type <n> UnloadTerm +%type <n> WhileTerm +//%type <n> CaseTermList + +/* Type 2 opcodes */ + +%type <n> AcquireTerm +%type <n> AddTerm +%type <n> AndTerm +%type <n> ConcatResTerm +%type <n> ConcatTerm +%type <n> CondRefOfTerm +%type <n> CopyObjectTerm +%type <n> DecTerm +%type <n> DerefOfTerm +%type <n> DivideTerm +%type <n> FindSetLeftBitTerm +%type <n> FindSetRightBitTerm +%type <n> FromBCDTerm +%type <n> IncTerm +%type <n> IndexTerm +%type <n> LAndTerm +%type <n> LEqualTerm +%type <n> LGreaterEqualTerm +%type <n> LGreaterTerm +%type <n> LLessEqualTerm +%type <n> LLessTerm +%type <n> LNotEqualTerm +%type <n> LNotTerm +%type <n> LoadTableTerm +%type <n> LOrTerm +%type <n> MatchTerm +%type <n> MidTerm +%type <n> ModTerm +%type <n> MultiplyTerm +%type <n> NAndTerm +%type <n> NOrTerm +%type <n> NotTerm +%type <n> ObjectTypeTerm +%type <n> OrTerm +%type <n> RefOfTerm +%type <n> ShiftLeftTerm +%type <n> ShiftRightTerm +%type <n> SizeOfTerm +%type <n> StoreTerm +%type <n> SubtractTerm +%type <n> TimerTerm +%type <n> ToBCDTerm +%type <n> ToBufferTerm +%type <n> ToDecimalStringTerm +%type <n> ToHexStringTerm +%type <n> ToIntegerTerm +%type <n> ToStringTerm +%type <n> WaitTerm +%type <n> XOrTerm + +/* Keywords */ + +%type <n> AccessAttribKeyword +%type <n> AccessTypeKeyword +%type <n> AddressingModeKeyword +%type <n> AddressKeyword +%type <n> AddressSpaceKeyword +%type <n> BitsPerByteKeyword +%type <n> ClockPhaseKeyword +%type <n> ClockPolarityKeyword +%type <n> DecodeKeyword +%type <n> DevicePolarityKeyword +%type <n> DMATypeKeyword +%type <n> EndianKeyword +%type <n> FlowControlKeyword +%type <n> InterruptLevel +%type <n> InterruptTypeKeyword +%type <n> IODecodeKeyword +%type <n> IoRestrictionKeyword +%type <n> LockRuleKeyword +%type <n> MatchOpKeyword +%type <n> MaxKeyword +%type <n> MemTypeKeyword +%type <n> MinKeyword +%type <n> ObjectTypeKeyword +%type <n> OptionalBusMasterKeyword +%type <n> OptionalReadWriteKeyword +%type <n> ParityTypeKeyword +%type <n> PinConfigByte +%type <n> PinConfigKeyword +%type <n> RangeTypeKeyword +%type <n> RegionSpaceKeyword +%type <n> ResourceTypeKeyword +%type <n> SerializeRuleKeyword +%type <n> ShareTypeKeyword +%type <n> SlaveModeKeyword +%type <n> StopBitsKeyword +%type <n> TranslationKeyword +%type <n> TypeKeyword +%type <n> UpdateRuleKeyword +%type <n> WireModeKeyword +%type <n> XferSizeKeyword +%type <n> XferTypeKeyword + +/* Types */ + +%type <n> SuperName +%type <n> ArgTerm +%type <n> LocalTerm +%type <n> DebugTerm + +%type <n> Integer +%type <n> ByteConst +%type <n> WordConst +%type <n> DWordConst +%type <n> QWordConst +%type <n> String + +%type <n> ConstTerm +%type <n> ConstExprTerm +%type <n> ByteConstExpr +%type <n> WordConstExpr +%type <n> DWordConstExpr +%type <n> QWordConstExpr + +%type <n> DWordList +%type <n> BufferTerm +%type <n> ByteList + +%type <n> PackageElement +%type <n> PackageList +%type <n> PackageTerm +%type <n> VarPackageLengthTerm + +/* Macros */ + +%type <n> EISAIDTerm +%type <n> ResourceMacroList +%type <n> ResourceMacroTerm +%type <n> ResourceTemplateTerm +%type <n> ToUUIDTerm +%type <n> UnicodeTerm + +/* Resource Descriptors */ + +%type <n> ConnectionTerm +%type <n> DataBufferTerm +%type <n> DMATerm +%type <n> DWordIOTerm +%type <n> DWordMemoryTerm +%type <n> DWordSpaceTerm +%type <n> EndDependentFnTerm +%type <n> ExtendedIOTerm +%type <n> ExtendedMemoryTerm +%type <n> ExtendedSpaceTerm +%type <n> FixedDmaTerm +%type <n> FixedIOTerm +%type <n> GpioIntTerm +%type <n> GpioIoTerm +%type <n> I2cSerialBusTerm +%type <n> InterruptTerm +%type <n> IOTerm +%type <n> IRQNoFlagsTerm +%type <n> IRQTerm +%type <n> Memory24Term +%type <n> Memory32FixedTerm +%type <n> Memory32Term +%type <n> NameSeg +%type <n> NameString +%type <n> QWordIOTerm +%type <n> QWordMemoryTerm +%type <n> QWordSpaceTerm +%type <n> RegisterTerm +%type <n> SpiSerialBusTerm +%type <n> StartDependentFnNoPriTerm +%type <n> StartDependentFnTerm +%type <n> UartSerialBusTerm +%type <n> VendorLongTerm +%type <n> VendorShortTerm +%type <n> WordBusNumberTerm +%type <n> WordIOTerm +%type <n> WordSpaceTerm + +/* Local types that help construct the AML, not in ACPI spec */ + +%type <n> AmlPackageLengthTerm +%type <n> IncludeEndTerm +%type <n> NameStringItem +%type <n> TermArgItem + +%type <n> OptionalAccessSize +%type <n> OptionalAddressingMode +%type <n> OptionalAddressRange +%type <n> OptionalBitsPerByte +%type <n> OptionalBuffer_Last +%type <n> OptionalByteConstExpr +%type <n> OptionalCount +%type <n> OptionalDecodeType +%type <n> OptionalDevicePolarity +%type <n> OptionalDWordConstExpr +%type <n> OptionalEndian +%type <n> OptionalFlowControl +%type <n> OptionalIoRestriction +%type <n> OptionalListString +%type <n> OptionalMaxType +%type <n> OptionalMemType +%type <n> OptionalMinType +%type <n> OptionalNameString +%type <n> OptionalNameString_First +%type <n> OptionalNameString_Last +%type <n> OptionalObjectTypeKeyword +%type <n> OptionalParameterTypePackage +%type <n> OptionalParameterTypesPackage +%type <n> OptionalParityType +%type <n> OptionalQWordConstExpr +%type <n> OptionalRangeType +%type <n> OptionalReference +%type <n> OptionalResourceType +%type <n> OptionalResourceType_First +%type <n> OptionalReturnArg +%type <n> OptionalSerializeRuleKeyword +%type <n> OptionalShareType +%type <n> OptionalShareType_First +%type <n> OptionalSlaveMode +%type <n> OptionalStopBits +%type <n> OptionalStringData +%type <n> OptionalTermArg +%type <n> OptionalTranslationType_Last +%type <n> OptionalType +%type <n> OptionalType_Last +%type <n> OptionalWireMode +%type <n> OptionalWordConst +%type <n> OptionalWordConstExpr +%type <n> OptionalXferSize + +%% +/******************************************************************************* + * + * Production rules start here + * + ******************************************************************************/ + +/* + * ASL Names + */ + + +/* + * Root rule. Allow multiple #line directives before the definition block + * to handle output from preprocessors + */ +ASLCode + : DefinitionBlockTerm + | error {YYABORT; $$ = NULL;} + ; + +/* + * Blocks, Data, and Opcodes + */ + +/* + * Note concerning support for "module-level code". + * + * ACPI 1.0 allowed Type1 and Type2 executable opcodes outside of control + * methods (the so-called module-level code.) This support was explicitly + * removed in ACPI 2.0, but this type of code continues to be created by + * BIOS vendors. In order to support the disassembly and recompilation of + * such code (and the porting of ASL code to iASL), iASL supports this + * code in violation of the current ACPI specification. + * + * The grammar change to support module-level code is to revert the + * {ObjectList} portion of the DefinitionBlockTerm in ACPI 2.0 to the + * original use of {TermList} instead (see below.) This allows the use + * of Type1 and Type2 opcodes at module level. + */ +DefinitionBlockTerm + : PARSEOP_DEFINITIONBLOCK '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DEFINITIONBLOCK);} + String ',' + String ',' + ByteConst ',' + String ',' + String ',' + DWordConst + ')' {TrSetEndLineNumber ($<n>3);} + '{' TermList '}' {$$ = TrLinkChildren ($<n>3,7,$4,$6,$8,$10,$12,$14,$18);} + ; + +/* ACPI 3.0 -- allow semicolons between terms */ + +TermList + : {$$ = NULL;} + | TermList Term {$$ = TrLinkPeerNode (TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$2);} + | TermList Term ';' {$$ = TrLinkPeerNode (TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$2);} + | TermList ';' Term {$$ = TrLinkPeerNode (TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$3);} + | TermList ';' Term ';' {$$ = TrLinkPeerNode (TrSetNodeFlags ($1, NODE_RESULT_NOT_USED),$3);} + ; + +Term + : Object {} + | Type1Opcode {} + | Type2Opcode {} + | Type2IntegerOpcode {} + | Type2StringOpcode {} + | Type2BufferOpcode {} + | Type2BufferOrStringOpcode {} + | error {$$ = AslDoError(); yyclearin;} + ; + +CompilerDirective + : IncludeTerm {} + | ExternalTerm {} + ; + +ObjectList + : {$$ = NULL;} + | ObjectList Object {$$ = TrLinkPeerNode ($1,$2);} + | error {$$ = AslDoError(); yyclearin;} + ; + +Object + : CompilerDirective {} + | NamedObject {} + | NameSpaceModifier {} + ; + +DataObject + : BufferData {} + | PackageData {} + | IntegerData {} + | StringData {} + ; + +BufferData + : Type5Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);} + | Type2BufferOrStringOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);} + | Type2BufferOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);} + | BufferTerm {} + ; + +PackageData + : PackageTerm {} + ; + +IntegerData + : Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);} + | Type3Opcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);} + | Integer {} + | ConstTerm {} + ; + +StringData + : Type2StringOpcode {$$ = TrSetNodeFlags ($1, NODE_COMPILE_TIME_CONST);} + | String {} + ; + +NamedObject + : BankFieldTerm {} + | CreateBitFieldTerm {} + | CreateByteFieldTerm {} + | CreateDWordFieldTerm {} + | CreateFieldTerm {} + | CreateQWordFieldTerm {} + | CreateWordFieldTerm {} + | DataRegionTerm {} + | DeviceTerm {} + | EventTerm {} + | FieldTerm {} + | FunctionTerm {} + | IndexFieldTerm {} + | MethodTerm {} + | MutexTerm {} + | OpRegionTerm {} + | PowerResTerm {} + | ProcessorTerm {} + | ThermalZoneTerm {} + ; + +NameSpaceModifier + : AliasTerm {} + | NameTerm {} + | ScopeTerm {} + ; + +UserTerm + : NameString '(' {TrUpdateNode (PARSEOP_METHODCALL, $1);} + ArgList ')' {$$ = TrLinkChildNode ($1,$4);} + ; + +ArgList + : {$$ = NULL;} + | TermArg + | ArgList ',' /* Allows a trailing comma at list end */ + | ArgList ',' + TermArg {$$ = TrLinkPeerNode ($1,$3);} + ; + +/* +Removed from TermArg due to reduce/reduce conflicts + | Type2IntegerOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + | Type2StringOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + | Type2BufferOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + | Type2BufferOrStringOpcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + +*/ + +TermArg + : Type2Opcode {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + | DataObject {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + | NameString {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + | ArgTerm {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + | LocalTerm {$$ = TrSetNodeFlags ($1, NODE_IS_TERM_ARG);} + ; + +Target + : {$$ = TrSetNodeFlags (TrCreateLeafNode (PARSEOP_ZERO), NODE_IS_TARGET | NODE_COMPILE_TIME_CONST);} /* Placeholder is a ZeroOp object */ + | ',' {$$ = TrSetNodeFlags (TrCreateLeafNode (PARSEOP_ZERO), NODE_IS_TARGET | NODE_COMPILE_TIME_CONST);} /* Placeholder is a ZeroOp object */ + | ',' SuperName {$$ = TrSetNodeFlags ($2, NODE_IS_TARGET);} + ; + +RequiredTarget + : ',' SuperName {$$ = TrSetNodeFlags ($2, NODE_IS_TARGET);} + ; + +SimpleTarget + : NameString {} + | LocalTerm {} + | ArgTerm {} + ; + +/* Rules for specifying the type of one method argument or return value */ + +ParameterTypePackage + : {$$ = NULL;} + | ObjectTypeKeyword {$$ = $1;} + | ParameterTypePackage ',' + ObjectTypeKeyword {$$ = TrLinkPeerNodes (2,$1,$3);} + ; + +ParameterTypePackageList + : {$$ = NULL;} + | ObjectTypeKeyword {$$ = $1;} + | '{' ParameterTypePackage '}' {$$ = $2;} + ; + +OptionalParameterTypePackage + : {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);} + | ',' ParameterTypePackageList {$$ = TrLinkChildren (TrCreateLeafNode (PARSEOP_DEFAULT_ARG),1,$2);} + ; + +/* Rules for specifying the types for method arguments */ + +ParameterTypesPackage + : ParameterTypePackageList {$$ = $1;} + | ParameterTypesPackage ',' + ParameterTypePackageList {$$ = TrLinkPeerNodes (2,$1,$3);} + ; + +ParameterTypesPackageList + : {$$ = NULL;} + | ObjectTypeKeyword {$$ = $1;} + | '{' ParameterTypesPackage '}' {$$ = $2;} + ; + +OptionalParameterTypesPackage + : {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);} + | ',' ParameterTypesPackageList {$$ = TrLinkChildren (TrCreateLeafNode (PARSEOP_DEFAULT_ARG),1,$2);} + ; + + +/* Opcode types */ + +Type1Opcode + : BreakTerm {} + | BreakPointTerm {} + | ContinueTerm {} + | FatalTerm {} + | IfElseTerm {} + | LoadTerm {} + | NoOpTerm {} + | NotifyTerm {} + | ReleaseTerm {} + | ResetTerm {} + | ReturnTerm {} + | SignalTerm {} + | SleepTerm {} + | StallTerm {} + | SwitchTerm {} + | UnloadTerm {} + | WhileTerm {} + ; + +Type2Opcode + : AcquireTerm {} + | CondRefOfTerm {} + | CopyObjectTerm {} + | DerefOfTerm {} + | ObjectTypeTerm {} + | RefOfTerm {} + | SizeOfTerm {} + | StoreTerm {} + | TimerTerm {} + | WaitTerm {} + | UserTerm {} + ; + +/* + * Type 3/4/5 opcodes + */ + +Type2IntegerOpcode /* "Type3" opcodes */ + : AddTerm {} + | AndTerm {} + | DecTerm {} + | DivideTerm {} + | FindSetLeftBitTerm {} + | FindSetRightBitTerm {} + | FromBCDTerm {} + | IncTerm {} + | IndexTerm {} + | LAndTerm {} + | LEqualTerm {} + | LGreaterTerm {} + | LGreaterEqualTerm {} + | LLessTerm {} + | LLessEqualTerm {} + | LNotTerm {} + | LNotEqualTerm {} + | LoadTableTerm {} + | LOrTerm {} + | MatchTerm {} + | ModTerm {} + | MultiplyTerm {} + | NAndTerm {} + | NOrTerm {} + | NotTerm {} + | OrTerm {} + | ShiftLeftTerm {} + | ShiftRightTerm {} + | SubtractTerm {} + | ToBCDTerm {} + | ToIntegerTerm {} + | XOrTerm {} + ; + +Type2StringOpcode /* "Type4" Opcodes */ + : ToDecimalStringTerm {} + | ToHexStringTerm {} + | ToStringTerm {} + ; + +Type2BufferOpcode /* "Type5" Opcodes */ + : ToBufferTerm {} + | ConcatResTerm {} + ; + +Type2BufferOrStringOpcode + : ConcatTerm {} + | MidTerm {} + ; + +/* + * A type 3 opcode evaluates to an Integer and cannot have a destination operand + */ + +Type3Opcode + : EISAIDTerm {} + ; + +/* Obsolete +Type4Opcode + : ConcatTerm {} + | ToDecimalStringTerm {} + | ToHexStringTerm {} + | MidTerm {} + | ToStringTerm {} + ; +*/ + + +Type5Opcode + : ResourceTemplateTerm {} + | UnicodeTerm {} + | ToUUIDTerm {} + ; + +Type6Opcode + : RefOfTerm {} + | DerefOfTerm {} + | IndexTerm {} + | UserTerm {} + ; + +IncludeTerm + : PARSEOP_INCLUDE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_INCLUDE);} + String ')' {TrLinkChildren ($<n>3,1,$4);FlOpenIncludeFile ($4);} + TermList + IncludeEndTerm {$$ = TrLinkPeerNodes (3,$<n>3,$7,$8);} + ; + +IncludeEndTerm + : PARSEOP_INCLUDE_END {$$ = TrCreateLeafNode (PARSEOP_INCLUDE_END);} + ; + +ExternalTerm + : PARSEOP_EXTERNAL '(' + NameString + OptionalObjectTypeKeyword + OptionalParameterTypePackage + OptionalParameterTypesPackage + ')' {$$ = TrCreateNode (PARSEOP_EXTERNAL,4,$3,$4,$5,$6);} + | PARSEOP_EXTERNAL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +/******* Named Objects *******************************************************/ + + +BankFieldTerm + : PARSEOP_BANKFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_BANKFIELD);} + NameString + NameStringItem + TermArgItem + ',' AccessTypeKeyword + ',' LockRuleKeyword + ',' UpdateRuleKeyword + ')' '{' + FieldUnitList '}' {$$ = TrLinkChildren ($<n>3,7,$4,$5,$6,$8,$10,$12,$15);} + | PARSEOP_BANKFIELD '(' + error ')' '{' error '}' {$$ = AslDoError(); yyclearin;} + ; + +FieldUnitList + : {$$ = NULL;} + | FieldUnit + | FieldUnitList ',' /* Allows a trailing comma at list end */ + | FieldUnitList ',' + FieldUnit {$$ = TrLinkPeerNode ($1,$3);} + ; + +FieldUnit + : FieldUnitEntry {} + | OffsetTerm {} + | AccessAsTerm {} + | ConnectionTerm {} + ; + +FieldUnitEntry + : ',' AmlPackageLengthTerm {$$ = TrCreateNode (PARSEOP_RESERVED_BYTES,1,$2);} + | NameSeg ',' + AmlPackageLengthTerm {$$ = TrLinkChildNode ($1,$3);} + ; + +OffsetTerm + : PARSEOP_OFFSET '(' + AmlPackageLengthTerm + ')' {$$ = TrCreateNode (PARSEOP_OFFSET,1,$3);} + | PARSEOP_OFFSET '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +AccessAsTerm + : PARSEOP_ACCESSAS '(' + AccessTypeKeyword + OptionalAccessAttribTerm + ')' {$$ = TrCreateNode (PARSEOP_ACCESSAS,2,$3,$4);} + | PARSEOP_ACCESSAS '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ConnectionTerm + : PARSEOP_CONNECTION '(' + NameString + ')' {$$ = TrCreateNode (PARSEOP_CONNECTION,1,$3);} + | PARSEOP_CONNECTION '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CONNECTION);} + ResourceMacroTerm + ')' {$$ = TrLinkChildren ($<n>3, 1, + TrLinkChildren (TrCreateLeafNode (PARSEOP_RESOURCETEMPLATE), 3, + TrCreateLeafNode (PARSEOP_DEFAULT_ARG), + TrCreateLeafNode (PARSEOP_DEFAULT_ARG), + $4));} + | PARSEOP_CONNECTION '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CreateBitFieldTerm + : PARSEOP_CREATEBITFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CREATEBITFIELD);} + TermArg + TermArgItem + NameStringItem + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,TrSetNodeFlags ($6, NODE_IS_NAME_DECLARATION));} + | PARSEOP_CREATEBITFIELD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CreateByteFieldTerm + : PARSEOP_CREATEBYTEFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CREATEBYTEFIELD);} + TermArg + TermArgItem + NameStringItem + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,TrSetNodeFlags ($6, NODE_IS_NAME_DECLARATION));} + | PARSEOP_CREATEBYTEFIELD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CreateDWordFieldTerm + : PARSEOP_CREATEDWORDFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CREATEDWORDFIELD);} + TermArg + TermArgItem + NameStringItem + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,TrSetNodeFlags ($6, NODE_IS_NAME_DECLARATION));} + | PARSEOP_CREATEDWORDFIELD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CreateFieldTerm + : PARSEOP_CREATEFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CREATEFIELD);} + TermArg + TermArgItem + TermArgItem + NameStringItem + ')' {$$ = TrLinkChildren ($<n>3,4,$4,$5,$6,TrSetNodeFlags ($7, NODE_IS_NAME_DECLARATION));} + | PARSEOP_CREATEFIELD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CreateQWordFieldTerm + : PARSEOP_CREATEQWORDFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CREATEQWORDFIELD);} + TermArg + TermArgItem + NameStringItem + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,TrSetNodeFlags ($6, NODE_IS_NAME_DECLARATION));} + | PARSEOP_CREATEQWORDFIELD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CreateWordFieldTerm + : PARSEOP_CREATEWORDFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CREATEWORDFIELD);} + TermArg + TermArgItem + NameStringItem + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,TrSetNodeFlags ($6, NODE_IS_NAME_DECLARATION));} + | PARSEOP_CREATEWORDFIELD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DataRegionTerm + : PARSEOP_DATATABLEREGION '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DATATABLEREGION);} + NameString + TermArgItem + TermArgItem + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,4,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$5,$6,$7);} + | PARSEOP_DATATABLEREGION '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DeviceTerm + : PARSEOP_DEVICE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DEVICE);} + NameString + ')' '{' + ObjectList '}' {$$ = TrLinkChildren ($<n>3,2,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$7);} + | PARSEOP_DEVICE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +EventTerm + : PARSEOP_EVENT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_EVENT);} + NameString + ')' {$$ = TrLinkChildren ($<n>3,1,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION));} + | PARSEOP_EVENT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +FieldTerm + : PARSEOP_FIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_FIELD);} + NameString + ',' AccessTypeKeyword + ',' LockRuleKeyword + ',' UpdateRuleKeyword + ')' '{' + FieldUnitList '}' {$$ = TrLinkChildren ($<n>3,5,$4,$6,$8,$10,$13);} + | PARSEOP_FIELD '(' + error ')' '{' error '}' {$$ = AslDoError(); yyclearin;} + ; + +FunctionTerm + : PARSEOP_FUNCTION '(' {$<n>$ = TrCreateLeafNode (PARSEOP_METHOD);} + NameString + OptionalParameterTypePackage + OptionalParameterTypesPackage + ')' '{' + TermList '}' {$$ = TrLinkChildren ($<n>3,7,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION), + TrCreateValuedLeafNode (PARSEOP_BYTECONST, 0), + TrCreateLeafNode (PARSEOP_SERIALIZERULE_NOTSERIAL), + TrCreateValuedLeafNode (PARSEOP_BYTECONST, 0),$5,$6,$9);} + | PARSEOP_FUNCTION '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +IndexFieldTerm + : PARSEOP_INDEXFIELD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_INDEXFIELD);} + NameString + NameStringItem + ',' AccessTypeKeyword + ',' LockRuleKeyword + ',' UpdateRuleKeyword + ')' '{' + FieldUnitList '}' {$$ = TrLinkChildren ($<n>3,6,$4,$5,$7,$9,$11,$14);} + | PARSEOP_INDEXFIELD '(' + error ')' '{' error '}' {$$ = AslDoError(); yyclearin;} + ; + +MethodTerm + : PARSEOP_METHOD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_METHOD);} + NameString + OptionalByteConstExpr {UtCheckIntegerRange ($5, 0, 7);} + OptionalSerializeRuleKeyword + OptionalByteConstExpr + OptionalParameterTypePackage + OptionalParameterTypesPackage + ')' '{' + TermList '}' {$$ = TrLinkChildren ($<n>3,7,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$5,$7,$8,$9,$10,$13);} + | PARSEOP_METHOD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +MutexTerm + : PARSEOP_MUTEX '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MUTEX);} + NameString + ',' ByteConstExpr + ')' {$$ = TrLinkChildren ($<n>3,2,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$6);} + | PARSEOP_MUTEX '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +OpRegionTerm + : PARSEOP_OPERATIONREGION '(' {$<n>$ = TrCreateLeafNode (PARSEOP_OPERATIONREGION);} + NameString + ',' OpRegionSpaceIdTerm + TermArgItem + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,4,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$6,$7,$8);} + | PARSEOP_OPERATIONREGION '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +OpRegionSpaceIdTerm + : RegionSpaceKeyword {} + | ByteConst {$$ = UtCheckIntegerRange ($1, 0x80, 0xFF);} + ; + +PowerResTerm + : PARSEOP_POWERRESOURCE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_POWERRESOURCE);} + NameString + ',' ByteConstExpr + ',' WordConstExpr + ')' '{' + ObjectList '}' {$$ = TrLinkChildren ($<n>3,4,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$6,$8,$11);} + | PARSEOP_POWERRESOURCE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ProcessorTerm + : PARSEOP_PROCESSOR '(' {$<n>$ = TrCreateLeafNode (PARSEOP_PROCESSOR);} + NameString + ',' ByteConstExpr + OptionalDWordConstExpr + OptionalByteConstExpr + ')' '{' + ObjectList '}' {$$ = TrLinkChildren ($<n>3,5,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$6,$7,$8,$11);} + | PARSEOP_PROCESSOR '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ThermalZoneTerm + : PARSEOP_THERMALZONE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_THERMALZONE);} + NameString + ')' '{' + ObjectList '}' {$$ = TrLinkChildren ($<n>3,2,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$7);} + | PARSEOP_THERMALZONE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +/******* Namespace modifiers *************************************************/ + + +AliasTerm + : PARSEOP_ALIAS '(' {$<n>$ = TrCreateLeafNode (PARSEOP_ALIAS);} + NameString + NameStringItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,TrSetNodeFlags ($5, NODE_IS_NAME_DECLARATION));} + | PARSEOP_ALIAS '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +NameTerm + : PARSEOP_NAME '(' {$<n>$ = TrCreateLeafNode (PARSEOP_NAME);} + NameString + ',' DataObject + ')' {$$ = TrLinkChildren ($<n>3,2,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$6);} + | PARSEOP_NAME '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ScopeTerm + : PARSEOP_SCOPE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SCOPE);} + NameString + ')' '{' + ObjectList '}' {$$ = TrLinkChildren ($<n>3,2,TrSetNodeFlags ($4, NODE_IS_NAME_DECLARATION),$7);} + | PARSEOP_SCOPE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +/******* Type 1 opcodes *******************************************************/ + + +BreakTerm + : PARSEOP_BREAK {$$ = TrCreateNode (PARSEOP_BREAK, 0);} + ; + +BreakPointTerm + : PARSEOP_BREAKPOINT {$$ = TrCreateNode (PARSEOP_BREAKPOINT, 0);} + ; + +ContinueTerm + : PARSEOP_CONTINUE {$$ = TrCreateNode (PARSEOP_CONTINUE, 0);} + ; + +FatalTerm + : PARSEOP_FATAL '(' {$<n>$ = TrCreateLeafNode (PARSEOP_FATAL);} + ByteConstExpr + ',' DWordConstExpr + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$6,$7);} + | PARSEOP_FATAL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +IfElseTerm + : IfTerm ElseTerm {$$ = TrLinkPeerNode ($1,$2);} + ; + +IfTerm + : PARSEOP_IF '(' {$<n>$ = TrCreateLeafNode (PARSEOP_IF);} + TermArg + ')' '{' + TermList '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + + | PARSEOP_IF '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ElseTerm + : {$$ = NULL;} + | PARSEOP_ELSE '{' {$<n>$ = TrCreateLeafNode (PARSEOP_ELSE);} + TermList '}' {$$ = TrLinkChildren ($<n>3,1,$4);} + + | PARSEOP_ELSE '{' + error '}' {$$ = AslDoError(); yyclearin;} + + | PARSEOP_ELSE + error {$$ = AslDoError(); yyclearin;} + + | PARSEOP_ELSEIF '(' {$<n>$ = TrCreateLeafNode (PARSEOP_ELSE);} + TermArg {$<n>$ = TrCreateLeafNode (PARSEOP_IF);} + ')' '{' + TermList '}' {TrLinkChildren ($<n>5,2,$4,$8);} + ElseTerm {TrLinkPeerNode ($<n>5,$11);} + {$$ = TrLinkChildren ($<n>3,1,$<n>5);} + + | PARSEOP_ELSEIF '(' + error ')' {$$ = AslDoError(); yyclearin;} + + | PARSEOP_ELSEIF + error {$$ = AslDoError(); yyclearin;} + ; + +LoadTerm + : PARSEOP_LOAD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LOAD);} + NameString + RequiredTarget + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_LOAD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +NoOpTerm + : PARSEOP_NOOP {$$ = TrCreateNode (PARSEOP_NOOP, 0);} + ; + +NotifyTerm + : PARSEOP_NOTIFY '(' {$<n>$ = TrCreateLeafNode (PARSEOP_NOTIFY);} + SuperName + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_NOTIFY '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ReleaseTerm + : PARSEOP_RELEASE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_RELEASE);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_RELEASE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ResetTerm + : PARSEOP_RESET '(' {$<n>$ = TrCreateLeafNode (PARSEOP_RESET);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_RESET '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ReturnTerm + : PARSEOP_RETURN '(' {$<n>$ = TrCreateLeafNode (PARSEOP_RETURN);} + OptionalReturnArg + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_RETURN {$$ = TrLinkChildren (TrCreateLeafNode (PARSEOP_RETURN),1,TrSetNodeFlags (TrCreateLeafNode (PARSEOP_ZERO), NODE_IS_NULL_RETURN));} + | PARSEOP_RETURN '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +SignalTerm + : PARSEOP_SIGNAL '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SIGNAL);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_SIGNAL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +SleepTerm + : PARSEOP_SLEEP '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SLEEP);} + TermArg + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_SLEEP '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +StallTerm + : PARSEOP_STALL '(' {$<n>$ = TrCreateLeafNode (PARSEOP_STALL);} + TermArg + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_STALL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +SwitchTerm + : PARSEOP_SWITCH '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SWITCH);} + TermArg + ')' '{' + CaseDefaultTermList '}' + {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_SWITCH '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +/* + * Case-Default list; allow only one Default term and unlimited Case terms + */ + +CaseDefaultTermList + : {$$ = NULL;} + | CaseTerm {} + | DefaultTerm {} + | CaseDefaultTermList + CaseTerm {$$ = TrLinkPeerNode ($1,$2);} + | CaseDefaultTermList + DefaultTerm {$$ = TrLinkPeerNode ($1,$2);} + +/* Original - attempts to force zero or one default term within the switch */ + +/* +CaseDefaultTermList + : {$$ = NULL;} + | CaseTermList + DefaultTerm + CaseTermList {$$ = TrLinkPeerNode ($1,TrLinkPeerNode ($2, $3));} + | CaseTermList + CaseTerm {$$ = TrLinkPeerNode ($1,$2);} + ; + +CaseTermList + : {$$ = NULL;} + | CaseTerm {} + | CaseTermList + CaseTerm {$$ = TrLinkPeerNode ($1,$2);} + ; +*/ + +CaseTerm + : PARSEOP_CASE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CASE);} + DataObject + ')' '{' + TermList '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_CASE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DefaultTerm + : PARSEOP_DEFAULT '{' {$<n>$ = TrCreateLeafNode (PARSEOP_DEFAULT);} + TermList '}' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_DEFAULT '{' + error '}' {$$ = AslDoError(); yyclearin;} + ; + +UnloadTerm + : PARSEOP_UNLOAD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_UNLOAD);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_UNLOAD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +WhileTerm + : PARSEOP_WHILE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_WHILE);} + TermArg + ')' '{' TermList '}' + {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_WHILE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +/******* Type 2 opcodes *******************************************************/ + +AcquireTerm + : PARSEOP_ACQUIRE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_ACQUIRE);} + SuperName + ',' WordConstExpr + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$6);} + | PARSEOP_ACQUIRE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +AddTerm + : PARSEOP_ADD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_ADD);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_ADD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +AndTerm + : PARSEOP_AND '(' {$<n>$ = TrCreateLeafNode (PARSEOP_AND);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_AND '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ConcatTerm + : PARSEOP_CONCATENATE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CONCATENATE);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_CONCATENATE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ConcatResTerm + : PARSEOP_CONCATENATERESTEMPLATE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CONCATENATERESTEMPLATE);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_CONCATENATERESTEMPLATE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CondRefOfTerm + : PARSEOP_CONDREFOF '(' {$<n>$ = TrCreateLeafNode (PARSEOP_CONDREFOF);} + SuperName + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_CONDREFOF '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +CopyObjectTerm + : PARSEOP_COPYOBJECT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_COPYOBJECT);} + TermArg + ',' SimpleTarget + ')' {$$ = TrLinkChildren ($<n>3,2,$4,TrSetNodeFlags ($6, NODE_IS_TARGET));} + | PARSEOP_COPYOBJECT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DecTerm + : PARSEOP_DECREMENT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DECREMENT);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_DECREMENT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DerefOfTerm + : PARSEOP_DEREFOF '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DEREFOF);} + TermArg + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_DEREFOF '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DivideTerm + : PARSEOP_DIVIDE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DIVIDE);} + TermArg + TermArgItem + Target + Target + ')' {$$ = TrLinkChildren ($<n>3,4,$4,$5,$6,$7);} + | PARSEOP_DIVIDE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +FindSetLeftBitTerm + : PARSEOP_FINDSETLEFTBIT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_FINDSETLEFTBIT);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_FINDSETLEFTBIT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +FindSetRightBitTerm + : PARSEOP_FINDSETRIGHTBIT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_FINDSETRIGHTBIT);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_FINDSETRIGHTBIT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +FromBCDTerm + : PARSEOP_FROMBCD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_FROMBCD);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_FROMBCD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +IncTerm + : PARSEOP_INCREMENT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_INCREMENT);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_INCREMENT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +IndexTerm + : PARSEOP_INDEX '(' {$<n>$ = TrCreateLeafNode (PARSEOP_INDEX);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_INDEX '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LAndTerm + : PARSEOP_LAND '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LAND);} + TermArg + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_LAND '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LEqualTerm + : PARSEOP_LEQUAL '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LEQUAL);} + TermArg + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_LEQUAL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LGreaterTerm + : PARSEOP_LGREATER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LGREATER);} + TermArg + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_LGREATER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LGreaterEqualTerm + : PARSEOP_LGREATEREQUAL '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LLESS);} + TermArg + TermArgItem + ')' {$$ = TrCreateNode (PARSEOP_LNOT, 1, TrLinkChildren ($<n>3,2,$4,$5));} + | PARSEOP_LGREATEREQUAL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LLessTerm + : PARSEOP_LLESS '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LLESS);} + TermArg + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_LLESS '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LLessEqualTerm + : PARSEOP_LLESSEQUAL '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LGREATER);} + TermArg + TermArgItem + ')' {$$ = TrCreateNode (PARSEOP_LNOT, 1, TrLinkChildren ($<n>3,2,$4,$5));} + | PARSEOP_LLESSEQUAL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LNotTerm + : PARSEOP_LNOT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LNOT);} + TermArg + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_LNOT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LNotEqualTerm + : PARSEOP_LNOTEQUAL '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LEQUAL);} + TermArg + TermArgItem + ')' {$$ = TrCreateNode (PARSEOP_LNOT, 1, TrLinkChildren ($<n>3,2,$4,$5));} + | PARSEOP_LNOTEQUAL '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LoadTableTerm + : PARSEOP_LOADTABLE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LOADTABLE);} + TermArg + TermArgItem + TermArgItem + OptionalListString + OptionalListString + OptionalReference + ')' {$$ = TrLinkChildren ($<n>3,6,$4,$5,$6,$7,$8,$9);} + | PARSEOP_LOADTABLE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +LOrTerm + : PARSEOP_LOR '(' {$<n>$ = TrCreateLeafNode (PARSEOP_LOR);} + TermArg + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_LOR '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +MatchTerm + : PARSEOP_MATCH '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MATCH);} + TermArg + ',' MatchOpKeyword + TermArgItem + ',' MatchOpKeyword + TermArgItem + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,6,$4,$6,$7,$9,$10,$11);} + | PARSEOP_MATCH '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +MidTerm + : PARSEOP_MID '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MID);} + TermArg + TermArgItem + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,4,$4,$5,$6,$7);} + | PARSEOP_MID '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ModTerm + : PARSEOP_MOD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MOD);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_MOD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +MultiplyTerm + : PARSEOP_MULTIPLY '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MULTIPLY);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_MULTIPLY '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +NAndTerm + : PARSEOP_NAND '(' {$<n>$ = TrCreateLeafNode (PARSEOP_NAND);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_NAND '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +NOrTerm + : PARSEOP_NOR '(' {$<n>$ = TrCreateLeafNode (PARSEOP_NOR);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_NOR '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +NotTerm + : PARSEOP_NOT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_NOT);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_NOT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ObjectTypeTerm + : PARSEOP_OBJECTTYPE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_OBJECTTYPE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +OrTerm + : PARSEOP_OR '(' {$<n>$ = TrCreateLeafNode (PARSEOP_OR);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_OR '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +/* + * In RefOf, the node isn't really a target, but we can't keep track of it after + * we've taken a pointer to it. (hard to tell if a local becomes initialized this way.) + */ +RefOfTerm + : PARSEOP_REFOF '(' {$<n>$ = TrCreateLeafNode (PARSEOP_REFOF);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,TrSetNodeFlags ($4, NODE_IS_TARGET));} + | PARSEOP_REFOF '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ShiftLeftTerm + : PARSEOP_SHIFTLEFT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SHIFTLEFT);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_SHIFTLEFT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ShiftRightTerm + : PARSEOP_SHIFTRIGHT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SHIFTRIGHT);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_SHIFTRIGHT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +SizeOfTerm + : PARSEOP_SIZEOF '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SIZEOF);} + SuperName + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_SIZEOF '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +StoreTerm + : PARSEOP_STORE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_STORE);} + TermArg + ',' SuperName + ')' {$$ = TrLinkChildren ($<n>3,2,$4,TrSetNodeFlags ($6, NODE_IS_TARGET));} + | PARSEOP_STORE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +SubtractTerm + : PARSEOP_SUBTRACT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SUBTRACT);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_SUBTRACT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +TimerTerm + : PARSEOP_TIMER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_TIMER);} + ')' {$$ = TrLinkChildren ($<n>3,0);} + | PARSEOP_TIMER {$$ = TrLinkChildren (TrCreateLeafNode (PARSEOP_TIMER),0);} + | PARSEOP_TIMER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ToBCDTerm + : PARSEOP_TOBCD '(' {$<n>$ = TrCreateLeafNode (PARSEOP_TOBCD);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_TOBCD '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ToBufferTerm + : PARSEOP_TOBUFFER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_TOBUFFER);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_TOBUFFER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ToDecimalStringTerm + : PARSEOP_TODECIMALSTRING '(' {$<n>$ = TrCreateLeafNode (PARSEOP_TODECIMALSTRING);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_TODECIMALSTRING '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ToHexStringTerm + : PARSEOP_TOHEXSTRING '(' {$<n>$ = TrCreateLeafNode (PARSEOP_TOHEXSTRING);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_TOHEXSTRING '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ToIntegerTerm + : PARSEOP_TOINTEGER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_TOINTEGER);} + TermArg + Target + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_TOINTEGER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ToStringTerm + : PARSEOP_TOSTRING '(' {$<n>$ = TrCreateLeafNode (PARSEOP_TOSTRING);} + TermArg + OptionalCount + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_TOSTRING '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ToUUIDTerm + : PARSEOP_TOUUID '(' + StringData ')' {$$ = TrUpdateNode (PARSEOP_TOUUID, $3);} + | PARSEOP_TOUUID '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +WaitTerm + : PARSEOP_WAIT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_WAIT);} + SuperName + TermArgItem + ')' {$$ = TrLinkChildren ($<n>3,2,$4,$5);} + | PARSEOP_WAIT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +XOrTerm + : PARSEOP_XOR '(' {$<n>$ = TrCreateLeafNode (PARSEOP_XOR);} + TermArg + TermArgItem + Target + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$5,$6);} + | PARSEOP_XOR '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +/******* Keywords *************************************************************/ + + +AccessAttribKeyword + : PARSEOP_ACCESSATTRIB_BLOCK {$$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_BLOCK);} + | PARSEOP_ACCESSATTRIB_BLOCK_CALL {$$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_BLOCK_CALL);} + | PARSEOP_ACCESSATTRIB_BYTE {$$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_BYTE);} + | PARSEOP_ACCESSATTRIB_QUICK {$$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_QUICK );} + | PARSEOP_ACCESSATTRIB_SND_RCV {$$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_SND_RCV);} + | PARSEOP_ACCESSATTRIB_WORD {$$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_WORD);} + | PARSEOP_ACCESSATTRIB_WORD_CALL {$$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_WORD_CALL);} + | PARSEOP_ACCESSATTRIB_MULTIBYTE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_MULTIBYTE);} + ByteConst + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_ACCESSATTRIB_RAW_BYTES '(' {$<n>$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_RAW_BYTES);} + ByteConst + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + | PARSEOP_ACCESSATTRIB_RAW_PROCESS '(' {$<n>$ = TrCreateLeafNode (PARSEOP_ACCESSATTRIB_RAW_PROCESS);} + ByteConst + ')' {$$ = TrLinkChildren ($<n>3,1,$4);} + ; + +AccessTypeKeyword + : PARSEOP_ACCESSTYPE_ANY {$$ = TrCreateLeafNode (PARSEOP_ACCESSTYPE_ANY);} + | PARSEOP_ACCESSTYPE_BYTE {$$ = TrCreateLeafNode (PARSEOP_ACCESSTYPE_BYTE);} + | PARSEOP_ACCESSTYPE_WORD {$$ = TrCreateLeafNode (PARSEOP_ACCESSTYPE_WORD);} + | PARSEOP_ACCESSTYPE_DWORD {$$ = TrCreateLeafNode (PARSEOP_ACCESSTYPE_DWORD);} + | PARSEOP_ACCESSTYPE_QWORD {$$ = TrCreateLeafNode (PARSEOP_ACCESSTYPE_QWORD);} + | PARSEOP_ACCESSTYPE_BUF {$$ = TrCreateLeafNode (PARSEOP_ACCESSTYPE_BUF);} + ; + +AddressingModeKeyword + : PARSEOP_ADDRESSINGMODE_7BIT {$$ = TrCreateLeafNode (PARSEOP_ADDRESSINGMODE_7BIT);} + | PARSEOP_ADDRESSINGMODE_10BIT {$$ = TrCreateLeafNode (PARSEOP_ADDRESSINGMODE_10BIT);} + ; + +AddressKeyword + : PARSEOP_ADDRESSTYPE_MEMORY {$$ = TrCreateLeafNode (PARSEOP_ADDRESSTYPE_MEMORY);} + | PARSEOP_ADDRESSTYPE_RESERVED {$$ = TrCreateLeafNode (PARSEOP_ADDRESSTYPE_RESERVED);} + | PARSEOP_ADDRESSTYPE_NVS {$$ = TrCreateLeafNode (PARSEOP_ADDRESSTYPE_NVS);} + | PARSEOP_ADDRESSTYPE_ACPI {$$ = TrCreateLeafNode (PARSEOP_ADDRESSTYPE_ACPI);} + ; + +AddressSpaceKeyword + : ByteConst {$$ = UtCheckIntegerRange ($1, 0x0A, 0xFF);} + | RegionSpaceKeyword {} + ; + +BitsPerByteKeyword + : PARSEOP_BITSPERBYTE_FIVE {$$ = TrCreateLeafNode (PARSEOP_BITSPERBYTE_FIVE);} + | PARSEOP_BITSPERBYTE_SIX {$$ = TrCreateLeafNode (PARSEOP_BITSPERBYTE_SIX);} + | PARSEOP_BITSPERBYTE_SEVEN {$$ = TrCreateLeafNode (PARSEOP_BITSPERBYTE_SEVEN);} + | PARSEOP_BITSPERBYTE_EIGHT {$$ = TrCreateLeafNode (PARSEOP_BITSPERBYTE_EIGHT);} + | PARSEOP_BITSPERBYTE_NINE {$$ = TrCreateLeafNode (PARSEOP_BITSPERBYTE_NINE);} + ; + +ClockPhaseKeyword + : PARSEOP_CLOCKPHASE_FIRST {$$ = TrCreateLeafNode (PARSEOP_CLOCKPHASE_FIRST);} + | PARSEOP_CLOCKPHASE_SECOND {$$ = TrCreateLeafNode (PARSEOP_CLOCKPHASE_SECOND);} + ; + +ClockPolarityKeyword + : PARSEOP_CLOCKPOLARITY_LOW {$$ = TrCreateLeafNode (PARSEOP_CLOCKPOLARITY_LOW);} + | PARSEOP_CLOCKPOLARITY_HIGH {$$ = TrCreateLeafNode (PARSEOP_CLOCKPOLARITY_HIGH);} + ; + +DecodeKeyword + : PARSEOP_DECODETYPE_POS {$$ = TrCreateLeafNode (PARSEOP_DECODETYPE_POS);} + | PARSEOP_DECODETYPE_SUB {$$ = TrCreateLeafNode (PARSEOP_DECODETYPE_SUB);} + ; + +DevicePolarityKeyword + : PARSEOP_DEVICEPOLARITY_LOW {$$ = TrCreateLeafNode (PARSEOP_DEVICEPOLARITY_LOW);} + | PARSEOP_DEVICEPOLARITY_HIGH {$$ = TrCreateLeafNode (PARSEOP_DEVICEPOLARITY_HIGH);} + ; + +DMATypeKeyword + : PARSEOP_DMATYPE_A {$$ = TrCreateLeafNode (PARSEOP_DMATYPE_A);} + | PARSEOP_DMATYPE_COMPATIBILITY {$$ = TrCreateLeafNode (PARSEOP_DMATYPE_COMPATIBILITY);} + | PARSEOP_DMATYPE_B {$$ = TrCreateLeafNode (PARSEOP_DMATYPE_B);} + | PARSEOP_DMATYPE_F {$$ = TrCreateLeafNode (PARSEOP_DMATYPE_F);} + ; + +EndianKeyword + : PARSEOP_ENDIAN_LITTLE {$$ = TrCreateLeafNode (PARSEOP_ENDIAN_LITTLE);} + | PARSEOP_ENDIAN_BIG {$$ = TrCreateLeafNode (PARSEOP_ENDIAN_BIG);} + ; + +FlowControlKeyword + : PARSEOP_FLOWCONTROL_HW {$$ = TrCreateLeafNode (PARSEOP_FLOWCONTROL_HW);} + | PARSEOP_FLOWCONTROL_NONE {$$ = TrCreateLeafNode (PARSEOP_FLOWCONTROL_NONE);} + | PARSEOP_FLOWCONTROL_SW {$$ = TrCreateLeafNode (PARSEOP_FLOWCONTROL_SW);} + ; + +InterruptLevel + : PARSEOP_INTLEVEL_ACTIVEBOTH {$$ = TrCreateLeafNode (PARSEOP_INTLEVEL_ACTIVEBOTH);} + | PARSEOP_INTLEVEL_ACTIVEHIGH {$$ = TrCreateLeafNode (PARSEOP_INTLEVEL_ACTIVEHIGH);} + | PARSEOP_INTLEVEL_ACTIVELOW {$$ = TrCreateLeafNode (PARSEOP_INTLEVEL_ACTIVELOW);} + ; + +InterruptTypeKeyword + : PARSEOP_INTTYPE_EDGE {$$ = TrCreateLeafNode (PARSEOP_INTTYPE_EDGE);} + | PARSEOP_INTTYPE_LEVEL {$$ = TrCreateLeafNode (PARSEOP_INTTYPE_LEVEL);} + ; + +IODecodeKeyword + : PARSEOP_IODECODETYPE_16 {$$ = TrCreateLeafNode (PARSEOP_IODECODETYPE_16);} + | PARSEOP_IODECODETYPE_10 {$$ = TrCreateLeafNode (PARSEOP_IODECODETYPE_10);} + ; + +IoRestrictionKeyword + : PARSEOP_IORESTRICT_IN {$$ = TrCreateLeafNode (PARSEOP_IORESTRICT_IN);} + | PARSEOP_IORESTRICT_OUT {$$ = TrCreateLeafNode (PARSEOP_IORESTRICT_OUT);} + | PARSEOP_IORESTRICT_NONE {$$ = TrCreateLeafNode (PARSEOP_IORESTRICT_NONE);} + | PARSEOP_IORESTRICT_PRESERVE {$$ = TrCreateLeafNode (PARSEOP_IORESTRICT_PRESERVE);} + ; + +LockRuleKeyword + : PARSEOP_LOCKRULE_LOCK {$$ = TrCreateLeafNode (PARSEOP_LOCKRULE_LOCK);} + | PARSEOP_LOCKRULE_NOLOCK {$$ = TrCreateLeafNode (PARSEOP_LOCKRULE_NOLOCK);} + ; + +MatchOpKeyword + : PARSEOP_MATCHTYPE_MTR {$$ = TrCreateLeafNode (PARSEOP_MATCHTYPE_MTR);} + | PARSEOP_MATCHTYPE_MEQ {$$ = TrCreateLeafNode (PARSEOP_MATCHTYPE_MEQ);} + | PARSEOP_MATCHTYPE_MLE {$$ = TrCreateLeafNode (PARSEOP_MATCHTYPE_MLE);} + | PARSEOP_MATCHTYPE_MLT {$$ = TrCreateLeafNode (PARSEOP_MATCHTYPE_MLT);} + | PARSEOP_MATCHTYPE_MGE {$$ = TrCreateLeafNode (PARSEOP_MATCHTYPE_MGE);} + | PARSEOP_MATCHTYPE_MGT {$$ = TrCreateLeafNode (PARSEOP_MATCHTYPE_MGT);} + ; + +MaxKeyword + : PARSEOP_MAXTYPE_FIXED {$$ = TrCreateLeafNode (PARSEOP_MAXTYPE_FIXED);} + | PARSEOP_MAXTYPE_NOTFIXED {$$ = TrCreateLeafNode (PARSEOP_MAXTYPE_NOTFIXED);} + ; + +MemTypeKeyword + : PARSEOP_MEMTYPE_CACHEABLE {$$ = TrCreateLeafNode (PARSEOP_MEMTYPE_CACHEABLE);} + | PARSEOP_MEMTYPE_WRITECOMBINING {$$ = TrCreateLeafNode (PARSEOP_MEMTYPE_WRITECOMBINING);} + | PARSEOP_MEMTYPE_PREFETCHABLE {$$ = TrCreateLeafNode (PARSEOP_MEMTYPE_PREFETCHABLE);} + | PARSEOP_MEMTYPE_NONCACHEABLE {$$ = TrCreateLeafNode (PARSEOP_MEMTYPE_NONCACHEABLE);} + ; + +MinKeyword + : PARSEOP_MINTYPE_FIXED {$$ = TrCreateLeafNode (PARSEOP_MINTYPE_FIXED);} + | PARSEOP_MINTYPE_NOTFIXED {$$ = TrCreateLeafNode (PARSEOP_MINTYPE_NOTFIXED);} + ; + +ObjectTypeKeyword + : PARSEOP_OBJECTTYPE_UNK {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_UNK);} + | PARSEOP_OBJECTTYPE_INT {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_INT);} + | PARSEOP_OBJECTTYPE_STR {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_STR);} + | PARSEOP_OBJECTTYPE_BUF {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_BUF);} + | PARSEOP_OBJECTTYPE_PKG {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_PKG);} + | PARSEOP_OBJECTTYPE_FLD {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_FLD);} + | PARSEOP_OBJECTTYPE_DEV {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_DEV);} + | PARSEOP_OBJECTTYPE_EVT {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_EVT);} + | PARSEOP_OBJECTTYPE_MTH {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_MTH);} + | PARSEOP_OBJECTTYPE_MTX {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_MTX);} + | PARSEOP_OBJECTTYPE_OPR {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_OPR);} + | PARSEOP_OBJECTTYPE_POW {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_POW);} + | PARSEOP_OBJECTTYPE_PRO {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_PRO);} + | PARSEOP_OBJECTTYPE_THZ {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_THZ);} + | PARSEOP_OBJECTTYPE_BFF {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_BFF);} + | PARSEOP_OBJECTTYPE_DDB {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_DDB);} + ; + +ParityTypeKeyword + : PARSEOP_PARITYTYPE_SPACE {$$ = TrCreateLeafNode (PARSEOP_PARITYTYPE_SPACE);} + | PARSEOP_PARITYTYPE_MARK {$$ = TrCreateLeafNode (PARSEOP_PARITYTYPE_MARK);} + | PARSEOP_PARITYTYPE_ODD {$$ = TrCreateLeafNode (PARSEOP_PARITYTYPE_ODD);} + | PARSEOP_PARITYTYPE_EVEN {$$ = TrCreateLeafNode (PARSEOP_PARITYTYPE_EVEN);} + | PARSEOP_PARITYTYPE_NONE {$$ = TrCreateLeafNode (PARSEOP_PARITYTYPE_NONE);} + ; + +PinConfigByte + : PinConfigKeyword {$$ = $1;} + | ByteConstExpr {$$ = UtCheckIntegerRange ($1, 0x80, 0xFF);} + ; + +PinConfigKeyword + : PARSEOP_PIN_NOPULL {$$ = TrCreateLeafNode (PARSEOP_PIN_NOPULL);} + | PARSEOP_PIN_PULLDOWN {$$ = TrCreateLeafNode (PARSEOP_PIN_PULLDOWN);} + | PARSEOP_PIN_PULLUP {$$ = TrCreateLeafNode (PARSEOP_PIN_PULLUP);} + | PARSEOP_PIN_PULLDEFAULT {$$ = TrCreateLeafNode (PARSEOP_PIN_PULLDEFAULT);} + ; + +RangeTypeKeyword + : PARSEOP_RANGETYPE_ISAONLY {$$ = TrCreateLeafNode (PARSEOP_RANGETYPE_ISAONLY);} + | PARSEOP_RANGETYPE_NONISAONLY {$$ = TrCreateLeafNode (PARSEOP_RANGETYPE_NONISAONLY);} + | PARSEOP_RANGETYPE_ENTIRE {$$ = TrCreateLeafNode (PARSEOP_RANGETYPE_ENTIRE);} + ; + +RegionSpaceKeyword + : PARSEOP_REGIONSPACE_IO {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_IO);} + | PARSEOP_REGIONSPACE_MEM {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_MEM);} + | PARSEOP_REGIONSPACE_PCI {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_PCI);} + | PARSEOP_REGIONSPACE_EC {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_EC);} + | PARSEOP_REGIONSPACE_SMBUS {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_SMBUS);} + | PARSEOP_REGIONSPACE_CMOS {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_CMOS);} + | PARSEOP_REGIONSPACE_PCIBAR {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_PCIBAR);} + | PARSEOP_REGIONSPACE_IPMI {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_IPMI);} + | PARSEOP_REGIONSPACE_GPIO {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_GPIO);} + | PARSEOP_REGIONSPACE_GSBUS {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_GSBUS);} + | PARSEOP_REGIONSPACE_FFIXEDHW {$$ = TrCreateLeafNode (PARSEOP_REGIONSPACE_FFIXEDHW);} + ; + +ResourceTypeKeyword + : PARSEOP_RESOURCETYPE_CONSUMER {$$ = TrCreateLeafNode (PARSEOP_RESOURCETYPE_CONSUMER);} + | PARSEOP_RESOURCETYPE_PRODUCER {$$ = TrCreateLeafNode (PARSEOP_RESOURCETYPE_PRODUCER);} + ; + +SerializeRuleKeyword + : PARSEOP_SERIALIZERULE_SERIAL {$$ = TrCreateLeafNode (PARSEOP_SERIALIZERULE_SERIAL);} + | PARSEOP_SERIALIZERULE_NOTSERIAL {$$ = TrCreateLeafNode (PARSEOP_SERIALIZERULE_NOTSERIAL);} + ; + +ShareTypeKeyword + : PARSEOP_SHARETYPE_SHARED {$$ = TrCreateLeafNode (PARSEOP_SHARETYPE_SHARED);} + | PARSEOP_SHARETYPE_EXCLUSIVE {$$ = TrCreateLeafNode (PARSEOP_SHARETYPE_EXCLUSIVE);} + | PARSEOP_SHARETYPE_SHAREDWAKE {$$ = TrCreateLeafNode (PARSEOP_SHARETYPE_SHAREDWAKE);} + | PARSEOP_SHARETYPE_EXCLUSIVEWAKE {$$ = TrCreateLeafNode (PARSEOP_SHARETYPE_EXCLUSIVEWAKE);} + ; + +SlaveModeKeyword + : PARSEOP_SLAVEMODE_CONTROLLERINIT {$$ = TrCreateLeafNode (PARSEOP_SLAVEMODE_CONTROLLERINIT);} + | PARSEOP_SLAVEMODE_DEVICEINIT {$$ = TrCreateLeafNode (PARSEOP_SLAVEMODE_DEVICEINIT);} + ; + +StopBitsKeyword + : PARSEOP_STOPBITS_TWO {$$ = TrCreateLeafNode (PARSEOP_STOPBITS_TWO);} + | PARSEOP_STOPBITS_ONEPLUSHALF {$$ = TrCreateLeafNode (PARSEOP_STOPBITS_ONEPLUSHALF);} + | PARSEOP_STOPBITS_ONE {$$ = TrCreateLeafNode (PARSEOP_STOPBITS_ONE);} + | PARSEOP_STOPBITS_ZERO {$$ = TrCreateLeafNode (PARSEOP_STOPBITS_ZERO);} + ; + +TranslationKeyword + : PARSEOP_TRANSLATIONTYPE_SPARSE {$$ = TrCreateLeafNode (PARSEOP_TRANSLATIONTYPE_SPARSE);} + | PARSEOP_TRANSLATIONTYPE_DENSE {$$ = TrCreateLeafNode (PARSEOP_TRANSLATIONTYPE_DENSE);} + ; + +TypeKeyword + : PARSEOP_TYPE_TRANSLATION {$$ = TrCreateLeafNode (PARSEOP_TYPE_TRANSLATION);} + | PARSEOP_TYPE_STATIC {$$ = TrCreateLeafNode (PARSEOP_TYPE_STATIC);} + ; + +UpdateRuleKeyword + : PARSEOP_UPDATERULE_PRESERVE {$$ = TrCreateLeafNode (PARSEOP_UPDATERULE_PRESERVE);} + | PARSEOP_UPDATERULE_ONES {$$ = TrCreateLeafNode (PARSEOP_UPDATERULE_ONES);} + | PARSEOP_UPDATERULE_ZEROS {$$ = TrCreateLeafNode (PARSEOP_UPDATERULE_ZEROS);} + ; + +WireModeKeyword + : PARSEOP_WIREMODE_FOUR {$$ = TrCreateLeafNode (PARSEOP_WIREMODE_FOUR);} + | PARSEOP_WIREMODE_THREE {$$ = TrCreateLeafNode (PARSEOP_WIREMODE_THREE);} + ; + +XferSizeKeyword + : PARSEOP_XFERSIZE_8 {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_8, 0);} + | PARSEOP_XFERSIZE_16 {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_16, 1);} + | PARSEOP_XFERSIZE_32 {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_32, 2);} + | PARSEOP_XFERSIZE_64 {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_64, 3);} + | PARSEOP_XFERSIZE_128 {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_128, 4);} + | PARSEOP_XFERSIZE_256 {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_256, 5);} + ; + +XferTypeKeyword + : PARSEOP_XFERTYPE_8 {$$ = TrCreateLeafNode (PARSEOP_XFERTYPE_8);} + | PARSEOP_XFERTYPE_8_16 {$$ = TrCreateLeafNode (PARSEOP_XFERTYPE_8_16);} + | PARSEOP_XFERTYPE_16 {$$ = TrCreateLeafNode (PARSEOP_XFERTYPE_16);} + ; + + +/******* Miscellaneous Types **************************************************/ + + +SuperName + : NameString {} + | ArgTerm {} + | LocalTerm {} + | DebugTerm {} + | Type6Opcode {} +/* | UserTerm {} */ /* Caused reduce/reduce with Type6Opcode->UserTerm */ + ; + +ArgTerm + : PARSEOP_ARG0 {$$ = TrCreateLeafNode (PARSEOP_ARG0);} + | PARSEOP_ARG1 {$$ = TrCreateLeafNode (PARSEOP_ARG1);} + | PARSEOP_ARG2 {$$ = TrCreateLeafNode (PARSEOP_ARG2);} + | PARSEOP_ARG3 {$$ = TrCreateLeafNode (PARSEOP_ARG3);} + | PARSEOP_ARG4 {$$ = TrCreateLeafNode (PARSEOP_ARG4);} + | PARSEOP_ARG5 {$$ = TrCreateLeafNode (PARSEOP_ARG5);} + | PARSEOP_ARG6 {$$ = TrCreateLeafNode (PARSEOP_ARG6);} + ; + +LocalTerm + : PARSEOP_LOCAL0 {$$ = TrCreateLeafNode (PARSEOP_LOCAL0);} + | PARSEOP_LOCAL1 {$$ = TrCreateLeafNode (PARSEOP_LOCAL1);} + | PARSEOP_LOCAL2 {$$ = TrCreateLeafNode (PARSEOP_LOCAL2);} + | PARSEOP_LOCAL3 {$$ = TrCreateLeafNode (PARSEOP_LOCAL3);} + | PARSEOP_LOCAL4 {$$ = TrCreateLeafNode (PARSEOP_LOCAL4);} + | PARSEOP_LOCAL5 {$$ = TrCreateLeafNode (PARSEOP_LOCAL5);} + | PARSEOP_LOCAL6 {$$ = TrCreateLeafNode (PARSEOP_LOCAL6);} + | PARSEOP_LOCAL7 {$$ = TrCreateLeafNode (PARSEOP_LOCAL7);} + ; + +DebugTerm + : PARSEOP_DEBUG {$$ = TrCreateLeafNode (PARSEOP_DEBUG);} + ; + + +ByteConst + : Integer {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);} + ; + +WordConst + : Integer {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);} + ; + +DWordConst + : Integer {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);} + ; + +QWordConst + : Integer {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);} + ; + +Integer + : PARSEOP_INTEGER {$$ = TrCreateValuedLeafNode (PARSEOP_INTEGER, AslCompilerlval.i);} + ; + +String + : PARSEOP_STRING_LITERAL {$$ = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL, (ACPI_NATIVE_INT) AslCompilerlval.s);} + ; + +ConstTerm + : ConstExprTerm {} + | PARSEOP_REVISION {$$ = TrCreateLeafNode (PARSEOP_REVISION);} + ; + +ConstExprTerm + : PARSEOP_ZERO {$$ = TrCreateValuedLeafNode (PARSEOP_ZERO, 0);} + | PARSEOP_ONE {$$ = TrCreateValuedLeafNode (PARSEOP_ONE, 1);} + | PARSEOP_ONES {$$ = TrCreateValuedLeafNode (PARSEOP_ONES, ACPI_UINT64_MAX);} + | PARSEOP___DATE__ {$$ = TrCreateConstantLeafNode (PARSEOP___DATE__);} + | PARSEOP___FILE__ {$$ = TrCreateConstantLeafNode (PARSEOP___FILE__);} + | PARSEOP___LINE__ {$$ = TrCreateConstantLeafNode (PARSEOP___LINE__);} + | PARSEOP___PATH__ {$$ = TrCreateConstantLeafNode (PARSEOP___PATH__);} + ; + +ByteConstExpr + : Type3Opcode {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);} + | Type2IntegerOpcode {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);} + | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_BYTECONST, $1);} + | ByteConst {} + ; + +WordConstExpr + : Type3Opcode {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);} + | Type2IntegerOpcode {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);} + | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_WORDCONST, $1);} + | WordConst {} + ; + +DWordConstExpr + : Type3Opcode {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);} + | Type2IntegerOpcode {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);} + | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_DWORDCONST, $1);} + | DWordConst {} + ; + +QWordConstExpr + : Type3Opcode {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);} + | Type2IntegerOpcode {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);} + | ConstExprTerm {$$ = TrUpdateNode (PARSEOP_QWORDCONST, $1);} + | QWordConst {} + ; + +/* OptionalCount must appear before ByteList or an incorrect reduction will result */ + +OptionalCount + : {$$ = TrCreateLeafNode (PARSEOP_ONES);} /* Placeholder is a OnesOp object */ + | ',' {$$ = TrCreateLeafNode (PARSEOP_ONES);} /* Placeholder is a OnesOp object */ + | ',' TermArg {$$ = $2;} + ; + +BufferTerm + : PARSEOP_BUFFER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_BUFFER);} + OptionalTermArg + ')' '{' + BufferTermData '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_BUFFER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +BufferTermData + : ByteList {} + | StringData {} + ; + +ByteList + : {$$ = NULL;} + | ByteConstExpr + | ByteList ',' /* Allows a trailing comma at list end */ + | ByteList ',' + ByteConstExpr {$$ = TrLinkPeerNode ($1,$3);} + ; + +DataBufferTerm + : PARSEOP_DATABUFFER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DATABUFFER);} + OptionalWordConst + ')' '{' + ByteList '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_DATABUFFER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DWordList + : {$$ = NULL;} + | DWordConstExpr + | DWordList ',' /* Allows a trailing comma at list end */ + | DWordList ',' + DWordConstExpr {$$ = TrLinkPeerNode ($1,$3);} + ; + +PackageTerm + : PARSEOP_PACKAGE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_VAR_PACKAGE);} + VarPackageLengthTerm + ')' '{' + PackageList '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_PACKAGE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +PackageList + : {$$ = NULL;} + | PackageElement + | PackageList ',' /* Allows a trailing comma at list end */ + | PackageList ',' + PackageElement {$$ = TrLinkPeerNode ($1,$3);} + ; + +PackageElement + : DataObject {} + | NameString {} + ; + +VarPackageLengthTerm + : {$$ = TrCreateLeafNode (PARSEOP_DEFAULT_ARG);} + | TermArg {$$ = $1;} + ; + + +/******* Macros ***********************************************/ + + +EISAIDTerm + : PARSEOP_EISAID '(' + StringData ')' {$$ = TrUpdateNode (PARSEOP_EISAID, $3);} + | PARSEOP_EISAID '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +UnicodeTerm + : PARSEOP_UNICODE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_UNICODE);} + StringData + ')' {$$ = TrLinkChildren ($<n>3,2,0,$4);} + | PARSEOP_UNICODE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +/******* Resources and Memory ***********************************************/ + + +/* + * Note: Create two default nodes to allow conversion to a Buffer AML opcode + * Also, insert the EndTag at the end of the template. + */ +ResourceTemplateTerm + : PARSEOP_RESOURCETEMPLATE '(' ')' + '{' + ResourceMacroList '}' {$$ = TrCreateNode (PARSEOP_RESOURCETEMPLATE,4, + TrCreateLeafNode (PARSEOP_DEFAULT_ARG), + TrCreateLeafNode (PARSEOP_DEFAULT_ARG), + $5, + TrCreateLeafNode (PARSEOP_ENDTAG));} + ; + +ResourceMacroList + : {$$ = NULL;} + | ResourceMacroList + ResourceMacroTerm {$$ = TrLinkPeerNode ($1,$2);} + ; + +ResourceMacroTerm + : DMATerm {} + | DWordIOTerm {} + | DWordMemoryTerm {} + | DWordSpaceTerm {} + | EndDependentFnTerm {} + | ExtendedIOTerm {} + | ExtendedMemoryTerm {} + | ExtendedSpaceTerm {} + | FixedDmaTerm {} + | FixedIOTerm {} + | GpioIntTerm {} + | GpioIoTerm {} + | I2cSerialBusTerm {} + | InterruptTerm {} + | IOTerm {} + | IRQNoFlagsTerm {} + | IRQTerm {} + | Memory24Term {} + | Memory32FixedTerm {} + | Memory32Term {} + | QWordIOTerm {} + | QWordMemoryTerm {} + | QWordSpaceTerm {} + | RegisterTerm {} + | SpiSerialBusTerm {} + | StartDependentFnNoPriTerm {} + | StartDependentFnTerm {} + | UartSerialBusTerm {} + | VendorLongTerm {} + | VendorShortTerm {} + | WordBusNumberTerm {} + | WordIOTerm {} + | WordSpaceTerm {} + ; + +DMATerm + : PARSEOP_DMA '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DMA);} + DMATypeKeyword + OptionalBusMasterKeyword + ',' XferTypeKeyword + OptionalNameString_Last + ')' '{' + ByteList '}' {$$ = TrLinkChildren ($<n>3,5,$4,$5,$7,$8,$11);} + | PARSEOP_DMA '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DWordIOTerm + : PARSEOP_DWORDIO '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DWORDIO);} + OptionalResourceType_First + OptionalMinType + OptionalMaxType + OptionalDecodeType + OptionalRangeType + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString + OptionalType + OptionalTranslationType_Last + ')' {$$ = TrLinkChildren ($<n>3,15,$4,$5,$6,$7,$8,$10,$12,$14,$16,$18,$19,$20,$21,$22,$23);} + | PARSEOP_DWORDIO '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DWordMemoryTerm + : PARSEOP_DWORDMEMORY '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DWORDMEMORY);} + OptionalResourceType_First + OptionalDecodeType + OptionalMinType + OptionalMaxType + OptionalMemType + ',' OptionalReadWriteKeyword + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString + OptionalAddressRange + OptionalType_Last + ')' {$$ = TrLinkChildren ($<n>3,16,$4,$5,$6,$7,$8,$10,$12,$14,$16,$18,$20,$21,$22,$23,$24,$25);} + | PARSEOP_DWORDMEMORY '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +DWordSpaceTerm + : PARSEOP_DWORDSPACE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_DWORDSPACE);} + ByteConstExpr {UtCheckIntegerRange ($4, 0xC0, 0xFF);} + OptionalResourceType + OptionalDecodeType + OptionalMinType + OptionalMaxType + ',' ByteConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,14,$4,$6,$7,$8,$9,$11,$13,$15,$17,$19,$21,$22,$23,$24);} + | PARSEOP_DWORDSPACE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +EndDependentFnTerm + : PARSEOP_ENDDEPENDENTFN '(' + ')' {$$ = TrCreateLeafNode (PARSEOP_ENDDEPENDENTFN);} + | PARSEOP_ENDDEPENDENTFN '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ExtendedIOTerm + : PARSEOP_EXTENDEDIO '(' {$<n>$ = TrCreateLeafNode (PARSEOP_EXTENDEDIO);} + OptionalResourceType_First + OptionalMinType + OptionalMaxType + OptionalDecodeType + OptionalRangeType + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + OptionalQWordConstExpr + OptionalNameString + OptionalType + OptionalTranslationType_Last + ')' {$$ = TrLinkChildren ($<n>3,14,$4,$5,$6,$7,$8,$10,$12,$14,$16,$18,$19,$20,$21,$22);} + | PARSEOP_EXTENDEDIO '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ExtendedMemoryTerm + : PARSEOP_EXTENDEDMEMORY '(' {$<n>$ = TrCreateLeafNode (PARSEOP_EXTENDEDMEMORY);} + OptionalResourceType_First + OptionalDecodeType + OptionalMinType + OptionalMaxType + OptionalMemType + ',' OptionalReadWriteKeyword + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + OptionalQWordConstExpr + OptionalNameString + OptionalAddressRange + OptionalType_Last + ')' {$$ = TrLinkChildren ($<n>3,15,$4,$5,$6,$7,$8,$10,$12,$14,$16,$18,$20,$21,$22,$23,$24);} + | PARSEOP_EXTENDEDMEMORY '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +ExtendedSpaceTerm + : PARSEOP_EXTENDEDSPACE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_EXTENDEDSPACE);} + ByteConstExpr {UtCheckIntegerRange ($4, 0xC0, 0xFF);} + OptionalResourceType + OptionalDecodeType + OptionalMinType + OptionalMaxType + ',' ByteConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + OptionalQWordConstExpr + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,13,$4,$6,$7,$8,$9,$11,$13,$15,$17,$19,$21,$22,$23);} + | PARSEOP_EXTENDEDSPACE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +FixedDmaTerm + : PARSEOP_FIXEDDMA '(' {$<n>$ = TrCreateLeafNode (PARSEOP_FIXEDDMA);} + WordConstExpr // 04: DMA RequestLines + ',' WordConstExpr // 06: DMA Channels + OptionalXferSize // 07: DMA TransferSize + OptionalNameString // 08: DescriptorName + ')' {$$ = TrLinkChildren ($<n>3,4,$4,$6,$7,$8);} + | PARSEOP_FIXEDDMA '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +FixedIOTerm + : PARSEOP_FIXEDIO '(' {$<n>$ = TrCreateLeafNode (PARSEOP_FIXEDIO);} + WordConstExpr + ',' ByteConstExpr + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,3,$4,$6,$7);} + | PARSEOP_FIXEDIO '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +GpioIntTerm + : PARSEOP_GPIO_INT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_GPIO_INT);} + InterruptTypeKeyword // 04: InterruptType + ',' InterruptLevel // 06: InterruptLevel + OptionalShareType // 07: SharedType + ',' PinConfigByte // 09: PinConfig + OptionalWordConstExpr // 10: DebounceTimeout + ',' StringData // 12: ResourceSource + OptionalByteConstExpr // 13: ResourceSourceIndex + OptionalResourceType // 14: ResourceType + OptionalNameString // 15: DescriptorName + OptionalBuffer_Last // 16: VendorData + ')' '{' + DWordConstExpr '}' {$$ = TrLinkChildren ($<n>3,11,$4,$6,$7,$9,$10,$12,$13,$14,$15,$16,$19);} + | PARSEOP_GPIO_INT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +GpioIoTerm + : PARSEOP_GPIO_IO '(' {$<n>$ = TrCreateLeafNode (PARSEOP_GPIO_IO);} + OptionalShareType_First // 04: SharedType + ',' PinConfigByte // 06: PinConfig + OptionalWordConstExpr // 07: DebounceTimeout + OptionalWordConstExpr // 08: DriveStrength + OptionalIoRestriction // 09: IoRestriction + ',' StringData // 11: ResourceSource + OptionalByteConstExpr // 12: ResourceSourceIndex + OptionalResourceType // 13: ResourceType + OptionalNameString // 14: DescriptorName + OptionalBuffer_Last // 15: VendorData + ')' '{' + DWordList '}' {$$ = TrLinkChildren ($<n>3,11,$4,$6,$7,$8,$9,$11,$12,$13,$14,$15,$18);} + | PARSEOP_GPIO_IO '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +I2cSerialBusTerm + : PARSEOP_I2C_SERIALBUS '(' {$<n>$ = TrCreateLeafNode (PARSEOP_I2C_SERIALBUS);} + WordConstExpr // 04: SlaveAddress + OptionalSlaveMode // 05: SlaveMode + ',' DWordConstExpr // 07: ConnectionSpeed + OptionalAddressingMode // 08: AddressingMode + ',' StringData // 10: ResourceSource + OptionalByteConstExpr // 11: ResourceSourceIndex + OptionalResourceType // 12: ResourceType + OptionalNameString // 13: DescriptorName + OptionalBuffer_Last // 14: VendorData + ')' {$$ = TrLinkChildren ($<n>3,9,$4,$5,$7,$8,$10,$11,$12,$13,$14);} + | PARSEOP_I2C_SERIALBUS '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +InterruptTerm + : PARSEOP_INTERRUPT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_INTERRUPT);} + OptionalResourceType_First + ',' InterruptTypeKeyword + ',' InterruptLevel + OptionalShareType + OptionalByteConstExpr + OptionalStringData + OptionalNameString_Last + ')' '{' + DWordList '}' {$$ = TrLinkChildren ($<n>3,8,$4,$6,$8,$9,$10,$11,$12,$15);} + | PARSEOP_INTERRUPT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +IOTerm + : PARSEOP_IO '(' {$<n>$ = TrCreateLeafNode (PARSEOP_IO);} + IODecodeKeyword + ',' WordConstExpr + ',' WordConstExpr + ',' ByteConstExpr + ',' ByteConstExpr + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,6,$4,$6,$8,$10,$12,$13);} + | PARSEOP_IO '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +IRQNoFlagsTerm + : PARSEOP_IRQNOFLAGS '(' {$<n>$ = TrCreateLeafNode (PARSEOP_IRQNOFLAGS);} + OptionalNameString_First + ')' '{' + ByteList '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_IRQNOFLAGS '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +IRQTerm + : PARSEOP_IRQ '(' {$<n>$ = TrCreateLeafNode (PARSEOP_IRQ);} + InterruptTypeKeyword + ',' InterruptLevel + OptionalShareType + OptionalNameString_Last + ')' '{' + ByteList '}' {$$ = TrLinkChildren ($<n>3,5,$4,$6,$7,$8,$11);} + | PARSEOP_IRQ '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +Memory24Term + : PARSEOP_MEMORY24 '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MEMORY24);} + OptionalReadWriteKeyword + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,6,$4,$6,$8,$10,$12,$13);} + | PARSEOP_MEMORY24 '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +Memory32FixedTerm + : PARSEOP_MEMORY32FIXED '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MEMORY32FIXED);} + OptionalReadWriteKeyword + ',' DWordConstExpr + ',' DWordConstExpr + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,4,$4,$6,$8,$9);} + | PARSEOP_MEMORY32FIXED '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +Memory32Term + : PARSEOP_MEMORY32 '(' {$<n>$ = TrCreateLeafNode (PARSEOP_MEMORY32);} + OptionalReadWriteKeyword + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + ',' DWordConstExpr + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,6,$4,$6,$8,$10,$12,$13);} + | PARSEOP_MEMORY32 '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +QWordIOTerm + : PARSEOP_QWORDIO '(' {$<n>$ = TrCreateLeafNode (PARSEOP_QWORDIO);} + OptionalResourceType_First + OptionalMinType + OptionalMaxType + OptionalDecodeType + OptionalRangeType + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString + OptionalType + OptionalTranslationType_Last + ')' {$$ = TrLinkChildren ($<n>3,15,$4,$5,$6,$7,$8,$10,$12,$14,$16,$18,$19,$20,$21,$22,$23);} + | PARSEOP_QWORDIO '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +QWordMemoryTerm + : PARSEOP_QWORDMEMORY '(' {$<n>$ = TrCreateLeafNode (PARSEOP_QWORDMEMORY);} + OptionalResourceType_First + OptionalDecodeType + OptionalMinType + OptionalMaxType + OptionalMemType + ',' OptionalReadWriteKeyword + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString + OptionalAddressRange + OptionalType_Last + ')' {$$ = TrLinkChildren ($<n>3,16,$4,$5,$6,$7,$8,$10,$12,$14,$16,$18,$20,$21,$22,$23,$24,$25);} + | PARSEOP_QWORDMEMORY '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +QWordSpaceTerm + : PARSEOP_QWORDSPACE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_QWORDSPACE);} + ByteConstExpr {UtCheckIntegerRange ($4, 0xC0, 0xFF);} + OptionalResourceType + OptionalDecodeType + OptionalMinType + OptionalMaxType + ',' ByteConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + ',' QWordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,14,$4,$6,$7,$8,$9,$11,$13,$15,$17,$19,$21,$22,$23,$24);} + | PARSEOP_QWORDSPACE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +RegisterTerm + : PARSEOP_REGISTER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_REGISTER);} + AddressSpaceKeyword + ',' ByteConstExpr + ',' ByteConstExpr + ',' QWordConstExpr + OptionalAccessSize + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,6,$4,$6,$8,$10,$11,$12);} + | PARSEOP_REGISTER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +SpiSerialBusTerm + : PARSEOP_SPI_SERIALBUS '(' {$<n>$ = TrCreateLeafNode (PARSEOP_SPI_SERIALBUS);} + WordConstExpr // 04: DeviceSelection + OptionalDevicePolarity // 05: DevicePolarity + OptionalWireMode // 06: WireMode + ',' ByteConstExpr // 08: DataBitLength + OptionalSlaveMode // 09: SlaveMode + ',' DWordConstExpr // 11: ConnectionSpeed + ',' ClockPolarityKeyword // 13: ClockPolarity + ',' ClockPhaseKeyword // 15: ClockPhase + ',' StringData // 17: ResourceSource + OptionalByteConstExpr // 18: ResourceSourceIndex + OptionalResourceType // 19: ResourceType + OptionalNameString // 20: DescriptorName + OptionalBuffer_Last // 21: VendorData + ')' {$$ = TrLinkChildren ($<n>3,13,$4,$5,$6,$8,$9,$11,$13,$15,$17,$18,$19,$20,$21);} + | PARSEOP_SPI_SERIALBUS '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +StartDependentFnNoPriTerm + : PARSEOP_STARTDEPENDENTFN_NOPRI '(' {$<n>$ = TrCreateLeafNode (PARSEOP_STARTDEPENDENTFN_NOPRI);} + ')' '{' + ResourceMacroList '}' {$$ = TrLinkChildren ($<n>3,1,$6);} + | PARSEOP_STARTDEPENDENTFN_NOPRI '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +StartDependentFnTerm + : PARSEOP_STARTDEPENDENTFN '(' {$<n>$ = TrCreateLeafNode (PARSEOP_STARTDEPENDENTFN);} + ByteConstExpr + ',' ByteConstExpr + ')' '{' + ResourceMacroList '}' {$$ = TrLinkChildren ($<n>3,3,$4,$6,$9);} + | PARSEOP_STARTDEPENDENTFN '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +UartSerialBusTerm + : PARSEOP_UART_SERIALBUS '(' {$<n>$ = TrCreateLeafNode (PARSEOP_UART_SERIALBUS);} + DWordConstExpr // 04: ConnectionSpeed + OptionalBitsPerByte // 05: BitsPerByte + OptionalStopBits // 06: StopBits + ',' ByteConstExpr // 08: LinesInUse + OptionalEndian // 09: Endianess + OptionalParityType // 10: Parity + OptionalFlowControl // 11: FlowControl + ',' WordConstExpr // 13: Rx BufferSize + ',' WordConstExpr // 15: Tx BufferSize + ',' StringData // 17: ResourceSource + OptionalByteConstExpr // 18: ResourceSourceIndex + OptionalResourceType // 19: ResourceType + OptionalNameString // 20: DescriptorName + OptionalBuffer_Last // 21: VendorData + ')' {$$ = TrLinkChildren ($<n>3,14,$4,$5,$6,$8,$9,$10,$11,$13,$15,$17,$18,$19,$20,$21);} + | PARSEOP_UART_SERIALBUS '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +VendorLongTerm + : PARSEOP_VENDORLONG '(' {$<n>$ = TrCreateLeafNode (PARSEOP_VENDORLONG);} + OptionalNameString_First + ')' '{' + ByteList '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_VENDORLONG '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +VendorShortTerm + : PARSEOP_VENDORSHORT '(' {$<n>$ = TrCreateLeafNode (PARSEOP_VENDORSHORT);} + OptionalNameString_First + ')' '{' + ByteList '}' {$$ = TrLinkChildren ($<n>3,2,$4,$7);} + | PARSEOP_VENDORSHORT '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +WordBusNumberTerm + : PARSEOP_WORDBUSNUMBER '(' {$<n>$ = TrCreateLeafNode (PARSEOP_WORDBUSNUMBER);} + OptionalResourceType_First + OptionalMinType + OptionalMaxType + OptionalDecodeType + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,12,$4,$5,$6,$7,$9,$11,$13,$15,$17,$18,$19,$20);} + | PARSEOP_WORDBUSNUMBER '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +WordIOTerm + : PARSEOP_WORDIO '(' {$<n>$ = TrCreateLeafNode (PARSEOP_WORDIO);} + OptionalResourceType_First + OptionalMinType + OptionalMaxType + OptionalDecodeType + OptionalRangeType + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString + OptionalType + OptionalTranslationType_Last + ')' {$$ = TrLinkChildren ($<n>3,15,$4,$5,$6,$7,$8,$10,$12,$14,$16,$18,$19,$20,$21,$22,$23);} + | PARSEOP_WORDIO '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + +WordSpaceTerm + : PARSEOP_WORDSPACE '(' {$<n>$ = TrCreateLeafNode (PARSEOP_WORDSPACE);} + ByteConstExpr {UtCheckIntegerRange ($4, 0xC0, 0xFF);} + OptionalResourceType + OptionalDecodeType + OptionalMinType + OptionalMaxType + ',' ByteConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + ',' WordConstExpr + OptionalByteConstExpr + OptionalStringData + OptionalNameString_Last + ')' {$$ = TrLinkChildren ($<n>3,14,$4,$6,$7,$8,$9,$11,$13,$15,$17,$19,$21,$22,$23,$24);} + | PARSEOP_WORDSPACE '(' + error ')' {$$ = AslDoError(); yyclearin;} + ; + + +/******* Object References ***********************************************/ + +/* Allow IO, DMA, IRQ Resource macro names to also be used as identifiers */ + +NameString + : NameSeg {} + | PARSEOP_NAMESTRING {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) AslCompilerlval.s);} + | PARSEOP_IO {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IO");} + | PARSEOP_DMA {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "DMA");} + | PARSEOP_IRQ {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, (ACPI_NATIVE_INT) "IRQ");} + ; + +NameSeg + : PARSEOP_NAMESEG {$$ = TrCreateValuedLeafNode (PARSEOP_NAMESEG, (ACPI_NATIVE_INT) AslCompilerlval.s);} + ; + + +/******* Helper rules ****************************************************/ + + +AmlPackageLengthTerm + : Integer {$$ = TrUpdateNode (PARSEOP_PACKAGE_LENGTH,(ACPI_PARSE_OBJECT *) $1);} + ; + +NameStringItem + : ',' NameString {$$ = $2;} + | ',' error {$$ = AslDoError (); yyclearin;} + ; + +TermArgItem + : ',' TermArg {$$ = $2;} + | ',' error {$$ = AslDoError (); yyclearin;} + ; + +OptionalBusMasterKeyword + : ',' {$$ = TrCreateLeafNode (PARSEOP_BUSMASTERTYPE_MASTER);} + | ',' PARSEOP_BUSMASTERTYPE_MASTER {$$ = TrCreateLeafNode (PARSEOP_BUSMASTERTYPE_MASTER);} + | ',' PARSEOP_BUSMASTERTYPE_NOTMASTER {$$ = TrCreateLeafNode (PARSEOP_BUSMASTERTYPE_NOTMASTER);} + ; + +OptionalAccessAttribTerm + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' ByteConstExpr {$$ = $2;} + | ',' AccessAttribKeyword {$$ = $2;} + ; + +OptionalAccessSize + : {$$ = TrCreateValuedLeafNode (PARSEOP_BYTECONST, 0);} + | ',' {$$ = TrCreateValuedLeafNode (PARSEOP_BYTECONST, 0);} + | ',' ByteConstExpr {$$ = $2;} + ; + +OptionalAddressingMode + : ',' {$$ = NULL;} + | ',' AddressingModeKeyword {$$ = $2;} + ; + +OptionalAddressRange + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' AddressKeyword {$$ = $2;} + ; + +OptionalBitsPerByte + : ',' {$$ = NULL;} + | ',' BitsPerByteKeyword {$$ = $2;} + ; + +OptionalBuffer_Last + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' DataBufferTerm {$$ = $2;} + ; + +OptionalByteConstExpr + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' ByteConstExpr {$$ = $2;} + ; + +OptionalDecodeType + : ',' {$$ = NULL;} + | ',' DecodeKeyword {$$ = $2;} + ; + +OptionalDevicePolarity + : ',' {$$ = NULL;} + | ',' DevicePolarityKeyword {$$ = $2;} + ; + +OptionalDWordConstExpr + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' DWordConstExpr {$$ = $2;} + ; + +OptionalEndian + : ',' {$$ = NULL;} + | ',' EndianKeyword {$$ = $2;} + ; + +OptionalFlowControl + : ',' {$$ = NULL;} + | ',' FlowControlKeyword {$$ = $2;} + ; + +OptionalIoRestriction + : ',' {$$ = NULL;} + | ',' IoRestrictionKeyword {$$ = $2;} + ; + +OptionalListString + : {$$ = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL, ACPI_TO_INTEGER (""));} /* Placeholder is a NULL string */ + | ',' {$$ = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL, ACPI_TO_INTEGER (""));} /* Placeholder is a NULL string */ + | ',' TermArg {$$ = $2;} + ; + +OptionalMaxType + : ',' {$$ = NULL;} + | ',' MaxKeyword {$$ = $2;} + ; + +OptionalMemType + : ',' {$$ = NULL;} + | ',' MemTypeKeyword {$$ = $2;} + ; + +OptionalMinType + : ',' {$$ = NULL;} + | ',' MinKeyword {$$ = $2;} + ; + +OptionalNameString + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' NameString {$$ = $2;} + ; + +OptionalNameString_Last + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' NameString {$$ = $2;} + ; + +OptionalNameString_First + : {$$ = TrCreateLeafNode (PARSEOP_ZERO);} + | NameString {$$ = $1;} + ; + +OptionalObjectTypeKeyword + : {$$ = TrCreateLeafNode (PARSEOP_OBJECTTYPE_UNK);} + | ',' ObjectTypeKeyword {$$ = $2;} + ; + +OptionalParityType + : ',' {$$ = NULL;} + | ',' ParityTypeKeyword {$$ = $2;} + ; + +OptionalQWordConstExpr + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' QWordConstExpr {$$ = $2;} + ; + +OptionalRangeType + : ',' {$$ = NULL;} + | ',' RangeTypeKeyword {$$ = $2;} + ; + +OptionalReadWriteKeyword + : {$$ = TrCreateLeafNode (PARSEOP_READWRITETYPE_BOTH);} + | PARSEOP_READWRITETYPE_BOTH {$$ = TrCreateLeafNode (PARSEOP_READWRITETYPE_BOTH);} + | PARSEOP_READWRITETYPE_READONLY {$$ = TrCreateLeafNode (PARSEOP_READWRITETYPE_READONLY);} + ; + +OptionalReference + : {$$ = TrCreateLeafNode (PARSEOP_ZERO);} /* Placeholder is a ZeroOp object */ + | ',' {$$ = TrCreateLeafNode (PARSEOP_ZERO);} /* Placeholder is a ZeroOp object */ + | ',' TermArg {$$ = $2;} + ; + +OptionalResourceType_First + : {$$ = TrCreateLeafNode (PARSEOP_RESOURCETYPE_CONSUMER);} + | ResourceTypeKeyword {$$ = $1;} + ; + +OptionalResourceType + : {$$ = TrCreateLeafNode (PARSEOP_RESOURCETYPE_CONSUMER);} + | ',' {$$ = TrCreateLeafNode (PARSEOP_RESOURCETYPE_CONSUMER);} + | ',' ResourceTypeKeyword {$$ = $2;} + ; + +OptionalReturnArg + : {$$ = TrSetNodeFlags (TrCreateLeafNode (PARSEOP_ZERO), NODE_IS_NULL_RETURN);} /* Placeholder is a ZeroOp object */ + | TermArg {$$ = $1;} + ; + +OptionalSerializeRuleKeyword + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' SerializeRuleKeyword {$$ = $2;} + ; + +OptionalSlaveMode + : ',' {$$ = NULL;} + | ',' SlaveModeKeyword {$$ = $2;} + ; + +OptionalShareType + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' ShareTypeKeyword {$$ = $2;} + ; + +OptionalShareType_First + : {$$ = NULL;} + | ShareTypeKeyword {$$ = $1;} + ; + +OptionalStopBits + : ',' {$$ = NULL;} + | ',' StopBitsKeyword {$$ = $2;} + ; + +OptionalStringData + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' StringData {$$ = $2;} + ; + +OptionalTermArg + : {$$ = NULL;} + | TermArg {$$ = $1;} + ; + +OptionalType + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' TypeKeyword {$$ = $2;} + ; + +OptionalType_Last + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' TypeKeyword {$$ = $2;} + ; + +OptionalTranslationType_Last + : {$$ = NULL;} + | ',' {$$ = NULL;} + | ',' TranslationKeyword {$$ = $2;} + ; + +OptionalWireMode + : ',' {$$ = NULL;} + | ',' WireModeKeyword {$$ = $2;} + ; + +OptionalWordConst + : {$$ = NULL;} + | WordConst {$$ = $1;} + ; + +OptionalWordConstExpr + : ',' {$$ = NULL;} + | ',' WordConstExpr {$$ = $2;} + ; + +OptionalXferSize + : {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_32, 2);} + | ',' {$$ = TrCreateValuedLeafNode (PARSEOP_XFERSIZE_32, 2);} + | ',' XferSizeKeyword {$$ = $2;} + ; + +%% +/****************************************************************************** + * + * Local support functions + * + *****************************************************************************/ + +int +AslCompilerwrap(void) +{ + return 1; +} + +/*! [End] no source code translation !*/ + +void * +AslLocalAllocate (unsigned int Size) +{ + void *Mem; + + + DbgPrint (ASL_PARSE_OUTPUT, "\nAslLocalAllocate: Expanding Stack to %u\n\n", Size); + + Mem = ACPI_ALLOCATE_ZEROED (Size); + if (!Mem) + { + AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_InputByteCount, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + exit (1); + } + + return (Mem); +} + +ACPI_PARSE_OBJECT * +AslDoError (void) +{ + + + return (TrCreateLeafNode (PARSEOP_ERRORNODE)); + +} + + +/******************************************************************************* + * + * FUNCTION: UtGetOpName + * + * PARAMETERS: ParseOpcode - Parser keyword ID + * + * RETURN: Pointer to the opcode name + * + * DESCRIPTION: Get the ascii name of the parse opcode + * + ******************************************************************************/ + +char * +UtGetOpName ( + UINT32 ParseOpcode) +{ +#ifdef ASL_YYTNAME_START + /* + * First entries (ASL_YYTNAME_START) in yytname are special reserved names. + * Ignore first 8 characters of the name + */ + return ((char *) yytname + [(ParseOpcode - ASL_FIRST_PARSE_OPCODE) + ASL_YYTNAME_START] + 8); +#else + return ("[Unknown parser generator]"); +#endif +} diff --git a/sys/contrib/dev/acpica/compiler/asldefine.h b/sys/contrib/dev/acpica/compiler/asldefine.h new file mode 100644 index 0000000..a83a021 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asldefine.h @@ -0,0 +1,177 @@ + +/****************************************************************************** + * + * Module Name: asldefine.h - Common defines for the iASL compiler + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#ifndef __ASLDEFINE_H +#define __ASLDEFINE_H + + +/* + * Compiler versions and names + */ +#define ASL_REVISION ACPI_CA_VERSION +#define ASL_COMPILER_NAME "ASL Optimizing Compiler" +#define AML_DISASSEMBLER_NAME "AML Disassembler" +#define ASL_INVOCATION_NAME "iasl" +#define ASL_CREATOR_ID "INTL" + +#define ASL_COMPLIANCE "Supports ACPI Specification Revision 5.0" + + +/* Configuration constants */ + +#define ASL_MAX_ERROR_COUNT 200 +#define ASL_NODE_CACHE_SIZE 1024 +#define ASL_STRING_CACHE_SIZE 32768 + +#define ASL_FIRST_PARSE_OPCODE PARSEOP_ACCESSAS +#define ASL_PARSE_OPCODE_BASE PARSEOP_ACCESSAS /* First Lex type */ + + +/* + * Per-parser-generator configuration. These values are used to cheat and + * directly access the bison/yacc token name table (yyname or yytname). + * Note: These values are the index in yyname for the first lex token + * (PARSEOP_ACCCESSAS). + */ +#if defined (YYBISON) +#define ASL_YYTNAME_START 3 /* Bison */ +#elif defined (YYBYACC) +#define ASL_YYTNAME_START 257 /* Berkeley yacc */ +#endif + + +/* + * Macros + */ +#define ASL_RESDESC_OFFSET(m) ACPI_OFFSET (AML_RESOURCE, m) +#define ASL_PTR_DIFF(a,b) ((UINT8 *)(b) - (UINT8 *)(a)) +#define ASL_PTR_ADD(a,b) ((UINT8 *)(a) = ((UINT8 *)(a) + (b))) +#define ASL_GET_CHILD_NODE(a) (a)->Asl.Child +#define ASL_GET_PEER_NODE(a) (a)->Asl.Next +#define OP_TABLE_ENTRY(a,b,c,d) {b,d,a,c} + + +/* Internal AML opcodes */ + +#define AML_RAW_DATA_BYTE (UINT16) 0xAA01 /* write one raw byte */ +#define AML_RAW_DATA_WORD (UINT16) 0xAA02 /* write 2 raw bytes */ +#define AML_RAW_DATA_DWORD (UINT16) 0xAA04 /* write 4 raw bytes */ +#define AML_RAW_DATA_QWORD (UINT16) 0xAA08 /* write 8 raw bytes */ +#define AML_RAW_DATA_BUFFER (UINT16) 0xAA0B /* raw buffer with length */ +#define AML_RAW_DATA_CHAIN (UINT16) 0xAA0C /* chain of raw buffers */ +#define AML_PACKAGE_LENGTH (UINT16) 0xAA10 +#define AML_UNASSIGNED_OPCODE (UINT16) 0xEEEE +#define AML_DEFAULT_ARG_OP (UINT16) 0xDDDD + + +/* filename suffixes for output files */ + +#define FILE_SUFFIX_PREPROCESSOR "i" +#define FILE_SUFFIX_AML_CODE "aml" +#define FILE_SUFFIX_LISTING "lst" +#define FILE_SUFFIX_HEX_DUMP "hex" +#define FILE_SUFFIX_DEBUG "txt" +#define FILE_SUFFIX_SOURCE "src" +#define FILE_SUFFIX_NAMESPACE "nsp" +#define FILE_SUFFIX_ASM_SOURCE "asm" +#define FILE_SUFFIX_C_SOURCE "c" +#define FILE_SUFFIX_DISASSEMBLY "dsl" +#define FILE_SUFFIX_ASM_INCLUDE "inc" +#define FILE_SUFFIX_C_INCLUDE "h" +#define FILE_SUFFIX_ASL_CODE "asl" + + +/* Types for input files */ + +#define ASL_INPUT_TYPE_BINARY 0 +#define ASL_INPUT_TYPE_ASCII_ASL 1 +#define ASL_INPUT_TYPE_ASCII_DATA 2 + + +/* Misc */ + +#define ASL_EXTERNAL_METHOD 255 +#define ASL_ABORT TRUE +#define ASL_NO_ABORT FALSE +#define ASL_EOF ACPI_UINT32_MAX + + +/* Support for reserved method names */ + +#define ACPI_VALID_RESERVED_NAME_MAX 0x80000000 +#define ACPI_NOT_RESERVED_NAME ACPI_UINT32_MAX +#define ACPI_PREDEFINED_NAME (ACPI_UINT32_MAX - 1) +#define ACPI_EVENT_RESERVED_NAME (ACPI_UINT32_MAX - 2) +#define ACPI_COMPILER_RESERVED_NAME (ACPI_UINT32_MAX - 3) + + +/* String to Integer conversion */ + +#define NEGATIVE 1 +#define POSITIVE 0 + + +/* Helper macros for resource tag creation */ + +#define RsCreateMultiBitField \ + RsCreateResourceField + +#define RsCreateBitField(Op, Name, ByteOffset, BitOffset) \ + RsCreateResourceField (Op, Name, ByteOffset, BitOffset, 1) + +#define RsCreateByteField(Op, Name, ByteOffset) \ + RsCreateResourceField (Op, Name, ByteOffset, 0, 8); + +#define RsCreateWordField(Op, Name, ByteOffset) \ + RsCreateResourceField (Op, Name, ByteOffset, 0, 16); + +#define RsCreateDwordField(Op, Name, ByteOffset) \ + RsCreateResourceField (Op, Name, ByteOffset, 0, 32); + +#define RsCreateQwordField(Op, Name, ByteOffset) \ + RsCreateResourceField (Op, Name, ByteOffset, 0, 64); + +#endif /* ASLDEFINE.H */ + diff --git a/sys/contrib/dev/acpica/compiler/aslerror.c b/sys/contrib/dev/acpica/compiler/aslerror.c new file mode 100644 index 0000000..9173d46 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslerror.c @@ -0,0 +1,755 @@ + +/****************************************************************************** + * + * Module Name: aslerror - Error handling and statistics + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define ASL_EXCEPTIONS +#include <contrib/dev/acpica/compiler/aslcompiler.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslerror") + +/* Local prototypes */ + +static void +AeAddToErrorLog ( + ASL_ERROR_MSG *Enode); + + +/******************************************************************************* + * + * FUNCTION: AeClearErrorLog + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Empty the error list + * + ******************************************************************************/ + +void +AeClearErrorLog ( + void) +{ + ASL_ERROR_MSG *Enode = Gbl_ErrorLog; + ASL_ERROR_MSG *Next; + + /* Walk the error node list */ + + while (Enode) + { + Next = Enode->Next; + ACPI_FREE (Enode); + Enode = Next; + } + + Gbl_ErrorLog = NULL; +} + + +/******************************************************************************* + * + * FUNCTION: AeAddToErrorLog + * + * PARAMETERS: Enode - An error node to add to the log + * + * RETURN: None + * + * DESCRIPTION: Add a new error node to the error log. The error log is + * ordered by the "logical" line number (cumulative line number + * including all include files.) + * + ******************************************************************************/ + +static void +AeAddToErrorLog ( + ASL_ERROR_MSG *Enode) +{ + ASL_ERROR_MSG *Next; + ASL_ERROR_MSG *Prev; + + + /* If Gbl_ErrorLog is null, this is the first error node */ + + if (!Gbl_ErrorLog) + { + Gbl_ErrorLog = Enode; + return; + } + + /* + * Walk error list until we find a line number greater than ours. + * List is sorted according to line number. + */ + Prev = NULL; + Next = Gbl_ErrorLog; + + while ((Next) && + (Next->LogicalLineNumber <= Enode->LogicalLineNumber)) + { + Prev = Next; + Next = Next->Next; + } + + /* Found our place in the list */ + + Enode->Next = Next; + + if (Prev) + { + Prev->Next = Enode; + } + else + { + Gbl_ErrorLog = Enode; + } +} + + +/******************************************************************************* + * + * FUNCTION: AePrintException + * + * PARAMETERS: FileId - ID of output file + * Enode - Error node to print + * Header - Additional text before each message + * + * RETURN: None + * + * DESCRIPTION: Print the contents of an error node. + * + * NOTE: We don't use the FlxxxFile I/O functions here because on error + * they abort the compiler and call this function! Since we + * are reporting errors here, we ignore most output errors and + * just try to get out as much as we can. + * + ******************************************************************************/ + +void +AePrintException ( + UINT32 FileId, + ASL_ERROR_MSG *Enode, + char *Header) +{ + UINT8 SourceByte; + int Actual; + size_t RActual; + UINT32 MsgLength; + char *MainMessage; + char *ExtraMessage; + UINT32 SourceColumn; + UINT32 ErrorColumn; + FILE *OutputFile; + FILE *SourceFile = NULL; + long FileSize; + BOOLEAN PrematureEOF = FALSE; + + + if (Gbl_NoErrors) + { + return; + } + + /* + * Only listing files have a header, and remarks/optimizations + * are always output + */ + if (!Header) + { + /* Ignore remarks if requested */ + + switch (Enode->Level) + { + case ASL_REMARK: + if (!Gbl_DisplayRemarks) + { + return; + } + break; + + case ASL_OPTIMIZATION: + if (!Gbl_DisplayOptimizations) + { + return; + } + break; + + default: + break; + } + } + + /* Get the file handles */ + + OutputFile = Gbl_Files[FileId].Handle; + + + if (!Enode->SourceLine) + { + /* Use the merged header/source file if present, otherwise use input file */ + + SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle; + if (!SourceFile) + { + SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle; + } + + if (SourceFile) + { + /* Determine if the error occurred at source file EOF */ + + fseek (SourceFile, 0, SEEK_END); + FileSize = ftell (SourceFile); + + if ((long) Enode->LogicalByteOffset >= FileSize) + { + PrematureEOF = TRUE; + } + } + } + + if (Header) + { + fprintf (OutputFile, "%s", Header); + } + + /* Print filename and line number if present and valid */ + + if (Enode->Filename) + { + if (Gbl_VerboseErrors) + { + fprintf (OutputFile, "%-8s", Enode->Filename); + + if (Enode->LineNumber) + { + if (Enode->SourceLine) + { + fprintf (OutputFile, " %6u: %s", + Enode->LineNumber, Enode->SourceLine); + } + else + { + fprintf (OutputFile, " %6u: ", Enode->LineNumber); + + /* + * If not at EOF, get the corresponding source code line and + * display it. Don't attempt this if we have a premature EOF + * condition. + */ + if (!PrematureEOF) + { + /* + * Seek to the offset in the combined source file, read + * the source line, and write it to the output. + */ + Actual = fseek (SourceFile, (long) Enode->LogicalByteOffset, + (int) SEEK_SET); + if (Actual) + { + fprintf (OutputFile, + "[*** iASL: Seek error on source code temp file %s ***]", + Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); + } + else + { + RActual = fread (&SourceByte, 1, 1, SourceFile); + if (!RActual) + { + fprintf (OutputFile, + "[*** iASL: Read error on source code temp file %s ***]", + Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename); + } + + else while (RActual && SourceByte && (SourceByte != '\n')) + { + fwrite (&SourceByte, 1, 1, OutputFile); + RActual = fread (&SourceByte, 1, 1, SourceFile); + } + } + } + + fprintf (OutputFile, "\n"); + } + } + } + else + { + fprintf (OutputFile, "%s", Enode->Filename); + + if (Enode->LineNumber) + { + fprintf (OutputFile, "(%u) i:%6u : ", + Enode->LineNumber, Enode->LineNumber); + } + } + } + + /* NULL message ID, just print the raw message */ + + if (Enode->MessageId == 0) + { + fprintf (OutputFile, "%s\n", Enode->Message); + } + else + { + /* Decode the message ID */ + + fprintf (OutputFile, "%s %4.4d - ", + AslErrorLevel[Enode->Level], + Enode->MessageId + ((Enode->Level+1) * 1000)); + + MainMessage = AslMessages[Enode->MessageId]; + ExtraMessage = Enode->Message; + + if (Enode->LineNumber) + { + /* Main message: try to use string from AslMessages first */ + + if (!MainMessage) + { + MainMessage = ""; + } + + MsgLength = strlen (MainMessage); + if (MsgLength == 0) + { + /* Use the secondary/extra message as main message */ + + MainMessage = Enode->Message; + if (!MainMessage) + { + MainMessage = ""; + } + + MsgLength = strlen (MainMessage); + ExtraMessage = NULL; + } + + if (Gbl_VerboseErrors && !PrematureEOF) + { + SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2; + ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1; + + if ((MsgLength + ErrorColumn) < (SourceColumn - 1)) + { + fprintf (OutputFile, "%*s%s", + (int) ((SourceColumn - 1) - ErrorColumn), + MainMessage, " ^ "); + } + else + { + fprintf (OutputFile, "%*s %s", + (int) ((SourceColumn - ErrorColumn) + 1), "^", + MainMessage); + } + } + else + { + fprintf (OutputFile, " %s", MainMessage); + } + + /* Print the extra info message if present */ + + if (ExtraMessage) + { + fprintf (OutputFile, " (%s)", ExtraMessage); + } + + if (PrematureEOF) + { + fprintf (OutputFile, " and premature End-Of-File"); + } + + fprintf (OutputFile, "\n"); + if (Gbl_VerboseErrors) + { + fprintf (OutputFile, "\n"); + } + } + else + { + fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: AePrintErrorLog + * + * PARAMETERS: FileId - Where to output the error log + * + * RETURN: None + * + * DESCRIPTION: Print the entire contents of the error log + * + ******************************************************************************/ + +void +AePrintErrorLog ( + UINT32 FileId) +{ + ASL_ERROR_MSG *Enode = Gbl_ErrorLog; + + + /* Walk the error node list */ + + while (Enode) + { + AePrintException (FileId, Enode, NULL); + Enode = Enode->Next; + } +} + + +/******************************************************************************* + * + * FUNCTION: AslCommonError2 + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * LineNumber - Actual file line number + * Column - Column in current line + * SourceLine - Actual source code line + * Filename - source filename + * ExtraMessage - additional error message + * + * RETURN: None + * + * DESCRIPTION: Create a new error node and add it to the error log + * + ******************************************************************************/ + +void +AslCommonError2 ( + UINT8 Level, + UINT8 MessageId, + UINT32 LineNumber, + UINT32 Column, + char *SourceLine, + char *Filename, + char *ExtraMessage) +{ + char *MessageBuffer = NULL; + char *LineBuffer; + ASL_ERROR_MSG *Enode; + + + Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG)); + + if (ExtraMessage) + { + /* Allocate a buffer for the message and a new error node */ + + MessageBuffer = UtLocalCalloc (strlen (ExtraMessage) + 1); + + /* Keep a copy of the extra message */ + + ACPI_STRCPY (MessageBuffer, ExtraMessage); + } + + LineBuffer = UtLocalCalloc (strlen (SourceLine) + 1); + ACPI_STRCPY (LineBuffer, SourceLine); + + /* Initialize the error node */ + + if (Filename) + { + Enode->Filename = Filename; + Enode->FilenameLength = strlen (Filename); + if (Enode->FilenameLength < 6) + { + Enode->FilenameLength = 6; + } + } + + Enode->MessageId = MessageId; + Enode->Level = Level; + Enode->LineNumber = LineNumber; + Enode->LogicalLineNumber = LineNumber; + Enode->LogicalByteOffset = 0; + Enode->Column = Column; + Enode->Message = MessageBuffer; + Enode->SourceLine = LineBuffer; + + /* Add the new node to the error node list */ + + AeAddToErrorLog (Enode); + + if (Gbl_DebugFlag) + { + /* stderr is a file, send error to it immediately */ + + AePrintException (ASL_FILE_STDERR, Enode, NULL); + } + + Gbl_ExceptionCount[Level]++; +} + + +/******************************************************************************* + * + * FUNCTION: AslCommonError + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * CurrentLineNumber - Actual file line number + * LogicalLineNumber - Cumulative line number + * LogicalByteOffset - Byte offset in source file + * Column - Column in current line + * Filename - source filename + * ExtraMessage - additional error message + * + * RETURN: None + * + * DESCRIPTION: Create a new error node and add it to the error log + * + ******************************************************************************/ + +void +AslCommonError ( + UINT8 Level, + UINT8 MessageId, + UINT32 CurrentLineNumber, + UINT32 LogicalLineNumber, + UINT32 LogicalByteOffset, + UINT32 Column, + char *Filename, + char *ExtraMessage) +{ + UINT32 MessageSize; + char *MessageBuffer = NULL; + ASL_ERROR_MSG *Enode; + + + Enode = UtLocalCalloc (sizeof (ASL_ERROR_MSG)); + + if (ExtraMessage) + { + /* Allocate a buffer for the message and a new error node */ + + MessageSize = strlen (ExtraMessage) + 1; + MessageBuffer = UtLocalCalloc (MessageSize); + + /* Keep a copy of the extra message */ + + ACPI_STRCPY (MessageBuffer, ExtraMessage); + } + + /* Initialize the error node */ + + if (Filename) + { + Enode->Filename = Filename; + Enode->FilenameLength = strlen (Filename); + if (Enode->FilenameLength < 6) + { + Enode->FilenameLength = 6; + } + } + + Enode->MessageId = MessageId; + Enode->Level = Level; + Enode->LineNumber = CurrentLineNumber; + Enode->LogicalLineNumber = LogicalLineNumber; + Enode->LogicalByteOffset = LogicalByteOffset; + Enode->Column = Column; + Enode->Message = MessageBuffer; + Enode->SourceLine = NULL; + + /* Add the new node to the error node list */ + + AeAddToErrorLog (Enode); + + if (Gbl_DebugFlag) + { + /* stderr is a file, send error to it immediately */ + + AePrintException (ASL_FILE_STDERR, Enode, NULL); + } + + Gbl_ExceptionCount[Level]++; + if (Gbl_ExceptionCount[ASL_ERROR] > ASL_MAX_ERROR_COUNT) + { + printf ("\nMaximum error count (%u) exceeded\n", ASL_MAX_ERROR_COUNT); + + Gbl_SourceLine = 0; + Gbl_NextError = Gbl_ErrorLog; + CmDoOutputFiles (); + CmCleanupAndExit (); + exit(1); + } + + return; +} + + +/******************************************************************************* + * + * FUNCTION: AslError + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * Op - Parse node where error happened + * ExtraMessage - additional error message + * + * RETURN: None + * + * DESCRIPTION: Main error reporting routine for the ASL compiler (all code + * except the parser.) + * + ******************************************************************************/ + +void +AslError ( + UINT8 Level, + UINT8 MessageId, + ACPI_PARSE_OBJECT *Op, + char *ExtraMessage) +{ + + switch (Level) + { + case ASL_WARNING2: + case ASL_WARNING3: + if (Gbl_WarningLevel < Level) + { + return; + } + break; + + default: + break; + } + + if (Op) + { + AslCommonError (Level, MessageId, Op->Asl.LineNumber, + Op->Asl.LogicalLineNumber, + Op->Asl.LogicalByteOffset, + Op->Asl.Column, + Op->Asl.Filename, ExtraMessage); + } + else + { + AslCommonError (Level, MessageId, 0, + 0, 0, 0, NULL, ExtraMessage); + } +} + + +/******************************************************************************* + * + * FUNCTION: AslCoreSubsystemError + * + * PARAMETERS: Op - Parse node where error happened + * Status - The ACPI CA Exception + * ExtraMessage - additional error message + * Abort - TRUE -> Abort compilation + * + * RETURN: None + * + * DESCRIPTION: Error reporting routine for exceptions returned by the ACPI + * CA core subsystem. + * + ******************************************************************************/ + +void +AslCoreSubsystemError ( + ACPI_PARSE_OBJECT *Op, + ACPI_STATUS Status, + char *ExtraMessage, + BOOLEAN Abort) +{ + + sprintf (MsgBuffer, "%s %s", AcpiFormatException (Status), ExtraMessage); + + if (Op) + { + AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Op->Asl.LineNumber, + Op->Asl.LogicalLineNumber, + Op->Asl.LogicalByteOffset, + Op->Asl.Column, + Op->Asl.Filename, MsgBuffer); + } + else + { + AslCommonError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, 0, + 0, 0, 0, NULL, MsgBuffer); + } + + if (Abort) + { + AslAbort (); + } +} + + +/******************************************************************************* + * + * FUNCTION: AslCompilererror + * + * PARAMETERS: CompilerMessage - Error message from the parser + * + * RETURN: Status (0 for now) + * + * DESCRIPTION: Report an error situation discovered in a production + * NOTE: don't change the name of this function, it is called + * from the auto-generated parser. + * + ******************************************************************************/ + +int +AslCompilererror ( + const char *CompilerMessage) +{ + + AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber, + Gbl_LogicalLineNumber, Gbl_CurrentLineOffset, + Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, + ACPI_CAST_PTR (char, CompilerMessage)); + + return 0; +} diff --git a/sys/contrib/dev/acpica/compiler/aslfiles.c b/sys/contrib/dev/acpica/compiler/aslfiles.c new file mode 100644 index 0000000..e3d8a1a --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslfiles.c @@ -0,0 +1,1016 @@ + +/****************************************************************************** + * + * Module Name: aslfiles - file I/O suppoert + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/include/acapps.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslfiles") + +/* Local prototypes */ + +FILE * +FlOpenIncludeWithPrefix ( + char *PrefixDir, + char *Filename); + + +#ifdef ACPI_OBSOLETE_FUNCTIONS +ACPI_STATUS +FlParseInputPathname ( + char *InputFilename); +#endif + + +/******************************************************************************* + * + * FUNCTION: AslAbort + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Dump the error log and abort the compiler. Used for serious + * I/O errors + * + ******************************************************************************/ + +void +AslAbort ( + void) +{ + + AePrintErrorLog (ASL_FILE_STDERR); + if (Gbl_DebugFlag) + { + /* Print error summary to stdout also */ + + AePrintErrorLog (ASL_FILE_STDOUT); + } + + exit (1); +} + + +/******************************************************************************* + * + * FUNCTION: FlFileError + * + * PARAMETERS: FileId - Index into file info array + * ErrorId - Index into error message array + * + * RETURN: None + * + * DESCRIPTION: Decode errno to an error message and add the entire error + * to the error log. + * + ******************************************************************************/ + +void +FlFileError ( + UINT32 FileId, + UINT8 ErrorId) +{ + + sprintf (MsgBuffer, "\"%s\" (%s)", Gbl_Files[FileId].Filename, + strerror (errno)); + AslCommonError (ASL_ERROR, ErrorId, 0, 0, 0, 0, NULL, MsgBuffer); +} + + +/******************************************************************************* + * + * FUNCTION: FlOpenFile + * + * PARAMETERS: FileId - Index into file info array + * Filename - file pathname to open + * Mode - Open mode for fopen + * + * RETURN: None + * + * DESCRIPTION: Open a file. + * NOTE: Aborts compiler on any error. + * + ******************************************************************************/ + +void +FlOpenFile ( + UINT32 FileId, + char *Filename, + char *Mode) +{ + FILE *File; + + + File = fopen (Filename, Mode); + + Gbl_Files[FileId].Filename = Filename; + Gbl_Files[FileId].Handle = File; + + if (!File) + { + FlFileError (FileId, ASL_MSG_OPEN); + AslAbort (); + } +} + + +/******************************************************************************* + * + * FUNCTION: FlGetFileSize + * + * PARAMETERS: FileId - Index into file info array + * + * RETURN: File Size + * + * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open. + * + ******************************************************************************/ + +UINT32 +FlGetFileSize ( + UINT32 FileId) +{ + FILE *fp; + UINT32 FileSize; + long Offset; + + + fp = Gbl_Files[FileId].Handle; + Offset = ftell (fp); + + fseek (fp, 0, SEEK_END); + FileSize = (UINT32) ftell (fp); + + /* Restore file pointer */ + + fseek (fp, Offset, SEEK_SET); + return (FileSize); +} + + +/******************************************************************************* + * + * FUNCTION: FlReadFile + * + * PARAMETERS: FileId - Index into file info array + * Buffer - Where to place the data + * Length - Amount to read + * + * RETURN: Status. AE_ERROR indicates EOF. + * + * DESCRIPTION: Read data from an open file. + * NOTE: Aborts compiler on any error. + * + ******************************************************************************/ + +ACPI_STATUS +FlReadFile ( + UINT32 FileId, + void *Buffer, + UINT32 Length) +{ + UINT32 Actual; + + + /* Read and check for error */ + + Actual = fread (Buffer, 1, Length, Gbl_Files[FileId].Handle); + if (Actual != Length) + { + if (feof (Gbl_Files[FileId].Handle)) + { + /* End-of-file, just return error */ + + return (AE_ERROR); + } + + FlFileError (FileId, ASL_MSG_READ); + AslAbort (); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: FlWriteFile + * + * PARAMETERS: FileId - Index into file info array + * Buffer - Data to write + * Length - Amount of data to write + * + * RETURN: None + * + * DESCRIPTION: Write data to an open file. + * NOTE: Aborts compiler on any error. + * + ******************************************************************************/ + +void +FlWriteFile ( + UINT32 FileId, + void *Buffer, + UINT32 Length) +{ + UINT32 Actual; + + + /* Write and check for error */ + + Actual = fwrite ((char *) Buffer, 1, Length, Gbl_Files[FileId].Handle); + if (Actual != Length) + { + FlFileError (FileId, ASL_MSG_WRITE); + AslAbort (); + } +} + + +/******************************************************************************* + * + * FUNCTION: FlPrintFile + * + * PARAMETERS: FileId - Index into file info array + * Format - Printf format string + * ... - Printf arguments + * + * RETURN: None + * + * DESCRIPTION: Formatted write to an open file. + * NOTE: Aborts compiler on any error. + * + ******************************************************************************/ + +void +FlPrintFile ( + UINT32 FileId, + char *Format, + ...) +{ + INT32 Actual; + va_list Args; + + + va_start (Args, Format); + + Actual = vfprintf (Gbl_Files[FileId].Handle, Format, Args); + va_end (Args); + + if (Actual == -1) + { + FlFileError (FileId, ASL_MSG_WRITE); + AslAbort (); + } +} + + +/******************************************************************************* + * + * FUNCTION: FlSeekFile + * + * PARAMETERS: FileId - Index into file info array + * Offset - Absolute byte offset in file + * + * RETURN: None + * + * DESCRIPTION: Seek to absolute offset + * NOTE: Aborts compiler on any error. + * + ******************************************************************************/ + +void +FlSeekFile ( + UINT32 FileId, + long Offset) +{ + int Error; + + + Error = fseek (Gbl_Files[FileId].Handle, Offset, SEEK_SET); + if (Error) + { + FlFileError (FileId, ASL_MSG_SEEK); + AslAbort (); + } +} + + +/******************************************************************************* + * + * FUNCTION: FlCloseFile + * + * PARAMETERS: FileId - Index into file info array + * + * RETURN: None + * + * DESCRIPTION: Close an open file. Aborts compiler on error + * + ******************************************************************************/ + +void +FlCloseFile ( + UINT32 FileId) +{ + int Error; + + + if (!Gbl_Files[FileId].Handle) + { + return; + } + + Error = fclose (Gbl_Files[FileId].Handle); + if (Error) + { + FlFileError (FileId, ASL_MSG_CLOSE); + AslAbort (); + } + + Gbl_Files[FileId].Handle = NULL; + return; +} + + +/******************************************************************************* + * + * FUNCTION: FlSetLineNumber + * + * PARAMETERS: Op - Parse node for the LINE asl statement + * + * RETURN: None. + * + * DESCRIPTION: Set the current line number + * + ******************************************************************************/ + +void +FlSetLineNumber ( + UINT32 LineNumber) +{ + + DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New line number %u (old %u)\n", + LineNumber, Gbl_LogicalLineNumber); + + Gbl_CurrentLineNumber = LineNumber; + Gbl_LogicalLineNumber = LineNumber; +} + + +/******************************************************************************* + * + * FUNCTION: FlSetFilename + * + * PARAMETERS: Op - Parse node for the LINE asl statement + * + * RETURN: None. + * + * DESCRIPTION: Set the current filename + * + ******************************************************************************/ + +void +FlSetFilename ( + char *Filename) +{ + + DbgPrint (ASL_PARSE_OUTPUT, "\n#line: New filename %s (old %s)\n", + Filename, Gbl_Files[ASL_FILE_INPUT].Filename); + + Gbl_Files[ASL_FILE_INPUT].Filename = Filename; +} + + +/******************************************************************************* + * + * FUNCTION: FlAddIncludeDirectory + * + * PARAMETERS: Dir - Directory pathname string + * + * RETURN: None + * + * DESCRIPTION: Add a directory the list of include prefix directories. + * + ******************************************************************************/ + +void +FlAddIncludeDirectory ( + char *Dir) +{ + ASL_INCLUDE_DIR *NewDir; + ASL_INCLUDE_DIR *NextDir; + ASL_INCLUDE_DIR *PrevDir = NULL; + UINT32 NeedsSeparator = 0; + size_t DirLength; + + + DirLength = strlen (Dir); + if (!DirLength) + { + return; + } + + /* Make sure that the pathname ends with a path separator */ + + if ((Dir[DirLength-1] != '/') && + (Dir[DirLength-1] != '\\')) + { + NeedsSeparator = 1; + } + + NewDir = ACPI_ALLOCATE_ZEROED (sizeof (ASL_INCLUDE_DIR)); + NewDir->Dir = ACPI_ALLOCATE (DirLength + 1 + NeedsSeparator); + strcpy (NewDir->Dir, Dir); + if (NeedsSeparator) + { + strcat (NewDir->Dir, "/"); + } + + /* + * Preserve command line ordering of -I options by adding new elements + * at the end of the list + */ + NextDir = Gbl_IncludeDirList; + while (NextDir) + { + PrevDir = NextDir; + NextDir = NextDir->Next; + } + + if (PrevDir) + { + PrevDir->Next = NewDir; + } + else + { + Gbl_IncludeDirList = NewDir; + } +} + + +/******************************************************************************* + * + * FUNCTION: FlOpenIncludeWithPrefix + * + * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero + * length string. + * Filename - The include filename from the source ASL. + * + * RETURN: Valid file descriptor if successful. Null otherwise. + * + * DESCRIPTION: Open an include file and push it on the input file stack. + * + ******************************************************************************/ + +FILE * +FlOpenIncludeWithPrefix ( + char *PrefixDir, + char *Filename) +{ + FILE *IncludeFile; + char *Pathname; + + + /* Build the full pathname to the file */ + + Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); + + strcpy (Pathname, PrefixDir); + strcat (Pathname, Filename); + + DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n", + Pathname); + + /* Attempt to open the file, push if successful */ + + IncludeFile = fopen (Pathname, "r"); + if (IncludeFile) + { + /* Push the include file on the open input file stack */ + + AslPushInputFileStack (IncludeFile, Pathname); + return (IncludeFile); + } + + ACPI_FREE (Pathname); + return (NULL); +} + + +/******************************************************************************* + * + * FUNCTION: FlOpenIncludeFile + * + * PARAMETERS: Op - Parse node for the INCLUDE ASL statement + * + * RETURN: None. + * + * DESCRIPTION: Open an include file and push it on the input file stack. + * + ******************************************************************************/ + +void +FlOpenIncludeFile ( + ACPI_PARSE_OBJECT *Op) +{ + FILE *IncludeFile; + ASL_INCLUDE_DIR *NextDir; + + + /* Op must be valid */ + + if (!Op) + { + AslCommonError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_InputByteCount, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, " - Null parse node"); + + return; + } + + /* + * Flush out the "include ()" statement on this line, start + * the actual include file on the next line + */ + AslResetCurrentLineBuffer (); + FlPrintFile (ASL_FILE_SOURCE_OUTPUT, "\n"); + Gbl_CurrentLineOffset++; + + + /* Attempt to open the include file */ + + /* If the file specifies an absolute path, just open it */ + + if ((Op->Asl.Value.String[0] == '/') || + (Op->Asl.Value.String[0] == '\\') || + (Op->Asl.Value.String[1] == ':')) + { + IncludeFile = FlOpenIncludeWithPrefix ("", Op->Asl.Value.String); + if (!IncludeFile) + { + goto ErrorExit; + } + return; + } + + /* + * The include filename is not an absolute path. + * + * First, search for the file within the "local" directory -- meaning + * the same directory that contains the source file. + * + * Construct the file pathname from the global directory name. + */ + IncludeFile = FlOpenIncludeWithPrefix (Gbl_DirectoryPath, Op->Asl.Value.String); + if (IncludeFile) + { + return; + } + + /* + * Second, search for the file within the (possibly multiple) directories + * specified by the -I option on the command line. + */ + NextDir = Gbl_IncludeDirList; + while (NextDir) + { + IncludeFile = FlOpenIncludeWithPrefix (NextDir->Dir, Op->Asl.Value.String); + if (IncludeFile) + { + return; + } + + NextDir = NextDir->Next; + } + + /* We could not open the include file after trying very hard */ + +ErrorExit: + sprintf (MsgBuffer, "%s, %s", Op->Asl.Value.String, strerror (errno)); + AslError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, Op, MsgBuffer); +} + + +/******************************************************************************* + * + * FUNCTION: FlOpenInputFile + * + * PARAMETERS: InputFilename - The user-specified ASL source file to be + * compiled + * + * RETURN: Status + * + * DESCRIPTION: Open the specified input file, and save the directory path to + * the file so that include files can be opened in + * the same directory. + * + ******************************************************************************/ + +ACPI_STATUS +FlOpenInputFile ( + char *InputFilename) +{ + + /* Open the input ASL file, text mode */ + + FlOpenFile (ASL_FILE_INPUT, InputFilename, "r"); + AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: FlOpenAmlOutputFile + * + * PARAMETERS: FilenamePrefix - The user-specified ASL source file + * + * RETURN: Status + * + * DESCRIPTION: Create the output filename (*.AML) and open the file. The file + * is created in the same directory as the parent input file. + * + ******************************************************************************/ + +ACPI_STATUS +FlOpenAmlOutputFile ( + char *FilenamePrefix) +{ + char *Filename; + + + /* Output filename usually comes from the ASL itself */ + + Filename = Gbl_Files[ASL_FILE_AML_OUTPUT].Filename; + if (!Filename) + { + /* Create the output AML filename */ + + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_AML_CODE); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_OUTPUT_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + } + + /* Open the output AML file in binary mode */ + + FlOpenFile (ASL_FILE_AML_OUTPUT, Filename, "w+b"); + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: FlOpenMiscOutputFiles + * + * PARAMETERS: FilenamePrefix - The user-specified ASL source file + * + * RETURN: Status + * + * DESCRIPTION: Create and open the various output files needed, depending on + * the command line options + * + ******************************************************************************/ + +ACPI_STATUS +FlOpenMiscOutputFiles ( + char *FilenamePrefix) +{ + char *Filename; + + + /* Create/Open a hex output file if asked */ + + if (Gbl_HexOutputFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_HEX_DUMP); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the hex file, text mode */ + + FlOpenFile (ASL_FILE_HEX_OUTPUT, Filename, "w+"); + + AslCompilerSignon (ASL_FILE_HEX_OUTPUT); + AslCompilerFileHeader (ASL_FILE_HEX_OUTPUT); + } + + /* Create/Open a debug output file if asked */ + + if (Gbl_DebugFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_DEBUG); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the debug file as STDERR, text mode */ + + /* TBD: hide this behind a FlReopenFile function */ + + Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Filename = Filename; + Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle = + freopen (Filename, "w+t", stderr); + + if (!Gbl_Files[ASL_FILE_DEBUG_OUTPUT].Handle) + { + AslCommonError (ASL_ERROR, ASL_MSG_DEBUG_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + AslCompilerSignon (ASL_FILE_DEBUG_OUTPUT); + AslCompilerFileHeader (ASL_FILE_DEBUG_OUTPUT); + } + + /* Create/Open a listing output file if asked */ + + if (Gbl_ListingFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_LISTING); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the listing file, text mode */ + + FlOpenFile (ASL_FILE_LISTING_OUTPUT, Filename, "w+"); + + AslCompilerSignon (ASL_FILE_LISTING_OUTPUT); + AslCompilerFileHeader (ASL_FILE_LISTING_OUTPUT); + } + + /* Create the preprocessor output file if preprocessor enabled */ + + if (Gbl_PreprocessFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_PREPROCESSOR); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_PREPROCESSOR_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + FlOpenFile (ASL_FILE_PREPROCESSOR, Filename, "w+b"); + } + + /* All done for data table compiler */ + + if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) + { + return (AE_OK); + } + + /* Create/Open a combined source output file */ + + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_SOURCE); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* + * Open the source output file, binary mode (so that LF does not get + * expanded to CR/LF on some systems, messing up our seek + * calculations.) + */ + FlOpenFile (ASL_FILE_SOURCE_OUTPUT, Filename, "w+b"); + +/* +// TBD: TEMP +// AslCompilerin = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle; +*/ + /* Create/Open a assembly code source output file if asked */ + + if (Gbl_AsmOutputFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_SOURCE); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the assembly code source file, text mode */ + + FlOpenFile (ASL_FILE_ASM_SOURCE_OUTPUT, Filename, "w+"); + + AslCompilerSignon (ASL_FILE_ASM_SOURCE_OUTPUT); + AslCompilerFileHeader (ASL_FILE_ASM_SOURCE_OUTPUT); + } + + /* Create/Open a C code source output file if asked */ + + if (Gbl_C_OutputFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_SOURCE); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the C code source file, text mode */ + + FlOpenFile (ASL_FILE_C_SOURCE_OUTPUT, Filename, "w+"); + + FlPrintFile (ASL_FILE_C_SOURCE_OUTPUT, "/*\n"); + AslCompilerSignon (ASL_FILE_C_SOURCE_OUTPUT); + AslCompilerFileHeader (ASL_FILE_C_SOURCE_OUTPUT); + } + + /* Create/Open a assembly include output file if asked */ + + if (Gbl_AsmIncludeOutputFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_ASM_INCLUDE); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the assembly include file, text mode */ + + FlOpenFile (ASL_FILE_ASM_INCLUDE_OUTPUT, Filename, "w+"); + + AslCompilerSignon (ASL_FILE_ASM_INCLUDE_OUTPUT); + AslCompilerFileHeader (ASL_FILE_ASM_INCLUDE_OUTPUT); + } + + /* Create/Open a C include output file if asked */ + + if (Gbl_C_IncludeOutputFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_C_INCLUDE); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the C include file, text mode */ + + FlOpenFile (ASL_FILE_C_INCLUDE_OUTPUT, Filename, "w+"); + + FlPrintFile (ASL_FILE_C_INCLUDE_OUTPUT, "/*\n"); + AslCompilerSignon (ASL_FILE_C_INCLUDE_OUTPUT); + AslCompilerFileHeader (ASL_FILE_C_INCLUDE_OUTPUT); + } + + /* Create a namespace output file if asked */ + + if (Gbl_NsOutputFlag) + { + Filename = FlGenerateFilename (FilenamePrefix, FILE_SUFFIX_NAMESPACE); + if (!Filename) + { + AslCommonError (ASL_ERROR, ASL_MSG_LISTING_FILENAME, + 0, 0, 0, 0, NULL, NULL); + return (AE_ERROR); + } + + /* Open the namespace file, text mode */ + + FlOpenFile (ASL_FILE_NAMESPACE_OUTPUT, Filename, "w+"); + + AslCompilerSignon (ASL_FILE_NAMESPACE_OUTPUT); + AslCompilerFileHeader (ASL_FILE_NAMESPACE_OUTPUT); + } + + return (AE_OK); +} + + +#ifdef ACPI_OBSOLETE_FUNCTIONS +/******************************************************************************* + * + * FUNCTION: FlParseInputPathname + * + * PARAMETERS: InputFilename - The user-specified ASL source file to be + * compiled + * + * RETURN: Status + * + * DESCRIPTION: Split the input path into a directory and filename part + * 1) Directory part used to open include files + * 2) Filename part used to generate output filenames + * + ******************************************************************************/ + +ACPI_STATUS +FlParseInputPathname ( + char *InputFilename) +{ + char *Substring; + + + if (!InputFilename) + { + return (AE_OK); + } + + /* Get the path to the input filename's directory */ + + Gbl_DirectoryPath = strdup (InputFilename); + if (!Gbl_DirectoryPath) + { + return (AE_NO_MEMORY); + } + + Substring = strrchr (Gbl_DirectoryPath, '\\'); + if (!Substring) + { + Substring = strrchr (Gbl_DirectoryPath, '/'); + if (!Substring) + { + Substring = strrchr (Gbl_DirectoryPath, ':'); + } + } + + if (!Substring) + { + Gbl_DirectoryPath[0] = 0; + if (Gbl_UseDefaultAmlFilename) + { + Gbl_OutputFilenamePrefix = strdup (InputFilename); + } + } + else + { + if (Gbl_UseDefaultAmlFilename) + { + Gbl_OutputFilenamePrefix = strdup (Substring + 1); + } + *(Substring+1) = 0; + } + + return (AE_OK); +} +#endif + + diff --git a/sys/contrib/dev/acpica/compiler/aslfold.c b/sys/contrib/dev/acpica/compiler/aslfold.c new file mode 100644 index 0000000..61a2944 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslfold.c @@ -0,0 +1,491 @@ + +/****************************************************************************** + * + * Module Name: aslfold - Constant folding + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + +#include <contrib/dev/acpica/include/acdispat.h> +#include <contrib/dev/acpica/include/acparser.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslfold") + +/* Local prototypes */ + +static ACPI_STATUS +OpcAmlEvaluationWalk1 ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static ACPI_STATUS +OpcAmlEvaluationWalk2 ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static ACPI_STATUS +OpcAmlCheckForConstant ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + + +/******************************************************************************* + * + * FUNCTION: OpcAmlEvaluationWalk1 + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Descending callback for AML execution of constant subtrees + * + ******************************************************************************/ + +static ACPI_STATUS +OpcAmlEvaluationWalk1 ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = Context; + ACPI_STATUS Status; + ACPI_PARSE_OBJECT *OutOp; + + + WalkState->Op = Op; + WalkState->Opcode = Op->Common.AmlOpcode; + WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); + + /* Copy child pointer to Arg for compatibility with Interpreter */ + + if (Op->Asl.Child) + { + Op->Common.Value.Arg = Op->Asl.Child; + } + + /* Call AML dispatcher */ + + Status = AcpiDsExecBeginOp (WalkState, &OutOp); + if (ACPI_FAILURE (Status)) + { + AcpiOsPrintf ("Constant interpretation failed - %s\n", + AcpiFormatException (Status)); + } + + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: OpcAmlEvaluationWalk2 + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Ascending callback for AML execution of constant subtrees + * + ******************************************************************************/ + +static ACPI_STATUS +OpcAmlEvaluationWalk2 ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = Context; + ACPI_STATUS Status; + + + WalkState->Op = Op; + WalkState->Opcode = Op->Common.AmlOpcode; + WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); + + /* Copy child pointer to Arg for compatibility with Interpreter */ + + if (Op->Asl.Child) + { + Op->Common.Value.Arg = Op->Asl.Child; + } + + /* Call AML dispatcher */ + + Status = AcpiDsExecEndOp (WalkState); + if (ACPI_FAILURE (Status)) + { + AcpiOsPrintf ("Constant interpretation failed - %s\n", + AcpiFormatException (Status)); + } + + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: OpcAmlCheckForConstant + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Check one Op for a type 3/4/5 AML opcode + * + ******************************************************************************/ + +static ACPI_STATUS +OpcAmlCheckForConstant ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = Context; + + + WalkState->Op = Op; + WalkState->Opcode = Op->Common.AmlOpcode; + WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); + + DbgPrint (ASL_PARSE_OUTPUT, "[%.4d] Opcode: %12.12s ", + Op->Asl.LogicalLineNumber, Op->Asl.ParseOpName); + + if (!(WalkState->OpInfo->Flags & AML_CONSTANT)) + { + /* The opcode is not a Type 3/4/5 opcode */ + + if (Op->Asl.CompileFlags & NODE_IS_TARGET) + { + DbgPrint (ASL_PARSE_OUTPUT, + "**** Valid Target, cannot reduce ****\n"); + } + else + { + DbgPrint (ASL_PARSE_OUTPUT, + "**** Not a Type 3/4/5 opcode ****\n"); + } + + if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL) + { + /* + * We are looking at at normal expression to see if it can be + * reduced. It can't. No error + */ + return (AE_TYPE); + } + + /* + * This is an expression that MUST reduce to a constant, and it + * can't be reduced. This is an error + */ + if (Op->Asl.CompileFlags & NODE_IS_TARGET) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_TARGET, Op, + Op->Asl.ParseOpName); + } + else + { + AslError (ASL_ERROR, ASL_MSG_INVALID_CONSTANT_OP, Op, + Op->Asl.ParseOpName); + } + + return (AE_TYPE); + } + + /* Debug output */ + + DbgPrint (ASL_PARSE_OUTPUT, "TYPE_345"); + + if (Op->Asl.CompileFlags & NODE_IS_TARGET) + { + DbgPrint (ASL_PARSE_OUTPUT, " TARGET"); + } + if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG) + { + DbgPrint (ASL_PARSE_OUTPUT, " TERMARG"); + } + DbgPrint (ASL_PARSE_OUTPUT, "\n"); + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: OpcAmlConstantWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Reduce an Op and its subtree to a constant if possible + * + ******************************************************************************/ + +ACPI_STATUS +OpcAmlConstantWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState; + ACPI_STATUS Status = AE_OK; + ACPI_OPERAND_OBJECT *ObjDesc; + ACPI_PARSE_OBJECT *RootOp; + ACPI_PARSE_OBJECT *OriginalParentOp; + UINT8 WalkType; + + + /* + * Only interested in subtrees that could possibly contain + * expressions that can be evaluated at this time + */ + if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) || + (Op->Asl.CompileFlags & NODE_IS_TARGET)) + { + return (AE_OK); + } + + /* Set the walk type based on the reduction used for this op */ + + if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG) + { + /* Op is a TermArg, constant folding is merely optional */ + + if (!Gbl_FoldConstants) + { + return (AE_CTRL_DEPTH); + } + + WalkType = ACPI_WALK_CONST_OPTIONAL; + } + else + { + /* Op is a DataObject, the expression MUST reduced to a constant */ + + WalkType = ACPI_WALK_CONST_REQUIRED; + } + + /* Create a new walk state */ + + WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); + if (!WalkState) + { + return AE_NO_MEMORY; + } + + WalkState->NextOp = NULL; + WalkState->Params = NULL; + WalkState->CallerReturnDesc = &ObjDesc; + WalkState->WalkType = WalkType; + + /* + * Examine the entire subtree -- all nodes must be constants + * or type 3/4/5 opcodes + */ + Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD, + OpcAmlCheckForConstant, NULL, WalkState); + + /* + * Did we find an entire subtree that contains all constants and type 3/4/5 + * opcodes? (Only AE_OK or AE_TYPE returned from above) + */ + if (Status == AE_TYPE) + { + /* Subtree cannot be reduced to a constant */ + + if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL) + { + AcpiDsDeleteWalkState (WalkState); + return (AE_OK); + } + + /* Don't descend any further, and use a default "constant" value */ + + Status = AE_CTRL_DEPTH; + } + else + { + /* Subtree can be reduced */ + + /* Allocate a new temporary root for this subtree */ + + RootOp = TrAllocateNode (PARSEOP_INTEGER); + if (!RootOp) + { + return (AE_NO_MEMORY); + } + + RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP; + + OriginalParentOp = Op->Common.Parent; + Op->Common.Parent = RootOp; + + /* Hand off the subtree to the AML interpreter */ + + Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE, + OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState); + Op->Common.Parent = OriginalParentOp; + + /* TBD: we really *should* release the RootOp node */ + + if (ACPI_SUCCESS (Status)) + { + TotalFolds++; + + /* Get the final result */ + + Status = AcpiDsResultPop (&ObjDesc, WalkState); + } + } + + if (ACPI_FAILURE (Status)) + { + /* We could not resolve the subtree for some reason */ + + AslCoreSubsystemError (Op, Status, + "Failure during constant evaluation", FALSE); + AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op, + Op->Asl.ParseOpName); + + /* Set the subtree value to ZERO anyway. Eliminates further errors */ + + Op->Asl.ParseOpcode = PARSEOP_INTEGER; + Op->Common.Value.Integer = 0; + OpcSetOptimalIntegerSize (Op); + } + else + { + AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op, + Op->Asl.ParseOpName); + + /* + * Because we know we executed type 3/4/5 opcodes above, we know that + * the result must be either an Integer, String, or Buffer. + */ + switch (ObjDesc->Common.Type) + { + case ACPI_TYPE_INTEGER: + + Op->Asl.ParseOpcode = PARSEOP_INTEGER; + Op->Common.Value.Integer = ObjDesc->Integer.Value; + OpcSetOptimalIntegerSize (Op); + + DbgPrint (ASL_PARSE_OUTPUT, + "Constant expression reduced to (INTEGER) %8.8X%8.8X\n", + ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value)); + break; + + + case ACPI_TYPE_STRING: + + Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL; + Op->Common.AmlOpcode = AML_STRING_OP; + Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1; + Op->Common.Value.String = ObjDesc->String.Pointer; + + DbgPrint (ASL_PARSE_OUTPUT, + "Constant expression reduced to (STRING) %s\n", + Op->Common.Value.String); + + break; + + + case ACPI_TYPE_BUFFER: + + Op->Asl.ParseOpcode = PARSEOP_BUFFER; + Op->Common.AmlOpcode = AML_BUFFER_OP; + Op->Asl.CompileFlags = NODE_AML_PACKAGE; + UtSetParseOpName (Op); + + /* Child node is the buffer length */ + + RootOp = TrAllocateNode (PARSEOP_INTEGER); + + RootOp->Asl.AmlOpcode = AML_DWORD_OP; + RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length; + RootOp->Asl.Parent = Op; + + (void) OpcSetOptimalIntegerSize (RootOp); + + Op->Asl.Child = RootOp; + Op = RootOp; + UtSetParseOpName (Op); + + /* Peer to the child is the raw buffer data */ + + RootOp = TrAllocateNode (PARSEOP_RAW_DATA); + RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; + RootOp->Asl.AmlLength = ObjDesc->Buffer.Length; + RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer; + RootOp->Asl.Parent = Op->Asl.Parent; + + Op->Asl.Next = RootOp; + Op = RootOp; + + DbgPrint (ASL_PARSE_OUTPUT, + "Constant expression reduced to (BUFFER) length %X\n", + ObjDesc->Buffer.Length); + break; + + + default: + printf ("Unsupported return type: %s\n", + AcpiUtGetObjectTypeName (ObjDesc)); + break; + } + } + + UtSetParseOpName (Op); + Op->Asl.Child = NULL; + + AcpiDsDeleteWalkState (WalkState); + + return (AE_CTRL_DEPTH); +} + diff --git a/sys/contrib/dev/acpica/compiler/aslglobal.h b/sys/contrib/dev/acpica/compiler/aslglobal.h new file mode 100644 index 0000000..64cb76b --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslglobal.h @@ -0,0 +1,230 @@ + + +/****************************************************************************** + * + * Module Name: aslglobal.h - Global variable definitions + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#ifndef __ASLGLOBAL_H +#define __ASLGLOBAL_H + + +/* + * Global variables. Defined in aslmain.c only, externed in all other files + */ + +#undef ASL_EXTERN + +#ifdef _DECLARE_GLOBALS +#define ASL_EXTERN +#define ASL_INIT_GLOBAL(a,b) (a)=(b) +#else +#define ASL_EXTERN extern +#define ASL_INIT_GLOBAL(a,b) (a) +#endif + + +/* + * Parser and other externals + */ +extern int yydebug; +extern FILE *AslCompilerin; +extern int AslCompilerdebug; +extern int DtParserdebug; +extern int PrParserdebug; +extern const ASL_MAPPING_ENTRY AslKeywordMapping[]; +extern char *AslCompilertext; + +#define ASL_LINE_BUFFER_SIZE (4096 * 4) /* 16K */ +#define ASL_MSG_BUFFER_SIZE 4096 +#define HEX_TABLE_LINE_SIZE 8 +#define HEX_LISTING_LINE_SIZE 8 + + +/* Source code buffers and pointers for error reporting */ + +ASL_EXTERN char Gbl_CurrentLineBuffer[ASL_LINE_BUFFER_SIZE]; +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentColumn, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_PreviousLineNumber, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentLineNumber, 1); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_LogicalLineNumber, 1); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentLineOffset, 0); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_LineBufPtr, Gbl_CurrentLineBuffer); + +/* Exception reporting */ + +ASL_EXTERN ASL_ERROR_MSG ASL_INIT_GLOBAL (*Gbl_ErrorLog,NULL); +ASL_EXTERN ASL_ERROR_MSG ASL_INIT_GLOBAL (*Gbl_NextError,NULL); + +/* Option flags */ + +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DoCompile, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DoSignon, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_PreprocessOnly, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_PreprocessFlag, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DisassembleAll, FALSE); + +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_Acpi2, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_UseDefaultAmlFilename, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_NsOutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_PreprocessorOutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DebugFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_AsmOutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_C_OutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_AsmIncludeOutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_C_IncludeOutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_ListingFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_IgnoreErrors, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_SourceOutputFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_ParseOnlyFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_CompileTimesFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_FoldConstants, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_VerboseErrors, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_NoErrors, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_WarningsAsErrors, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_NoResourceChecking, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DisasmFlag, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_GetAllTables, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_IntegerOptimizationFlag, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_ReferenceOptimizationFlag, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DisplayRemarks, TRUE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DisplayOptimizations, FALSE); +ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_WarningLevel, ASL_WARNING); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_UseOriginalCompilerId, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_VerboseTemplates, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_DoTemplates, FALSE); +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_CompileGeneric, FALSE); + + +#define HEX_OUTPUT_NONE 0 +#define HEX_OUTPUT_C 1 +#define HEX_OUTPUT_ASM 2 +#define HEX_OUTPUT_ASL 3 + +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_HexOutputFlag, HEX_OUTPUT_NONE); + + +/* Files */ + +ASL_EXTERN ASL_FILE_INFO Gbl_Files [ASL_NUM_FILES]; + +ASL_EXTERN char *Gbl_DirectoryPath; +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_IncludeFilename, NULL); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_OutputFilenamePrefix, NULL); +ASL_EXTERN ASL_INCLUDE_DIR ASL_INIT_GLOBAL (*Gbl_IncludeDirList, NULL); +ASL_EXTERN char *Gbl_CurrentInputFilename; + +ASL_EXTERN BOOLEAN ASL_INIT_GLOBAL (Gbl_HasIncludeFiles, FALSE); + + +/* Statistics */ + +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_InputByteCount, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_InputFieldCount, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_NsLookupCount, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalKeywords, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalNamedObjects, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalExecutableOpcodes, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalParseNodes, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalMethods, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalAllocations, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalAllocated, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (TotalFolds, 0); + + +/* Misc */ + +ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_RevisionOverride, 0); +ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_TempCount, 0); +ASL_EXTERN ACPI_PARSE_OBJECT ASL_INIT_GLOBAL (*RootNode, NULL); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_TableLength, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_SourceLine, 0); +ASL_EXTERN ASL_LISTING_NODE ASL_INIT_GLOBAL (*Gbl_ListingNode, NULL); +ASL_EXTERN ACPI_PARSE_OBJECT ASL_INIT_GLOBAL (*Gbl_NodeCacheNext, NULL); +ASL_EXTERN ACPI_PARSE_OBJECT ASL_INIT_GLOBAL (*Gbl_NodeCacheLast, NULL); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_StringCacheNext, NULL); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_StringCacheLast, NULL); +ASL_EXTERN ACPI_PARSE_OBJECT *Gbl_FirstLevelInsertionNode; +ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_FileType, 0); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_Signature, NULL); +ASL_EXTERN char *Gbl_TemplateSignature; + +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentHexColumn, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentAmlOffset, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_CurrentLine, 0); +ASL_EXTERN UINT8 ASL_INIT_GLOBAL (Gbl_HexBytesWereWritten, FALSE); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_NumNamespaceObjects, 0); +ASL_EXTERN UINT32 ASL_INIT_GLOBAL (Gbl_ReservedMethods, 0); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_TableSignature, "NO_SIG"); +ASL_EXTERN char ASL_INIT_GLOBAL (*Gbl_TableId, "NO_ID"); +ASL_EXTERN FILE *AcpiGbl_DebugFile; /* Placeholder for oswinxf only */ + + +/* Static structures */ + +ASL_EXTERN ASL_ANALYSIS_WALK_INFO AnalysisWalkInfo; +ASL_EXTERN ACPI_TABLE_HEADER TableHeader; +extern char AslHexLookup[]; + +/* Event timing */ + +#define ASL_NUM_EVENTS 20 +ASL_EXTERN ASL_EVENT_INFO AslGbl_Events[ASL_NUM_EVENTS]; +ASL_EXTERN UINT8 AslGbl_NextEvent; +ASL_EXTERN UINT8 AslGbl_NamespaceEvent; + +/* Scratch buffers */ + +ASL_EXTERN UINT8 Gbl_AmlBuffer[HEX_LISTING_LINE_SIZE]; +ASL_EXTERN char MsgBuffer[ASL_MSG_BUFFER_SIZE]; +ASL_EXTERN char StringBuffer[ASL_MSG_BUFFER_SIZE]; +ASL_EXTERN char StringBuffer2[ASL_MSG_BUFFER_SIZE]; + + +#ifdef _DECLARE_GLOBALS +UINT32 Gbl_ExceptionCount[ASL_NUM_REPORT_LEVELS] = {0,0,0,0,0,0}; +#else +extern UINT32 Gbl_ExceptionCount[ASL_NUM_REPORT_LEVELS]; +#endif + +#endif /* __ASLGLOBAL_H */ + diff --git a/sys/contrib/dev/acpica/compiler/asllength.c b/sys/contrib/dev/acpica/compiler/asllength.c new file mode 100644 index 0000000..8dc21ac --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asllength.c @@ -0,0 +1,458 @@ + +/****************************************************************************** + * + * Module Name: asllength - Tree walk to determine package and opcode lengths + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("asllength") + +/* Local prototypes */ + +static UINT8 +CgGetPackageLenByteCount ( + ACPI_PARSE_OBJECT *Op, + UINT32 PackageLength); + +static void +CgGenerateAmlOpcodeLength ( + ACPI_PARSE_OBJECT *Op); + + +#ifdef ACPI_OBSOLETE_FUNCTIONS +void +LnAdjustLengthToRoot ( + ACPI_PARSE_OBJECT *Op, + UINT32 LengthDelta); +#endif + + +/******************************************************************************* + * + * FUNCTION: LnInitLengthsWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Walk callback to initialize (and re-initialize) the node + * subtree length(s) to zero. The Subtree lengths are bubbled + * up to the root node in order to get a total AML length. + * + ******************************************************************************/ + +ACPI_STATUS +LnInitLengthsWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + + Op->Asl.AmlSubtreeLength = 0; + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LnPackageLengthWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Walk callback to calculate the total AML length. + * 1) Calculate the AML lengths (opcode, package length, etc.) for + * THIS node. + * 2) Bubbble up all of these lengths to the parent node by summing + * them all into the parent subtree length. + * + * Note: The SubtreeLength represents the total AML length of all child nodes + * in all subtrees under a given node. Therefore, once this walk is + * complete, the Root Node subtree length is the AML length of the entire + * tree (and thus, the entire ACPI table) + * + ******************************************************************************/ + +ACPI_STATUS +LnPackageLengthWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + + /* Generate the AML lengths for this node */ + + CgGenerateAmlLengths (Op); + + /* Bubble up all lengths (this node and all below it) to the parent */ + + if ((Op->Asl.Parent) && + (Op->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)) + { + Op->Asl.Parent->Asl.AmlSubtreeLength += (Op->Asl.AmlLength + + Op->Asl.AmlOpcodeLength + + Op->Asl.AmlPkgLenBytes + + Op->Asl.AmlSubtreeLength); + } + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: CgGetPackageLenByteCount + * + * PARAMETERS: Op - Parse node + * PackageLength - Length to be encoded + * + * RETURN: Required length of the package length encoding + * + * DESCRIPTION: Calculate the number of bytes required to encode the given + * package length. + * + ******************************************************************************/ + +static UINT8 +CgGetPackageLenByteCount ( + ACPI_PARSE_OBJECT *Op, + UINT32 PackageLength) +{ + + /* + * Determine the number of bytes required to encode the package length + * Note: the package length includes the number of bytes used to encode + * the package length, so we must account for this also. + */ + if (PackageLength <= (0x0000003F - 1)) + { + return (1); + } + else if (PackageLength <= (0x00000FFF - 2)) + { + return (2); + } + else if (PackageLength <= (0x000FFFFF - 3)) + { + return (3); + } + else if (PackageLength <= (0x0FFFFFFF - 4)) + { + return (4); + } + else + { + /* Fatal error - the package length is too large to encode */ + + AslError (ASL_ERROR, ASL_MSG_ENCODING_LENGTH, Op, NULL); + } + + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: CgGenerateAmlOpcodeLength + * + * PARAMETERS: Op - Parse node whose AML opcode lengths will be + * calculated + * + * RETURN: None. + * + * DESCRIPTION: Calculate the AmlOpcodeLength, AmlPkgLenBytes, and AmlLength + * fields for this node. + * + ******************************************************************************/ + +static void +CgGenerateAmlOpcodeLength ( + ACPI_PARSE_OBJECT *Op) +{ + + /* Check for two-byte opcode */ + + if (Op->Asl.AmlOpcode > 0x00FF) + { + Op->Asl.AmlOpcodeLength = 2; + } + else + { + Op->Asl.AmlOpcodeLength = 1; + } + + /* Does this opcode have an associated "PackageLength" field? */ + + Op->Asl.AmlPkgLenBytes = 0; + if (Op->Asl.CompileFlags & NODE_AML_PACKAGE) + { + Op->Asl.AmlPkgLenBytes = CgGetPackageLenByteCount ( + Op, Op->Asl.AmlSubtreeLength); + } + + /* Data opcode lengths are easy */ + + switch (Op->Asl.AmlOpcode) + { + case AML_BYTE_OP: + + Op->Asl.AmlLength = 1; + break; + + case AML_WORD_OP: + + Op->Asl.AmlLength = 2; + break; + + case AML_DWORD_OP: + + Op->Asl.AmlLength = 4; + break; + + case AML_QWORD_OP: + + Op->Asl.AmlLength = 8; + break; + + default: + /* All data opcodes must be above */ + break; + } +} + + +/******************************************************************************* + * + * FUNCTION: CgGenerateAmlLengths + * + * PARAMETERS: Op - Parse node + * + * RETURN: None. + * + * DESCRIPTION: Generate internal length fields based on the AML opcode or + * parse opcode. + * + ******************************************************************************/ + +void +CgGenerateAmlLengths ( + ACPI_PARSE_OBJECT *Op) +{ + char *Buffer; + ACPI_STATUS Status; + + + switch (Op->Asl.AmlOpcode) + { + case AML_RAW_DATA_BYTE: + + Op->Asl.AmlOpcodeLength = 0; + Op->Asl.AmlLength = 1; + return; + + case AML_RAW_DATA_WORD: + + Op->Asl.AmlOpcodeLength = 0; + Op->Asl.AmlLength = 2; + return; + + case AML_RAW_DATA_DWORD: + + Op->Asl.AmlOpcodeLength = 0; + Op->Asl.AmlLength = 4; + return; + + case AML_RAW_DATA_QWORD: + + Op->Asl.AmlOpcodeLength = 0; + Op->Asl.AmlLength = 8; + return; + + case AML_RAW_DATA_BUFFER: + + /* Aml length is/was set by creator */ + + Op->Asl.AmlOpcodeLength = 0; + return; + + case AML_RAW_DATA_CHAIN: + + /* Aml length is/was set by creator */ + + Op->Asl.AmlOpcodeLength = 0; + return; + + default: + break; + } + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_DEFINITIONBLOCK: + + Gbl_TableLength = sizeof (ACPI_TABLE_HEADER) + + Op->Asl.AmlSubtreeLength; + break; + + case PARSEOP_NAMESEG: + + Op->Asl.AmlOpcodeLength = 0; + Op->Asl.AmlLength = 4; + Op->Asl.ExternalName = Op->Asl.Value.String; + break; + + case PARSEOP_NAMESTRING: + case PARSEOP_METHODCALL: + + if (Op->Asl.CompileFlags & NODE_NAME_INTERNALIZED) + { + break; + } + + Op->Asl.AmlOpcodeLength = 0; + Status = UtInternalizeName (Op->Asl.Value.String, &Buffer); + if (ACPI_FAILURE (Status)) + { + DbgPrint (ASL_DEBUG_OUTPUT, + "Failure from internalize name %X\n", Status); + break; + } + + Op->Asl.ExternalName = Op->Asl.Value.String; + Op->Asl.Value.String = Buffer; + Op->Asl.CompileFlags |= NODE_NAME_INTERNALIZED; + + Op->Asl.AmlLength = strlen (Buffer); + + /* + * Check for single backslash reference to root, + * make it a null terminated string in the AML + */ + if (Op->Asl.AmlLength == 1) + { + Op->Asl.AmlLength = 2; + } + break; + + case PARSEOP_STRING_LITERAL: + + Op->Asl.AmlOpcodeLength = 1; + + /* Get null terminator */ + + Op->Asl.AmlLength = strlen (Op->Asl.Value.String) + 1; + break; + + case PARSEOP_PACKAGE_LENGTH: + + Op->Asl.AmlOpcodeLength = 0; + Op->Asl.AmlPkgLenBytes = CgGetPackageLenByteCount (Op, + (UINT32) Op->Asl.Value.Integer); + break; + + case PARSEOP_RAW_DATA: + + Op->Asl.AmlOpcodeLength = 0; + break; + + case PARSEOP_DEFAULT_ARG: + case PARSEOP_EXTERNAL: + case PARSEOP_INCLUDE: + case PARSEOP_INCLUDE_END: + + /* Ignore the "default arg" nodes, they are extraneous at this point */ + + break; + + default: + + CgGenerateAmlOpcodeLength (Op); + break; + } +} + + +#ifdef ACPI_OBSOLETE_FUNCTIONS +/******************************************************************************* + * + * FUNCTION: LnAdjustLengthToRoot + * + * PARAMETERS: Op - Node whose Length was changed + * + * RETURN: None. + * + * DESCRIPTION: Change the Subtree length of the given node, and bubble the + * change all the way up to the root node. This allows for + * last second changes to a package length (for example, if the + * package length encoding gets shorter or longer.) + * + ******************************************************************************/ + +void +LnAdjustLengthToRoot ( + ACPI_PARSE_OBJECT *SubtreeOp, + UINT32 LengthDelta) +{ + ACPI_PARSE_OBJECT *Op; + + + /* Adjust all subtree lengths up to the root */ + + Op = SubtreeOp->Asl.Parent; + while (Op) + { + Op->Asl.AmlSubtreeLength -= LengthDelta; + Op = Op->Asl.Parent; + } + + /* Adjust the global table length */ + + Gbl_TableLength -= LengthDelta; +} +#endif + + diff --git a/sys/contrib/dev/acpica/compiler/asllisting.c b/sys/contrib/dev/acpica/compiler/asllisting.c new file mode 100644 index 0000000..106d330 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asllisting.c @@ -0,0 +1,1542 @@ + +/****************************************************************************** + * + * Module Name: asllisting - Listing file generation + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> +#include <contrib/dev/acpica/include/acparser.h> +#include <contrib/dev/acpica/include/acnamesp.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslisting") + +/* Local prototypes */ + +static void +LsDumpAscii ( + UINT32 FileId, + UINT32 Count, + UINT8 *Buffer); + +static void +LsDumpAsciiInComment ( + UINT32 FileId, + UINT32 Count, + UINT8 *Buffer); + +static ACPI_STATUS +LsAmlListingWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static void +LsGenerateListing ( + UINT32 FileId); + +static void +LsPushNode ( + char *Filename); + +static ASL_LISTING_NODE * +LsPopNode ( + void); + +static void +LsCheckException ( + UINT32 LineNumber, + UINT32 FileId); + +static void +LsFlushListingBuffer ( + UINT32 FileId); + +static void +LsWriteListingHexBytes ( + UINT8 *Buffer, + UINT32 Length, + UINT32 FileId); + +static UINT32 +LsWriteOneSourceLine ( + UINT32 FileId); + +static void +LsFinishSourceListing ( + UINT32 FileId); + +static void +LsWriteSourceLines ( + UINT32 ToLineNumber, + UINT32 ToLogicalLineNumber, + UINT32 FileId); + +static void +LsWriteNodeToListing ( + ACPI_PARSE_OBJECT *Op, + UINT32 FileId); + +static void +LsDoHexOutputC ( + void); + +static void +LsDoHexOutputAsm ( + void); + +static void +LsDoHexOutputAsl ( + void); + +static ACPI_STATUS +LsTreeWriteWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + + +/******************************************************************************* + * + * FUNCTION: LsTreeWriteWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * + * RETURN: None. + * + * DESCRIPTION: Dump entire parse tree, for compiler debug only + * + ******************************************************************************/ + +static ACPI_STATUS +LsTreeWriteWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + + /* Debug output */ + + DbgPrint (ASL_TREE_OUTPUT, + "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level); + UtPrintFormattedName (Op->Asl.ParseOpcode, Level); + + + DbgPrint (ASL_TREE_OUTPUT, "\n"); + return (AE_OK); +} + + +void +LsDumpParseTree ( + void) +{ + + if (!Gbl_DebugFlag) + { + return; + } + + DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n"); + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, + LsTreeWriteWalk, NULL, NULL); +} + + +/******************************************************************************* + * + * FUNCTION: LsDumpAscii + * + * PARAMETERS: FileId - ID of current listing file + * Count - Number of bytes to convert + * Buffer - Buffer of bytes to convert + * + * RETURN: None. + * + * DESCRIPTION: Convert hex bytes to ascii + * + ******************************************************************************/ + +static void +LsDumpAscii ( + UINT32 FileId, + UINT32 Count, + UINT8 *Buffer) +{ + UINT8 BufChar; + UINT32 i; + + + FlPrintFile (FileId, " \""); + for (i = 0; i < Count; i++) + { + BufChar = Buffer[i]; + if (isprint (BufChar)) + { + FlPrintFile (FileId, "%c", BufChar); + } + else + { + /* Not a printable character, just put out a dot */ + + FlPrintFile (FileId, "."); + } + } + FlPrintFile (FileId, "\""); +} + + +/******************************************************************************* + * + * FUNCTION: LsDumpAsciiInComment + * + * PARAMETERS: FileId - ID of current listing file + * Count - Number of bytes to convert + * Buffer - Buffer of bytes to convert + * + * RETURN: None. + * + * DESCRIPTION: Convert hex bytes to ascii + * + ******************************************************************************/ + +static void +LsDumpAsciiInComment ( + UINT32 FileId, + UINT32 Count, + UINT8 *Buffer) +{ + UINT8 BufChar = 0; + UINT8 LastChar; + UINT32 i; + + + FlPrintFile (FileId, " \""); + for (i = 0; i < Count; i++) + { + LastChar = BufChar; + BufChar = Buffer[i]; + + if (isprint (BufChar)) + { + /* Handle embedded C comment sequences */ + + if (((LastChar == '*') && (BufChar == '/')) || + ((LastChar == '/') && (BufChar == '*'))) + { + /* Insert a space to break the sequence */ + + FlPrintFile (FileId, ".", BufChar); + } + + FlPrintFile (FileId, "%c", BufChar); + } + else + { + /* Not a printable character, just put out a dot */ + + FlPrintFile (FileId, "."); + } + } + FlPrintFile (FileId, "\""); +} + + +/******************************************************************************* + * + * FUNCTION: LsAmlListingWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Process one node during a listing file generation. + * + ******************************************************************************/ + +static ACPI_STATUS +LsAmlListingWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + UINT8 FileByte; + UINT32 i; + UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context); + + + LsWriteNodeToListing (Op, FileId); + + if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA) + { + /* Buffer is a resource template, don't dump the data all at once */ + + return (AE_OK); + } + + /* Write the hex bytes to the listing file(s) (if requested) */ + + for (i = 0; i < Op->Asl.FinalAmlLength; i++) + { + if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1))) + { + FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ); + AslAbort (); + } + LsWriteListingHexBytes (&FileByte, 1, FileId); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LsGenerateListing + * + * PARAMETERS: FileId - ID of listing file + * + * RETURN: None + * + * DESCRIPTION: Generate a listing file. This can be one of the several types + * of "listings" supported. + * + ******************************************************************************/ + +static void +LsGenerateListing ( + UINT32 FileId) +{ + + /* Start at the beginning of both the source and AML files */ + + FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0); + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + Gbl_SourceLine = 0; + Gbl_CurrentHexColumn = 0; + LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename); + + /* Process all parse nodes */ + + TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk, + NULL, (void *) ACPI_TO_POINTER (FileId)); + + /* Final processing */ + + LsFinishSourceListing (FileId); +} + + +/******************************************************************************* + * + * FUNCTION: LsDoListings + * + * PARAMETERS: None. + * + * RETURN: None + * + * DESCRIPTION: Generate all requested listing files. + * + ******************************************************************************/ + +void +LsDoListings ( + void) +{ + + if (Gbl_C_OutputFlag) + { + LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT); + } + + if (Gbl_ListingFlag) + { + LsGenerateListing (ASL_FILE_LISTING_OUTPUT); + } + + if (Gbl_AsmOutputFlag) + { + LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT); + } + + if (Gbl_C_IncludeOutputFlag) + { + LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT); + } + + if (Gbl_AsmIncludeOutputFlag) + { + LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT); + } +} + + +/******************************************************************************* + * + * FUNCTION: LsPushNode + * + * PARAMETERS: Filename - Pointer to the include filename + * + * RETURN: None + * + * DESCRIPTION: Push a listing node on the listing/include file stack. This + * stack enables tracking of include files (infinitely nested) + * and resumption of the listing of the parent file when the + * include file is finished. + * + ******************************************************************************/ + +static void +LsPushNode ( + char *Filename) +{ + ASL_LISTING_NODE *Lnode; + + + /* Create a new node */ + + Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE)); + + /* Initialize */ + + Lnode->Filename = Filename; + Lnode->LineNumber = 0; + + /* Link (push) */ + + Lnode->Next = Gbl_ListingNode; + Gbl_ListingNode = Lnode; +} + + +/******************************************************************************* + * + * FUNCTION: LsPopNode + * + * PARAMETERS: None + * + * RETURN: List head after current head is popped off + * + * DESCRIPTION: Pop the current head of the list, free it, and return the + * next node on the stack (the new current node). + * + ******************************************************************************/ + +static ASL_LISTING_NODE * +LsPopNode ( + void) +{ + ASL_LISTING_NODE *Lnode; + + + /* Just grab the node at the head of the list */ + + Lnode = Gbl_ListingNode; + if ((!Lnode) || + (!Lnode->Next)) + { + AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL, + "Could not pop empty listing stack"); + return Gbl_ListingNode; + } + + Gbl_ListingNode = Lnode->Next; + ACPI_FREE (Lnode); + + /* New "Current" node is the new head */ + + return (Gbl_ListingNode); +} + + +/******************************************************************************* + * + * FUNCTION: LsCheckException + * + * PARAMETERS: LineNumber - Current logical (cumulative) line # + * FileId - ID of output listing file + * + * RETURN: None + * + * DESCRIPTION: Check if there is an exception for this line, and if there is, + * put it in the listing immediately. Handles multiple errors + * per line. Gbl_NextError points to the next error in the + * sorted (by line #) list of compile errors/warnings. + * + ******************************************************************************/ + +static void +LsCheckException ( + UINT32 LineNumber, + UINT32 FileId) +{ + + if ((!Gbl_NextError) || + (LineNumber < Gbl_NextError->LogicalLineNumber )) + { + return; + } + + /* Handle multiple errors per line */ + + if (FileId == ASL_FILE_LISTING_OUTPUT) + { + while (Gbl_NextError && + (LineNumber >= Gbl_NextError->LogicalLineNumber)) + { + AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n"); + + Gbl_NextError = Gbl_NextError->Next; + } + + FlPrintFile (FileId, "\n"); + } +} + + +/******************************************************************************* + * + * FUNCTION: LsFlushListingBuffer + * + * PARAMETERS: FileId - ID of the listing file + * + * RETURN: None + * + * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code + * buffer. Usually called at the termination of a single line + * of source code or when the buffer is full. + * + ******************************************************************************/ + +static void +LsFlushListingBuffer ( + UINT32 FileId) +{ + UINT32 i; + + + if (Gbl_CurrentHexColumn == 0) + { + return; + } + + /* Write the hex bytes */ + + switch (FileId) + { + case ASL_FILE_LISTING_OUTPUT: + + for (i = 0; i < Gbl_CurrentHexColumn; i++) + { + FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]); + } + + for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++) + { + FlWriteFile (FileId, ".", 1); + } + + /* Write the ASCII character associated with each of the bytes */ + + LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); + break; + + + case ASL_FILE_ASM_SOURCE_OUTPUT: + + for (i = 0; i < Gbl_CurrentHexColumn; i++) + { + if (i > 0) + { + FlPrintFile (FileId, ","); + } + FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]); + } + + for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) + { + FlWriteFile (FileId, " ", 1); + } + + FlPrintFile (FileId, " ;%8.8X", + Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); + + /* Write the ASCII character associated with each of the bytes */ + + LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); + break; + + + case ASL_FILE_C_SOURCE_OUTPUT: + + for (i = 0; i < Gbl_CurrentHexColumn; i++) + { + FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]); + } + + for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++) + { + FlWriteFile (FileId, " ", 1); + } + + FlPrintFile (FileId, " /* %8.8X", + Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE); + + /* Write the ASCII character associated with each of the bytes */ + + LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer); + FlPrintFile (FileId, " */"); + break; + + default: + /* No other types supported */ + return; + } + + FlPrintFile (FileId, "\n"); + + Gbl_CurrentHexColumn = 0; + Gbl_HexBytesWereWritten = TRUE; +} + + +/******************************************************************************* + * + * FUNCTION: LsWriteListingHexBytes + * + * PARAMETERS: Buffer - AML code buffer + * Length - Number of AML bytes to write + * FileId - ID of current listing file. + * + * RETURN: None + * + * DESCRIPTION: Write the contents of the AML buffer to the listing file via + * the listing buffer. The listing buffer is flushed every 16 + * AML bytes. + * + ******************************************************************************/ + +static void +LsWriteListingHexBytes ( + UINT8 *Buffer, + UINT32 Length, + UINT32 FileId) +{ + UINT32 i; + + + /* Transfer all requested bytes */ + + for (i = 0; i < Length; i++) + { + /* Print line header when buffer is empty */ + + if (Gbl_CurrentHexColumn == 0) + { + if (Gbl_HasIncludeFiles) + { + FlPrintFile (FileId, "%*s", 10, " "); + } + + switch (FileId) + { + case ASL_FILE_LISTING_OUTPUT: + + FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset); + break; + + case ASL_FILE_ASM_SOURCE_OUTPUT: + + FlPrintFile (FileId, " db "); + break; + + case ASL_FILE_C_SOURCE_OUTPUT: + + FlPrintFile (FileId, " "); + break; + + default: + /* No other types supported */ + return; + } + } + + /* Transfer AML byte and update counts */ + + Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i]; + + Gbl_CurrentHexColumn++; + Gbl_CurrentAmlOffset++; + + /* Flush buffer when it is full */ + + if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE) + { + LsFlushListingBuffer (FileId); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: LsWriteOneSourceLine + * + * PARAMETERS: FileID - ID of current listing file + * + * RETURN: FALSE on EOF (input source file), TRUE otherwise + * + * DESCRIPTION: Read one line from the input source file and echo it to the + * listing file, prefixed with the line number, and if the source + * file contains include files, prefixed with the current filename + * + ******************************************************************************/ + +static UINT32 +LsWriteOneSourceLine ( + UINT32 FileId) +{ + UINT8 FileByte; + + + Gbl_SourceLine++; + Gbl_ListingNode->LineNumber++; + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " *"); + } + if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) + { + FlPrintFile (FileId, "; "); + } + + if (Gbl_HasIncludeFiles) + { + /* + * This file contains "include" statements, print the current + * filename and line number within the current file + */ + FlPrintFile (FileId, "%12s %5d....", + Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber); + } + else + { + /* No include files, just print the line number */ + + FlPrintFile (FileId, "%8d....", Gbl_SourceLine); + } + + /* Read one line (up to a newline or EOF) */ + + while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK) + { + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + if (FileByte == '/') + { + FileByte = '*'; + } + } + + FlWriteFile (FileId, &FileByte, 1); + if (FileByte == '\n') + { + /* + * Check if an error occurred on this source line during the compile. + * If so, we print the error message after the source line. + */ + LsCheckException (Gbl_SourceLine, FileId); + return (1); + } + } + + /* EOF on the input file was reached */ + + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: LsFinishSourceListing + * + * PARAMETERS: FileId - ID of current listing file. + * + * RETURN: None + * + * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML + * listing buffer, and flush out any remaining lines in the + * source input file. + * + ******************************************************************************/ + +static void +LsFinishSourceListing ( + UINT32 FileId) +{ + + if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || + (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) + { + return; + } + + LsFlushListingBuffer (FileId); + Gbl_CurrentAmlOffset = 0; + + /* Flush any remaining text in the source file */ + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " /*\n"); + } + + while (LsWriteOneSourceLine (FileId)) + { ; } + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, "\n */\n };\n"); + } + + FlPrintFile (FileId, "\n"); + + if (FileId == ASL_FILE_LISTING_OUTPUT) + { + /* Print a summary of the compile exceptions */ + + FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n"); + AePrintErrorLog (FileId); + FlPrintFile (FileId, "\n"); + UtDisplaySummary (FileId); + FlPrintFile (FileId, "\n"); + } +} + + +/******************************************************************************* + * + * FUNCTION: LsWriteSourceLines + * + * PARAMETERS: ToLineNumber - + * ToLogicalLineNumber - Write up to this source line number + * FileId - ID of current listing file + * + * RETURN: None + * + * DESCRIPTION: Read then write source lines to the listing file until we have + * reached the specified logical (cumulative) line number. This + * automatically echos out comment blocks and other non-AML + * generating text until we get to the actual AML-generating line + * of ASL code specified by the logical line number. + * + ******************************************************************************/ + +static void +LsWriteSourceLines ( + UINT32 ToLineNumber, + UINT32 ToLogicalLineNumber, + UINT32 FileId) +{ + + if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) || + (FileId == ASL_FILE_C_INCLUDE_OUTPUT)) + { + return; + } + + Gbl_CurrentLine = ToLogicalLineNumber; + + /* Flush any hex bytes remaining from the last opcode */ + + LsFlushListingBuffer (FileId); + + /* Read lines and write them as long as we are not caught up */ + + if (Gbl_SourceLine < Gbl_CurrentLine) + { + /* + * If we just completed writing some AML hex bytes, output a linefeed + * to add some whitespace for readability. + */ + if (Gbl_HexBytesWereWritten) + { + FlPrintFile (FileId, "\n"); + Gbl_HexBytesWereWritten = FALSE; + } + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " /*\n"); + } + + /* Write one line at a time until we have reached the target line # */ + + while ((Gbl_SourceLine < Gbl_CurrentLine) && + LsWriteOneSourceLine (FileId)) + { ; } + + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, " */"); + } + FlPrintFile (FileId, "\n"); + } +} + + +/******************************************************************************* + * + * FUNCTION: LsWriteNodeToListing + * + * PARAMETERS: Op - Parse node to write to the listing file. + * FileId - ID of current listing file + * + * RETURN: None. + * + * DESCRIPTION: Write "a node" to the listing file. This means to + * 1) Write out all of the source text associated with the node + * 2) Write out all of the AML bytes associated with the node + * 3) Write any compiler exceptions associated with the node + * + ******************************************************************************/ + +static void +LsWriteNodeToListing ( + ACPI_PARSE_OBJECT *Op, + UINT32 FileId) +{ + const ACPI_OPCODE_INFO *OpInfo; + UINT32 OpClass; + char *Pathname; + UINT32 Length; + UINT32 i; + + + OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); + OpClass = OpInfo->Class; + + /* TBD: clean this up with a single flag that says: + * I start a named output block + */ + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_DEFINITIONBLOCK: + case PARSEOP_METHODCALL: + case PARSEOP_INCLUDE: + case PARSEOP_INCLUDE_END: + case PARSEOP_DEFAULT_ARG: + + break; + + default: + switch (OpClass) + { + case AML_CLASS_NAMED_OBJECT: + switch (Op->Asl.AmlOpcode) + { + case AML_SCOPE_OP: + case AML_ALIAS_OP: + break; + + default: + if (Op->Asl.ExternalName) + { + LsFlushListingBuffer (FileId); + FlPrintFile (FileId, " };\n"); + } + break; + } + break; + + default: + /* Don't care about other objects */ + break; + } + break; + } + } + + /* These cases do not have a corresponding AML opcode */ + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_DEFINITIONBLOCK: + + LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId); + + /* Use the table Signature and TableId to build a unique name */ + + if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) + { + FlPrintFile (FileId, + "%s_%s_Header \\\n", + Gbl_TableSignature, Gbl_TableId); + } + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, + " unsigned char %s_%s_Header [] =\n {\n", + Gbl_TableSignature, Gbl_TableId); + } + if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) + { + FlPrintFile (FileId, + "extrn %s_%s_Header : byte\n", + Gbl_TableSignature, Gbl_TableId); + } + if (FileId == ASL_FILE_C_INCLUDE_OUTPUT) + { + FlPrintFile (FileId, + "extern unsigned char %s_%s_Header [];\n", + Gbl_TableSignature, Gbl_TableId); + } + return; + + + case PARSEOP_METHODCALL: + + LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, + FileId); + return; + + + case PARSEOP_INCLUDE: + + /* Flush everything up to and including the include source line */ + + LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, + FileId); + + /* Create a new listing node and push it */ + + LsPushNode (Op->Asl.Child->Asl.Value.String); + return; + + + case PARSEOP_INCLUDE_END: + + /* Flush out the rest of the include file */ + + LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, + FileId); + + /* Pop off this listing node and go back to the parent file */ + + (void) LsPopNode (); + return; + + + case PARSEOP_DEFAULT_ARG: + + if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) + { + LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine, + FileId); + } + return; + + + default: + /* All other opcodes have an AML opcode */ + break; + } + + /* + * Otherwise, we look at the AML opcode because we can + * switch on the opcode type, getting an entire class + * at once + */ + switch (OpClass) + { + case AML_CLASS_ARGUMENT: /* argument type only */ + case AML_CLASS_INTERNAL: + + break; + + + case AML_CLASS_NAMED_OBJECT: + + switch (Op->Asl.AmlOpcode) + { + case AML_FIELD_OP: + case AML_INDEX_FIELD_OP: + case AML_BANK_FIELD_OP: + + /* + * For fields, we want to dump all the AML after the + * entire definition + */ + LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, + FileId); + break; + + case AML_NAME_OP: + + if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) + { + LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, + FileId); + } + else + { + /* + * For fields, we want to dump all the AML after the + * entire definition + */ + LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, + FileId); + } + break; + + default: + LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, + FileId); + break; + } + + switch (Op->Asl.AmlOpcode) + { + case AML_SCOPE_OP: + case AML_ALIAS_OP: + + /* These opcodes do not declare a new object, ignore them */ + + break; + + default: + + /* All other named object opcodes come here */ + + switch (FileId) + { + case ASL_FILE_ASM_SOURCE_OUTPUT: + case ASL_FILE_C_SOURCE_OUTPUT: + case ASL_FILE_ASM_INCLUDE_OUTPUT: + case ASL_FILE_C_INCLUDE_OUTPUT: + + /* + * For named objects, we will create a valid symbol so that the + * AML code can be referenced from C or ASM + */ + if (Op->Asl.ExternalName) + { + /* Get the full pathname associated with this node */ + + Pathname = AcpiNsGetExternalPathname (Op->Asl.Node); + Length = strlen (Pathname); + if (Length >= 4) + { + /* Convert all dots in the path to underscores */ + + for (i = 0; i < Length; i++) + { + if (Pathname[i] == '.') + { + Pathname[i] = '_'; + } + } + + /* Create the appropriate symbol in the output file */ + + if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT) + { + FlPrintFile (FileId, + "%s_%s_%s \\\n", + Gbl_TableSignature, Gbl_TableId, &Pathname[1]); + } + if (FileId == ASL_FILE_C_SOURCE_OUTPUT) + { + FlPrintFile (FileId, + " unsigned char %s_%s_%s [] =\n {\n", + Gbl_TableSignature, Gbl_TableId, &Pathname[1]); + } + if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) + { + FlPrintFile (FileId, + "extrn %s_%s_%s : byte\n", + Gbl_TableSignature, Gbl_TableId, &Pathname[1]); + } + if (FileId == ASL_FILE_C_INCLUDE_OUTPUT) + { + FlPrintFile (FileId, + "extern unsigned char %s_%s_%s [];\n", + Gbl_TableSignature, Gbl_TableId, &Pathname[1]); + } + } + ACPI_FREE (Pathname); + } + break; + + default: + /* Nothing to do for listing file */ + break; + } + } + break; + + case AML_CLASS_EXECUTE: + case AML_CLASS_CREATE: + default: + + if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) && + (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)) + { + return; + } + + LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber, + FileId); + break; + + case AML_CLASS_UNKNOWN: + break; + } +} + + +/******************************************************************************* + * + * FUNCTION: LsDoHexOutput + * + * PARAMETERS: None + * + * RETURN: None. + * + * DESCRIPTION: Create the hex output file. + * + ******************************************************************************/ + +void +LsDoHexOutput ( + void) +{ + + switch (Gbl_HexOutputFlag) + { + case HEX_OUTPUT_C: + + LsDoHexOutputC (); + break; + + case HEX_OUTPUT_ASM: + + LsDoHexOutputAsm (); + break; + + case HEX_OUTPUT_ASL: + + LsDoHexOutputAsl (); + break; + + default: + /* No other output types supported */ + break; + } +} + + +/******************************************************************************* + * + * FUNCTION: LsDoHexOutputC + * + * PARAMETERS: None + * + * RETURN: None. + * + * DESCRIPTION: Create the hex output file. This is the same data as the AML + * output file, but formatted into hex/ascii bytes suitable for + * inclusion into a C source file. + * + ******************************************************************************/ + +static void +LsDoHexOutputC ( + void) +{ + UINT8 FileData[HEX_TABLE_LINE_SIZE]; + UINT32 LineLength; + UINT32 Offset = 0; + UINT32 AmlFileSize; + UINT32 i; + + + /* Get AML size, seek back to start */ + + AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT); + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n"); + FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n", + AmlFileSize); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n"); + + while (Offset < AmlFileSize) + { + /* Read enough bytes needed for one output line */ + + LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE, + Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); + if (!LineLength) + { + break; + } + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); + + for (i = 0; i < LineLength; i++) + { + /* + * Print each hex byte. + * Add a comma until the very last byte of the AML file + * (Some C compilers complain about a trailing comma) + */ + FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]); + if ((Offset + i + 1) < AmlFileSize) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); + } + else + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); + } + } + + /* Add fill spaces if needed for last line */ + + if (LineLength < HEX_TABLE_LINE_SIZE) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s", + 5 * (HEX_TABLE_LINE_SIZE - LineLength), " "); + } + + /* Emit the offset and ascii dump for the entire line */ + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset); + LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n", + HEX_TABLE_LINE_SIZE - LineLength + 1, " "); + + Offset += LineLength; + } + + FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n"); +} + + +/******************************************************************************* + * + * FUNCTION: LsDoHexOutputAsl + * + * PARAMETERS: None + * + * RETURN: None. + * + * DESCRIPTION: Create the hex output file. This is the same data as the AML + * output file, but formatted into hex/ascii bytes suitable for + * inclusion into a C source file. + * + ******************************************************************************/ + +static void +LsDoHexOutputAsl ( + void) +{ + UINT8 FileData[HEX_TABLE_LINE_SIZE]; + UINT32 LineLength; + UINT32 Offset = 0; + UINT32 AmlFileSize; + UINT32 i; + + + /* Get AML size, seek back to start */ + + AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT); + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n"); + FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n", + AmlFileSize); + FlPrintFile (ASL_FILE_HEX_OUTPUT, " Name (BUF1, Buffer()\n {\n"); + + while (Offset < AmlFileSize) + { + /* Read enough bytes needed for one output line */ + + LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE, + Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); + if (!LineLength) + { + break; + } + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); + + for (i = 0; i < LineLength; i++) + { + /* + * Print each hex byte. + * Add a comma until the very last byte of the AML file + * (Some C compilers complain about a trailing comma) + */ + FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]); + if ((Offset + i + 1) < AmlFileSize) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); + } + else + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); + } + } + + /* Add fill spaces if needed for last line */ + + if (LineLength < HEX_TABLE_LINE_SIZE) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s", + 5 * (HEX_TABLE_LINE_SIZE - LineLength), " "); + } + + /* Emit the offset and ascii dump for the entire line */ + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset); + LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n", + HEX_TABLE_LINE_SIZE - LineLength + 1, " "); + + Offset += LineLength; + } + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n"); +} + + +/******************************************************************************* + * + * FUNCTION: LsDoHexOutputAsm + * + * PARAMETERS: None + * + * RETURN: None. + * + * DESCRIPTION: Create the hex output file. This is the same data as the AML + * output file, but formatted into hex/ascii bytes suitable for + * inclusion into a ASM source file. + * + ******************************************************************************/ + +static void +LsDoHexOutputAsm ( + void) +{ + UINT8 FileData[HEX_TABLE_LINE_SIZE]; + UINT32 LineLength; + UINT32 Offset = 0; + UINT32 AmlFileSize; + UINT32 i; + + + /* Get AML size, seek back to start */ + + AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT); + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + + FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n"); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n", + AmlFileSize); + + while (Offset < AmlFileSize) + { + /* Read enough bytes needed for one output line */ + + LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE, + Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); + if (!LineLength) + { + break; + } + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " db "); + + for (i = 0; i < LineLength; i++) + { + /* + * Print each hex byte. + * Add a comma until the last byte of the line + */ + FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]); + if ((i + 1) < LineLength) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, ","); + } + } + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " "); + + /* Add fill spaces if needed for last line */ + + if (LineLength < HEX_TABLE_LINE_SIZE) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s", + 5 * (HEX_TABLE_LINE_SIZE - LineLength), " "); + } + + /* Emit the offset and ascii dump for the entire line */ + + FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset); + LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); + + Offset += LineLength; + } + + FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n"); +} + + diff --git a/sys/contrib/dev/acpica/compiler/aslload.c b/sys/contrib/dev/acpica/compiler/aslload.c new file mode 100644 index 0000000..6198fb8 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslload.c @@ -0,0 +1,898 @@ +/****************************************************************************** + * + * Module Name: dswload - Dispatcher namespace load callbacks + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __ASLLOAD_C__ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/include/amlcode.h> +#include <contrib/dev/acpica/include/acdispat.h> +#include <contrib/dev/acpica/include/acnamesp.h> + +#include "aslcompiler.y.h" + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslload") + +/* Local prototypes */ + +static ACPI_STATUS +LdLoadFieldElements ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState); + +static ACPI_STATUS +LdLoadResourceElements ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState); + +static ACPI_STATUS +LdNamespace1Begin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static ACPI_STATUS +LdNamespace2Begin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static ACPI_STATUS +LdCommonNamespaceEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + + +/******************************************************************************* + * + * FUNCTION: LdLoadNamespace + * + * PARAMETERS: RootOp - Root of the parse tree + * + * RETURN: Status + * + * DESCRIPTION: Perform a walk of the parse tree that in turn loads all of the + * named ASL/AML objects into the namespace. The namespace is + * constructed in order to resolve named references and references + * to named fields within resource templates/descriptors. + * + ******************************************************************************/ + +ACPI_STATUS +LdLoadNamespace ( + ACPI_PARSE_OBJECT *RootOp) +{ + ACPI_WALK_STATE *WalkState; + + + DbgPrint (ASL_DEBUG_OUTPUT, "\nCreating namespace\n\n"); + + /* Create a new walk state */ + + WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); + if (!WalkState) + { + return AE_NO_MEMORY; + } + + /* Walk the entire parse tree, first pass */ + + TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace1Begin, + LdCommonNamespaceEnd, WalkState); + + /* Second pass to handle forward references */ + + TrWalkParseTree (RootOp, ASL_WALK_VISIT_TWICE, LdNamespace2Begin, + LdCommonNamespaceEnd, WalkState); + + /* Dump the namespace if debug is enabled */ + + AcpiNsDumpTables (ACPI_NS_ALL, ACPI_UINT32_MAX); + return AE_OK; +} + + +/******************************************************************************* + * + * FUNCTION: LdLoadFieldElements + * + * PARAMETERS: Op - Parent node (Field) + * WalkState - Current walk state + * + * RETURN: Status + * + * DESCRIPTION: Enter the named elements of the field (children of the parent) + * into the namespace. + * + ******************************************************************************/ + +static ACPI_STATUS +LdLoadFieldElements ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState) +{ + ACPI_PARSE_OBJECT *Child = NULL; + ACPI_NAMESPACE_NODE *Node; + ACPI_STATUS Status; + + + /* Get the first named field element */ + + switch (Op->Asl.AmlOpcode) + { + case AML_BANK_FIELD_OP: + + Child = UtGetArg (Op, 6); + break; + + case AML_INDEX_FIELD_OP: + + Child = UtGetArg (Op, 5); + break; + + case AML_FIELD_OP: + + Child = UtGetArg (Op, 4); + break; + + default: + /* No other opcodes should arrive here */ + return (AE_BAD_PARAMETER); + } + + /* Enter all elements into the namespace */ + + while (Child) + { + switch (Child->Asl.AmlOpcode) + { + case AML_INT_RESERVEDFIELD_OP: + case AML_INT_ACCESSFIELD_OP: + case AML_INT_CONNECTION_OP: + break; + + default: + + Status = AcpiNsLookup (WalkState->ScopeInfo, + Child->Asl.Value.String, + ACPI_TYPE_LOCAL_REGION_FIELD, + ACPI_IMODE_LOAD_PASS1, + ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | + ACPI_NS_ERROR_IF_FOUND, + NULL, &Node); + if (ACPI_FAILURE (Status)) + { + if (Status != AE_ALREADY_EXISTS) + { + AslError (ASL_ERROR, ASL_MSG_CORE_EXCEPTION, Child, + Child->Asl.Value.String); + return (Status); + } + + /* + * The name already exists in this scope + * But continue processing the elements + */ + AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Child, + Child->Asl.Value.String); + } + else + { + Child->Asl.Node = Node; + Node->Op = Child; + } + break; + } + + Child = Child->Asl.Next; + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LdLoadResourceElements + * + * PARAMETERS: Op - Parent node (Resource Descriptor) + * WalkState - Current walk state + * + * RETURN: Status + * + * DESCRIPTION: Enter the named elements of the resource descriptor (children + * of the parent) into the namespace. + * + * NOTE: In the real AML namespace, these named elements never exist. But + * we simply use the namespace here as a symbol table so we can look + * them up as they are referenced. + * + ******************************************************************************/ + +static ACPI_STATUS +LdLoadResourceElements ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState) +{ + ACPI_PARSE_OBJECT *InitializerOp = NULL; + ACPI_NAMESPACE_NODE *Node; + ACPI_STATUS Status; + + + /* + * Enter the resource name into the namespace. Name must not already exist. + * This opens a scope, so later field names are guaranteed to be new/unique. + */ + Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Asl.Namepath, + ACPI_TYPE_LOCAL_RESOURCE, ACPI_IMODE_LOAD_PASS1, + ACPI_NS_NO_UPSEARCH | ACPI_NS_ERROR_IF_FOUND, + WalkState, &Node); + if (ACPI_FAILURE (Status)) + { + if (Status == AE_ALREADY_EXISTS) + { + /* Actual node causing the error was saved in ParentMethod */ + + AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, + (ACPI_PARSE_OBJECT *) Op->Asl.ParentMethod, Op->Asl.Namepath); + return (AE_OK); + } + return (Status); + } + + Node->Value = (UINT32) Op->Asl.Value.Integer; + Node->Op = Op; + Op->Asl.Node = Node; + + /* + * Now enter the predefined fields, for easy lookup when referenced + * by the source ASL + */ + InitializerOp = ASL_GET_CHILD_NODE (Op); + while (InitializerOp) + { + if (InitializerOp->Asl.ExternalName) + { + Status = AcpiNsLookup (WalkState->ScopeInfo, + InitializerOp->Asl.ExternalName, + ACPI_TYPE_LOCAL_RESOURCE_FIELD, + ACPI_IMODE_LOAD_PASS1, + ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE, + NULL, &Node); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* + * Store the field offset and length in the namespace node + * so it can be used when the field is referenced + */ + Node->Value = InitializerOp->Asl.Value.Tag.BitOffset; + Node->Length = InitializerOp->Asl.Value.Tag.BitLength; + InitializerOp->Asl.Node = Node; + Node->Op = InitializerOp; + } + + InitializerOp = ASL_GET_PEER_NODE (InitializerOp); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LdNamespace1Begin + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Descending callback used during the parse tree walk. If this + * is a named AML opcode, enter into the namespace + * + ******************************************************************************/ + +static ACPI_STATUS +LdNamespace1Begin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; + ACPI_NAMESPACE_NODE *Node; + ACPI_STATUS Status; + ACPI_OBJECT_TYPE ObjectType; + ACPI_OBJECT_TYPE ActualObjectType = ACPI_TYPE_ANY; + char *Path; + UINT32 Flags = ACPI_NS_NO_UPSEARCH; + ACPI_PARSE_OBJECT *Arg; + UINT32 i; + BOOLEAN ForceNewScope = FALSE; + + + ACPI_FUNCTION_NAME (LdNamespace1Begin); + ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n", + Op, Op->Asl.ParseOpName)); + + + /* + * We are only interested in opcodes that have an associated name + * (or multiple names) + */ + switch (Op->Asl.AmlOpcode) + { + case AML_BANK_FIELD_OP: + case AML_INDEX_FIELD_OP: + case AML_FIELD_OP: + + Status = LdLoadFieldElements (Op, WalkState); + return (Status); + + default: + + /* All other opcodes go below */ + break; + } + + /* Check if this object has already been installed in the namespace */ + + if (Op->Asl.Node) + { + return (AE_OK); + } + + Path = Op->Asl.Namepath; + if (!Path) + { + return (AE_OK); + } + + /* Map the raw opcode into an internal object type */ + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_NAME: + + Arg = Op->Asl.Child; /* Get the NameSeg/NameString node */ + Arg = Arg->Asl.Next; /* First peer is the object to be associated with the name */ + + /* + * If this name refers to a ResourceTemplate, we will need to open + * a new scope so that the resource subfield names can be entered into + * the namespace underneath this name + */ + if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) + { + ForceNewScope = TRUE; + } + + /* Get the data type associated with the named object, not the name itself */ + + /* Log2 loop to convert from Btype (binary) to Etype (encoded) */ + + ObjectType = 1; + for (i = 1; i < Arg->Asl.AcpiBtype; i *= 2) + { + ObjectType++; + } + break; + + + case PARSEOP_EXTERNAL: + + /* + * "External" simply enters a name and type into the namespace. + * We must be careful to not open a new scope, however, no matter + * what type the external name refers to (e.g., a method) + * + * first child is name, next child is ObjectType + */ + ActualObjectType = (UINT8) Op->Asl.Child->Asl.Next->Asl.Value.Integer; + ObjectType = ACPI_TYPE_ANY; + + /* + * We will mark every new node along the path as "External". This + * allows some or all of the nodes to be created later in the ASL + * code. Handles cases like this: + * + * External (\_SB_.PCI0.ABCD, IntObj) + * Scope (_SB_) + * { + * Device (PCI0) + * { + * } + * } + * Method (X) + * { + * Store (\_SB_.PCI0.ABCD, Local0) + * } + */ + Flags |= ACPI_NS_EXTERNAL; + break; + + case PARSEOP_DEFAULT_ARG: + + if (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC) + { + Status = LdLoadResourceElements (Op, WalkState); + return_ACPI_STATUS (Status); + } + + ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); + break; + + + case PARSEOP_SCOPE: + + /* + * The name referenced by Scope(Name) must already exist at this point. + * In other words, forward references for Scope() are not supported. + * The only real reason for this is that the MS interpreter cannot + * handle this case. Perhaps someday this case can go away. + */ + Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY, + ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, + WalkState, &(Node)); + if (ACPI_FAILURE (Status)) + { + if (Status == AE_NOT_FOUND) + { + /* The name was not found, go ahead and create it */ + + Status = AcpiNsLookup (WalkState->ScopeInfo, Path, + ACPI_TYPE_LOCAL_SCOPE, + ACPI_IMODE_LOAD_PASS1, Flags, + WalkState, &(Node)); + + /* + * However, this is an error -- primarily because the MS + * interpreter can't handle a forward reference from the + * Scope() operator. + */ + AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, + Op->Asl.ExternalName); + AslError (ASL_ERROR, ASL_MSG_SCOPE_FWD_REF, Op, + Op->Asl.ExternalName); + goto FinishNode; + } + + AslCoreSubsystemError (Op, Status, + "Failure from namespace lookup", FALSE); + + return_ACPI_STATUS (Status); + } + + /* We found a node with this name, now check the type */ + + switch (Node->Type) + { + case ACPI_TYPE_LOCAL_SCOPE: + case ACPI_TYPE_DEVICE: + case ACPI_TYPE_POWER: + case ACPI_TYPE_PROCESSOR: + case ACPI_TYPE_THERMAL: + + /* These are acceptable types - they all open a new scope */ + break; + + case ACPI_TYPE_INTEGER: + case ACPI_TYPE_STRING: + case ACPI_TYPE_BUFFER: + + /* + * These types we will allow, but we will change the type. + * This enables some existing code of the form: + * + * Name (DEB, 0) + * Scope (DEB) { ... } + * + * Which is used to workaround the fact that the MS interpreter + * does not allow Scope() forward references. + */ + sprintf (MsgBuffer, "%s [%s], changing type to [Scope]", + Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type)); + AslError (ASL_REMARK, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); + + /* Switch the type to scope, open the new scope */ + + Node->Type = ACPI_TYPE_LOCAL_SCOPE; + Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, + WalkState); + if (ACPI_FAILURE (Status)) + { + return_ACPI_STATUS (Status); + } + break; + + default: + + /* All other types are an error */ + + sprintf (MsgBuffer, "%s [%s]", Op->Asl.ExternalName, + AcpiUtGetTypeName (Node->Type)); + AslError (ASL_ERROR, ASL_MSG_SCOPE_TYPE, Op, MsgBuffer); + + /* + * However, switch the type to be an actual scope so + * that compilation can continue without generating a whole + * cascade of additional errors. Open the new scope. + */ + Node->Type = ACPI_TYPE_LOCAL_SCOPE; + Status = AcpiDsScopeStackPush (Node, ACPI_TYPE_LOCAL_SCOPE, + WalkState); + if (ACPI_FAILURE (Status)) + { + return_ACPI_STATUS (Status); + } + break; + } + + Status = AE_OK; + goto FinishNode; + + + default: + + ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); + break; + } + + + ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Loading name: %s, (%s)\n", + Op->Asl.ExternalName, AcpiUtGetTypeName (ObjectType))); + + /* The name must not already exist */ + + Flags |= ACPI_NS_ERROR_IF_FOUND; + + /* + * Enter the named type into the internal namespace. We enter the name + * as we go downward in the parse tree. Any necessary subobjects that + * involve arguments to the opcode must be created as we go back up the + * parse tree later. + */ + Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, + ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node); + if (ACPI_FAILURE (Status)) + { + if (Status == AE_ALREADY_EXISTS) + { + /* The name already exists in this scope */ + + if (Node->Type == ACPI_TYPE_LOCAL_SCOPE) + { + /* Allow multiple references to the same scope */ + + Node->Type = (UINT8) ObjectType; + Status = AE_OK; + } + else if ((Node->Flags & ANOBJ_IS_EXTERNAL) && + (Op->Asl.ParseOpcode != PARSEOP_EXTERNAL)) + { + /* + * Allow one create on an object or segment that was + * previously declared External + */ + Node->Flags &= ~ANOBJ_IS_EXTERNAL; + Node->Type = (UINT8) ObjectType; + + /* Just retyped a node, probably will need to open a scope */ + + if (AcpiNsOpensScope (ObjectType)) + { + Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); + if (ACPI_FAILURE (Status)) + { + return_ACPI_STATUS (Status); + } + } + Status = AE_OK; + } + else + { + /* Valid error, object already exists */ + + AslError (ASL_ERROR, ASL_MSG_NAME_EXISTS, Op, + Op->Asl.ExternalName); + return_ACPI_STATUS (AE_OK); + } + } + else + { + AslCoreSubsystemError (Op, Status, + "Failure from namespace lookup", FALSE); + return_ACPI_STATUS (Status); + } + } + + if (ForceNewScope) + { + Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); + if (ACPI_FAILURE (Status)) + { + return_ACPI_STATUS (Status); + } + } + +FinishNode: + /* + * Point the parse node to the new namespace node, and point + * the Node back to the original Parse node + */ + Op->Asl.Node = Node; + Node->Op = Op; + + /* Set the actual data type if appropriate (EXTERNAL term only) */ + + if (ActualObjectType != ACPI_TYPE_ANY) + { + Node->Type = (UINT8) ActualObjectType; + Node->Value = ASL_EXTERNAL_METHOD; + } + + if (Op->Asl.ParseOpcode == PARSEOP_METHOD) + { + /* + * Get the method argument count from "Extra" and save + * it in the namespace node + */ + Node->Value = (UINT32) Op->Asl.Extra; + } + + return_ACPI_STATUS (Status); +} + + +/******************************************************************************* + * + * FUNCTION: LdNamespace2Begin + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Descending callback used during the pass 2 parse tree walk. + * Second pass resolves some forward references. + * + * Notes: + * Currently only needs to handle the Alias operator. + * Could be used to allow forward references from the Scope() operator, but + * the MS interpreter does not allow this, so this compiler does not either. + * + ******************************************************************************/ + +static ACPI_STATUS +LdNamespace2Begin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; + ACPI_STATUS Status; + ACPI_NAMESPACE_NODE *Node; + ACPI_OBJECT_TYPE ObjectType; + BOOLEAN ForceNewScope = FALSE; + ACPI_PARSE_OBJECT *Arg; + char *Path; + ACPI_NAMESPACE_NODE *TargetNode; + + + ACPI_FUNCTION_NAME (LdNamespace2Begin); + ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n", + Op, Op->Asl.ParseOpName)); + + + /* Ignore Ops with no namespace node */ + + Node = Op->Asl.Node; + if (!Node) + { + return (AE_OK); + } + + /* Get the type to determine if we should push the scope */ + + if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) && + (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)) + { + ObjectType = ACPI_TYPE_LOCAL_RESOURCE; + } + else + { + ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); + } + + /* Push scope for Resource Templates */ + + if (Op->Asl.ParseOpcode == PARSEOP_NAME) + { + if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) + { + ForceNewScope = TRUE; + } + } + + /* Push the scope stack */ + + if (ForceNewScope || AcpiNsOpensScope (ObjectType)) + { + Status = AcpiDsScopeStackPush (Node, ObjectType, WalkState); + if (ACPI_FAILURE (Status)) + { + return_ACPI_STATUS (Status); + } + } + + if (Op->Asl.ParseOpcode == PARSEOP_ALIAS) + { + /* Complete the alias node by getting and saving the target node */ + + /* First child is the alias target */ + + Arg = Op->Asl.Child; + + /* Get the target pathname */ + + Path = Arg->Asl.Namepath; + if (!Path) + { + Status = UtInternalizeName (Arg->Asl.ExternalName, &Path); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + } + + /* Get the NS node associated with the target. It must exist. */ + + Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY, + ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, + WalkState, &TargetNode); + if (ACPI_FAILURE (Status)) + { + if (Status == AE_NOT_FOUND) + { + AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, + Op->Asl.ExternalName); + + /* + * The name was not found, go ahead and create it. + * This prevents more errors later. + */ + Status = AcpiNsLookup (WalkState->ScopeInfo, Path, + ACPI_TYPE_ANY, + ACPI_IMODE_LOAD_PASS1, ACPI_NS_NO_UPSEARCH, + WalkState, &(Node)); + return (AE_OK); + } + + AslCoreSubsystemError (Op, Status, + "Failure from namespace lookup", FALSE); + return (AE_OK); + } + + /* Save the target node within the alias node */ + + Node->Object = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, TargetNode); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LdCommonNamespaceEnd + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Ascending callback used during the loading of the namespace, + * We only need to worry about managing the scope stack here. + * + ******************************************************************************/ + +static ACPI_STATUS +LdCommonNamespaceEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; + ACPI_OBJECT_TYPE ObjectType; + BOOLEAN ForceNewScope = FALSE; + + + ACPI_FUNCTION_NAME (LdCommonNamespaceEnd); + + + /* We are only interested in opcodes that have an associated name */ + + if (!Op->Asl.Namepath) + { + return (AE_OK); + } + + /* Get the type to determine if we should pop the scope */ + + if ((Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) && + (Op->Asl.CompileFlags == NODE_IS_RESOURCE_DESC)) + { + /* TBD: Merge into AcpiDsMapNamedOpcodeToDataType */ + + ObjectType = ACPI_TYPE_LOCAL_RESOURCE; + } + else + { + ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); + } + + /* Pop scope that was pushed for Resource Templates */ + + if (Op->Asl.ParseOpcode == PARSEOP_NAME) + { + if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC) + { + ForceNewScope = TRUE; + } + } + + /* Pop the scope stack */ + + if (ForceNewScope || AcpiNsOpensScope (ObjectType)) + { + ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, + "(%s): Popping scope for Op [%s] %p\n", + AcpiUtGetTypeName (ObjectType), Op->Asl.ParseOpName, Op)); + + (void) AcpiDsScopeStackPop (WalkState); + } + + return (AE_OK); +} + + diff --git a/sys/contrib/dev/acpica/compiler/asllookup.c b/sys/contrib/dev/acpica/compiler/asllookup.c new file mode 100644 index 0000000..26fa305 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asllookup.c @@ -0,0 +1,1401 @@ +/****************************************************************************** + * + * Module Name: asllookup- Namespace lookup + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#include <contrib/dev/acpica/include/acparser.h> +#include <contrib/dev/acpica/include/amlcode.h> +#include <contrib/dev/acpica/include/acnamesp.h> +#include <contrib/dev/acpica/include/acdispat.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("asllookup") + +/* Local prototypes */ + +static ACPI_STATUS +LsCompareOneNamespaceObject ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue); + +static ACPI_STATUS +LsDoOneNamespaceObject ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue); + +static BOOLEAN +LkObjectExists ( + char *Name); + +static void +LkCheckFieldRange ( + ACPI_PARSE_OBJECT *Op, + UINT32 RegionBitLength, + UINT32 FieldBitOffset, + UINT32 FieldBitLength, + UINT32 AccessBitWidth); + +static ACPI_STATUS +LkNamespaceLocateBegin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static ACPI_STATUS +LkNamespaceLocateEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); + +static ACPI_STATUS +LkIsObjectUsed ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue); + +static ACPI_STATUS +LsDoOnePathname ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue); + +static ACPI_PARSE_OBJECT * +LkGetNameOp ( + ACPI_PARSE_OBJECT *Op); + + +/******************************************************************************* + * + * FUNCTION: LsDoOneNamespaceObject + * + * PARAMETERS: ACPI_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Dump a namespace object to the namespace output file. + * Called during the walk of the namespace to dump all objects. + * + ******************************************************************************/ + +static ACPI_STATUS +LsDoOneNamespaceObject ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue) +{ + ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; + ACPI_OPERAND_OBJECT *ObjDesc; + ACPI_PARSE_OBJECT *Op; + + + Gbl_NumNamespaceObjects++; + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%5u [%u] %*s %4.4s - %s", + Gbl_NumNamespaceObjects, Level, (Level * 3), " ", + &Node->Name, + AcpiUtGetTypeName (Node->Type)); + + Op = Node->Op; + ObjDesc = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Node->Object); + + if (!Op) + { + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n"); + return (AE_OK); + } + + + if ((ObjDesc) && + (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND)) + { + switch (Node->Type) + { + case ACPI_TYPE_INTEGER: + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Initial Value 0x%8.8X%8.8X]", + ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value)); + break; + + + case ACPI_TYPE_STRING: + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Initial Value \"%s\"]", + ObjDesc->String.Pointer); + break; + + default: + /* Nothing to do for other types */ + break; + } + + } + else + { + switch (Node->Type) + { + case ACPI_TYPE_INTEGER: + + if (Op->Asl.ParseOpcode == PARSEOP_NAME) + { + Op = Op->Asl.Child; + } + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) + { + Op = Op->Asl.Next; + } + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Initial Value 0x%8.8X%8.8X]", + ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer)); + break; + + + case ACPI_TYPE_STRING: + + if (Op->Asl.ParseOpcode == PARSEOP_NAME) + { + Op = Op->Asl.Child; + } + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) + { + Op = Op->Asl.Next; + } + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Initial Value \"%s\"]", + Op->Asl.Value.String); + break; + + + case ACPI_TYPE_LOCAL_REGION_FIELD: + + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) + { + Op = Op->Asl.Child; + } + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Offset 0x%04X Length 0x%04X bits]", + Op->Asl.Parent->Asl.ExtraValue, (UINT32) Op->Asl.Value.Integer); + break; + + + case ACPI_TYPE_BUFFER_FIELD: + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_CREATEBYTEFIELD: + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BYTE ( 8 bit)]"); + break; + + case PARSEOP_CREATEDWORDFIELD: + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [DWORD (32 bit)]"); + break; + + case PARSEOP_CREATEQWORDFIELD: + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [QWORD (64 bit)]"); + break; + + case PARSEOP_CREATEWORDFIELD: + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [WORD (16 bit)]"); + break; + + case PARSEOP_CREATEBITFIELD: + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [BIT ( 1 bit)]"); + break; + + case PARSEOP_CREATEFIELD: + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, " [Arbitrary Bit Field]"); + break; + + default: + break; + + } + break; + + + case ACPI_TYPE_PACKAGE: + + if (Op->Asl.ParseOpcode == PARSEOP_NAME) + { + Op = Op->Asl.Child; + } + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) + { + Op = Op->Asl.Next; + } + Op = Op->Asl.Child; + + if ((Op->Asl.ParseOpcode == PARSEOP_BYTECONST) || + (Op->Asl.ParseOpcode == PARSEOP_RAW_DATA)) + { + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Initial Length 0x%.2X elements]", + Op->Asl.Value.Integer); + } + break; + + + case ACPI_TYPE_BUFFER: + + if (Op->Asl.ParseOpcode == PARSEOP_NAME) + { + Op = Op->Asl.Child; + } + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) + { + Op = Op->Asl.Next; + } + Op = Op->Asl.Child; + + if (Op && (Op->Asl.ParseOpcode == PARSEOP_INTEGER)) + { + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Initial Length 0x%.2X bytes]", + Op->Asl.Value.Integer); + } + break; + + + case ACPI_TYPE_METHOD: + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Code Length 0x%.4X bytes]", + Op->Asl.AmlSubtreeLength); + break; + + + case ACPI_TYPE_LOCAL_RESOURCE: + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Desc Offset 0x%.4X Bytes]", Node->Value); + break; + + + case ACPI_TYPE_LOCAL_RESOURCE_FIELD: + + if (Node->Flags & 0x80) + { + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Field Offset 0x%.4X Bits 0x%.4X Bytes]", + Node->Value, Node->Value / 8); + } + else + { + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, + " [Field Offset 0x%.4X Bytes]", Node->Value); + } + break; + + + default: + /* Nothing to do for other types */ + break; + } + } + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\n"); + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LsSetupNsList + * + * PARAMETERS: Handle - local file handle + * + * RETURN: None + * + * DESCRIPTION: Set the namespace output file to the input handle + * + ******************************************************************************/ + +void +LsSetupNsList ( + void *Handle) +{ + + Gbl_NsOutputFlag = TRUE; + Gbl_Files[ASL_FILE_NAMESPACE_OUTPUT].Handle = Handle; +} + + +/******************************************************************************* + * + * FUNCTION: LsDoOnePathname + * + * PARAMETERS: ACPI_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Print the full pathname for a namespace node. + * + ******************************************************************************/ + +static ACPI_STATUS +LsDoOnePathname ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue) +{ + ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; + ACPI_STATUS Status; + ACPI_BUFFER TargetPath; + + + TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER; + Status = AcpiNsHandleToPathname (Node, &TargetPath); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "%s\n", TargetPath.Pointer); + ACPI_FREE (TargetPath.Pointer); + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LsDisplayNamespace + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Walk the namespace an display information about each node + * in the tree. Information is written to the optional + * namespace output file. + * + ******************************************************************************/ + +ACPI_STATUS +LsDisplayNamespace ( + void) +{ + ACPI_STATUS Status; + + + if (!Gbl_NsOutputFlag) + { + return (AE_OK); + } + + Gbl_NumNamespaceObjects = 0; + + /* File header */ + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Contents of ACPI Namespace\n\n"); + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "Count Depth Name - Type\n\n"); + + /* Walk entire namespace from the root */ + + Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, FALSE, LsDoOneNamespaceObject, NULL, + NULL, NULL); + + /* Print the full pathname for each namespace node */ + + FlPrintFile (ASL_FILE_NAMESPACE_OUTPUT, "\nNamespace pathnames\n\n"); + + Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, FALSE, LsDoOnePathname, NULL, + NULL, NULL); + + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: LsCompareOneNamespaceObject + * + * PARAMETERS: ACPI_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Compare name of one object. + * + ******************************************************************************/ + +static ACPI_STATUS +LsCompareOneNamespaceObject ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue) +{ + ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle; + + + /* Simply check the name */ + + if (*((UINT32 *) (Context)) == Node->Name.Integer) + { + /* Abort walk if we found one instance */ + + return (AE_CTRL_TRUE); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LkObjectExists + * + * PARAMETERS: Name - 4 char ACPI name + * + * RETURN: TRUE if name exists in namespace + * + * DESCRIPTION: Walk the namespace to find an object + * + ******************************************************************************/ + +static BOOLEAN +LkObjectExists ( + char *Name) +{ + ACPI_STATUS Status; + + + /* Walk entire namespace from the supplied root */ + + Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, FALSE, LsCompareOneNamespaceObject, NULL, + Name, NULL); + if (Status == AE_CTRL_TRUE) + { + /* At least one instance of the name was found */ + + return (TRUE); + } + + return (FALSE); +} + + +/******************************************************************************* + * + * FUNCTION: LkGetNameOp + * + * PARAMETERS: Op - Current Op + * + * RETURN: NameOp associated with the input op + * + * DESCRIPTION: Find the name declaration op associated with the operator + * + ******************************************************************************/ + +static ACPI_PARSE_OBJECT * +LkGetNameOp ( + ACPI_PARSE_OBJECT *Op) +{ + const ACPI_OPCODE_INFO *OpInfo; + ACPI_PARSE_OBJECT *NameOp = Op; + + + OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); + + + /* Get the NamePath from the appropriate place */ + + if (OpInfo->Flags & AML_NAMED) + { + /* For nearly all NAMED operators, the name reference is the first child */ + + NameOp = Op->Asl.Child; + if (Op->Asl.AmlOpcode == AML_ALIAS_OP) + { + /* + * ALIAS is the only oddball opcode, the name declaration + * (alias name) is the second operand + */ + NameOp = Op->Asl.Child->Asl.Next; + } + } + else if (OpInfo->Flags & AML_CREATE) + { + /* Name must appear as the last parameter */ + + NameOp = Op->Asl.Child; + while (!(NameOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)) + { + NameOp = NameOp->Asl.Next; + } + } + + return (NameOp); +} + + +/******************************************************************************* + * + * FUNCTION: LkIsObjectUsed + * + * PARAMETERS: ACPI_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Check for an unreferenced namespace object and emit a warning. + * We have to be careful, because some types and names are + * typically or always unreferenced, we don't want to issue + * excessive warnings. + * + ******************************************************************************/ + +static ACPI_STATUS +LkIsObjectUsed ( + ACPI_HANDLE ObjHandle, + UINT32 Level, + void *Context, + void **ReturnValue) +{ + ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle); + + + /* Referenced flag is set during the namespace xref */ + + if (Node->Flags & ANOBJ_IS_REFERENCED) + { + return (AE_OK); + } + + /* + * Ignore names that start with an underscore, + * these are the reserved ACPI names and are typically not referenced, + * they are called by the host OS. + */ + if (Node->Name.Ascii[0] == '_') + { + return (AE_OK); + } + + /* There are some types that are typically not referenced, ignore them */ + + switch (Node->Type) + { + case ACPI_TYPE_DEVICE: + case ACPI_TYPE_PROCESSOR: + case ACPI_TYPE_POWER: + case ACPI_TYPE_LOCAL_RESOURCE: + return (AE_OK); + + default: + break; + } + + /* All others are valid unreferenced namespace objects */ + + if (Node->Op) + { + AslError (ASL_WARNING2, ASL_MSG_NOT_REFERENCED, LkGetNameOp (Node->Op), NULL); + } + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: LkFindUnreferencedObjects + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Namespace walk to find objects that are not referenced in any + * way. Must be called after the namespace has been cross + * referenced. + * + ******************************************************************************/ + +void +LkFindUnreferencedObjects ( + void) +{ + + /* Walk entire namespace from the supplied root */ + + (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, + ACPI_UINT32_MAX, FALSE, LkIsObjectUsed, NULL, + NULL, NULL); +} + + +/******************************************************************************* + * + * FUNCTION: LkCrossReferenceNamespace + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Perform a cross reference check of the parse tree against the + * namespace. Every named referenced within the parse tree + * should be get resolved with a namespace lookup. If not, the + * original reference in the ASL code is invalid -- i.e., refers + * to a non-existent object. + * + * NOTE: The ASL "External" operator causes the name to be inserted into the + * namespace so that references to the external name will be resolved + * correctly here. + * + ******************************************************************************/ + +ACPI_STATUS +LkCrossReferenceNamespace ( + void) +{ + ACPI_WALK_STATE *WalkState; + + + DbgPrint (ASL_DEBUG_OUTPUT, "\nCross referencing namespace\n\n"); + + /* + * Create a new walk state for use when looking up names + * within the namespace (Passed as context to the callbacks) + */ + WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); + if (!WalkState) + { + return AE_NO_MEMORY; + } + + /* Walk the entire parse tree */ + + TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, LkNamespaceLocateBegin, + LkNamespaceLocateEnd, WalkState); + return AE_OK; +} + + +/******************************************************************************* + * + * FUNCTION: LkCheckFieldRange + * + * PARAMETERS: RegionBitLength - Length of entire parent region + * FieldBitOffset - Start of the field unit (within region) + * FieldBitLength - Entire length of field unit + * AccessBitWidth - Access width of the field unit + * + * RETURN: None + * + * DESCRIPTION: Check one field unit to make sure it fits in the parent + * op region. + * + * Note: AccessBitWidth must be either 8,16,32, or 64 + * + ******************************************************************************/ + +static void +LkCheckFieldRange ( + ACPI_PARSE_OBJECT *Op, + UINT32 RegionBitLength, + UINT32 FieldBitOffset, + UINT32 FieldBitLength, + UINT32 AccessBitWidth) +{ + UINT32 FieldEndBitOffset; + + + /* + * Check each field unit against the region size. The entire + * field unit (start offset plus length) must fit within the + * region. + */ + FieldEndBitOffset = FieldBitOffset + FieldBitLength; + + if (FieldEndBitOffset > RegionBitLength) + { + /* Field definition itself is beyond the end-of-region */ + + AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL); + return; + } + + /* + * Now check that the field plus AccessWidth doesn't go beyond + * the end-of-region. Assumes AccessBitWidth is a power of 2 + */ + FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth); + + if (FieldEndBitOffset > RegionBitLength) + { + /* Field definition combined with the access is beyond EOR */ + + AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL); + } +} + +/******************************************************************************* + * + * FUNCTION: LkNamespaceLocateBegin + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Descending callback used during cross-reference. For named + * object references, attempt to locate the name in the + * namespace. + * + * NOTE: ASL references to named fields within resource descriptors are + * resolved to integer values here. Therefore, this step is an + * important part of the code generation. We don't know that the + * name refers to a resource descriptor until now. + * + ******************************************************************************/ + +static ACPI_STATUS +LkNamespaceLocateBegin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; + ACPI_NAMESPACE_NODE *Node; + ACPI_STATUS Status; + ACPI_OBJECT_TYPE ObjectType; + char *Path; + UINT8 PassedArgs; + ACPI_PARSE_OBJECT *NextOp; + ACPI_PARSE_OBJECT *OwningOp; + ACPI_PARSE_OBJECT *SpaceIdOp; + UINT32 MinimumLength; + UINT32 Offset; + UINT32 FieldBitLength; + UINT32 TagBitLength; + UINT8 Message = 0; + const ACPI_OPCODE_INFO *OpInfo; + UINT32 Flags; + + + ACPI_FUNCTION_TRACE_PTR (LkNamespaceLocateBegin, Op); + + /* + * If this node is the actual declaration of a name + * [such as the XXXX name in "Method (XXXX)"], + * we are not interested in it here. We only care about names that are + * references to other objects within the namespace and the parent objects + * of name declarations + */ + if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION) + { + return (AE_OK); + } + + /* We are only interested in opcodes that have an associated name */ + + OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); + + if ((!(OpInfo->Flags & AML_NAMED)) && + (!(OpInfo->Flags & AML_CREATE)) && + (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) && + (Op->Asl.ParseOpcode != PARSEOP_NAMESEG) && + (Op->Asl.ParseOpcode != PARSEOP_METHODCALL)) + { + return (AE_OK); + } + + /* + * One special case: CondRefOf operator - we don't care if the name exists + * or not at this point, just ignore it, the point of the operator is to + * determine if the name exists at runtime. + */ + if ((Op->Asl.Parent) && + (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)) + { + return (AE_OK); + } + + /* + * We must enable the "search-to-root" for single NameSegs, but + * we have to be very careful about opening up scopes + */ + Flags = ACPI_NS_SEARCH_PARENT; + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) + { + /* + * These are name references, do not push the scope stack + * for them. + */ + Flags |= ACPI_NS_DONT_OPEN_SCOPE; + } + + /* Get the NamePath from the appropriate place */ + + if (OpInfo->Flags & AML_NAMED) + { + /* For nearly all NAMED operators, the name reference is the first child */ + + Path = Op->Asl.Child->Asl.Value.String; + if (Op->Asl.AmlOpcode == AML_ALIAS_OP) + { + /* + * ALIAS is the only oddball opcode, the name declaration + * (alias name) is the second operand + */ + Path = Op->Asl.Child->Asl.Next->Asl.Value.String; + } + } + else if (OpInfo->Flags & AML_CREATE) + { + /* Name must appear as the last parameter */ + + NextOp = Op->Asl.Child; + while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)) + { + NextOp = NextOp->Asl.Next; + } + Path = NextOp->Asl.Value.String; + } + else + { + Path = Op->Asl.Value.String; + } + + ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); + ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, + "Type=%s\n", AcpiUtGetTypeName (ObjectType))); + + /* + * Lookup the name in the namespace. Name must exist at this point, or it + * is an invalid reference. + * + * The namespace is also used as a lookup table for references to resource + * descriptors and the fields within them. + */ + Gbl_NsLookupCount++; + + Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, + ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node)); + if (ACPI_FAILURE (Status)) + { + if (Status == AE_NOT_FOUND) + { + /* + * We didn't find the name reference by path -- we can qualify this + * a little better before we print an error message + */ + if (strlen (Path) == ACPI_NAME_SIZE) + { + /* A simple, one-segment ACPI name */ + + if (LkObjectExists (Path)) + { + /* + * There exists such a name, but we couldn't get to it + * from this scope + */ + AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op, + Op->Asl.ExternalName); + } + else + { + /* The name doesn't exist, period */ + + AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, + Op, Op->Asl.ExternalName); + } + } + else + { + /* Check for a fully qualified path */ + + if (Path[0] == AML_ROOT_PREFIX) + { + /* Gave full path, the object does not exist */ + + AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op, + Op->Asl.ExternalName); + } + else + { + /* + * We can't tell whether it doesn't exist or just + * can't be reached. + */ + AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op, + Op->Asl.ExternalName); + } + } + + Status = AE_OK; + } + return (Status); + } + + /* Check for a reference vs. name declaration */ + + if (!(OpInfo->Flags & AML_NAMED) && + !(OpInfo->Flags & AML_CREATE)) + { + /* This node has been referenced, mark it for reference check */ + + Node->Flags |= ANOBJ_IS_REFERENCED; + } + + /* Attempt to optimize the NamePath */ + + OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node); + + /* + * 1) Dereference an alias (A name reference that is an alias) + * Aliases are not nested, the alias always points to the final object + */ + if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) && + (Node->Type == ACPI_TYPE_LOCAL_ALIAS)) + { + /* This node points back to the original PARSEOP_ALIAS */ + + NextOp = Node->Op; + + /* The first child is the alias target op */ + + NextOp = NextOp->Asl.Child; + + /* That in turn points back to original target alias node */ + + if (NextOp->Asl.Node) + { + Node = NextOp->Asl.Node; + } + + /* Else - forward reference to alias, will be resolved later */ + } + + /* 2) Check for a reference to a resource descriptor */ + + if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) || + (Node->Type == ACPI_TYPE_LOCAL_RESOURCE)) + { + /* + * This was a reference to a field within a resource descriptor. + * Extract the associated field offset (either a bit or byte + * offset depending on the field type) and change the named + * reference into an integer for AML code generation + */ + Offset = Node->Value; + TagBitLength = Node->Length; + + /* + * If a field is being created, generate the length (in bits) of + * the field. Note: Opcodes other than CreateXxxField and Index + * can come through here. For other opcodes, we just need to + * convert the resource tag reference to an integer offset. + */ + switch (Op->Asl.Parent->Asl.AmlOpcode) + { + case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */ + /* + * We know the length operand is an integer constant because + * we know that it contains a reference to a resource + * descriptor tag. + */ + FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer; + break; + + case AML_CREATE_BIT_FIELD_OP: + FieldBitLength = 1; + break; + + case AML_CREATE_BYTE_FIELD_OP: + case AML_INDEX_OP: + FieldBitLength = 8; + break; + + case AML_CREATE_WORD_FIELD_OP: + FieldBitLength = 16; + break; + + case AML_CREATE_DWORD_FIELD_OP: + FieldBitLength = 32; + break; + + case AML_CREATE_QWORD_FIELD_OP: + FieldBitLength = 64; + break; + + default: + FieldBitLength = 0; + break; + } + + /* Check the field length against the length of the resource tag */ + + if (FieldBitLength) + { + if (TagBitLength < FieldBitLength) + { + Message = ASL_MSG_TAG_SMALLER; + } + else if (TagBitLength > FieldBitLength) + { + Message = ASL_MSG_TAG_LARGER; + } + + if (Message) + { + sprintf (MsgBuffer, "Tag: %u bit%s, Field: %u bit%s", + TagBitLength, (TagBitLength > 1) ? "s" : "", + FieldBitLength, (FieldBitLength > 1) ? "s" : ""); + + AslError (ASL_WARNING, Message, Op, MsgBuffer); + } + } + + /* Convert the BitOffset to a ByteOffset for certain opcodes */ + + switch (Op->Asl.Parent->Asl.AmlOpcode) + { + case AML_CREATE_BYTE_FIELD_OP: + case AML_CREATE_WORD_FIELD_OP: + case AML_CREATE_DWORD_FIELD_OP: + case AML_CREATE_QWORD_FIELD_OP: + case AML_INDEX_OP: + + Offset = ACPI_DIV_8 (Offset); + break; + + default: + break; + } + + /* Now convert this node to an integer whose value is the field offset */ + + Op->Asl.AmlLength = 0; + Op->Asl.ParseOpcode = PARSEOP_INTEGER; + Op->Asl.Value.Integer = (UINT64) Offset; + Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD; + + OpcGenerateAmlOpcode (Op); + } + + /* 3) Check for a method invocation */ + + else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) && + (Node->Type == ACPI_TYPE_METHOD) && + (Op->Asl.Parent) && + (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD)) || + + (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) + { + + /* + * A reference to a method within one of these opcodes is not an + * invocation of the method, it is simply a reference to the method. + */ + if ((Op->Asl.Parent) && + ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF) || + (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF) || + (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE))) + { + return (AE_OK); + } + /* + * There are two types of method invocation: + * 1) Invocation with arguments -- the parser recognizes this + * as a METHODCALL. + * 2) Invocation with no arguments --the parser cannot determine that + * this is a method invocation, therefore we have to figure it out + * here. + */ + if (Node->Type != ACPI_TYPE_METHOD) + { + sprintf (MsgBuffer, "%s is a %s", + Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type)); + + AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer); + return (AE_OK); + } + + /* Save the method node in the caller's op */ + + Op->Asl.Node = Node; + if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF) + { + return (AE_OK); + } + + /* + * This is a method invocation, with or without arguments. + * Count the number of arguments, each appears as a child + * under the parent node + */ + Op->Asl.ParseOpcode = PARSEOP_METHODCALL; + UtSetParseOpName (Op); + + PassedArgs = 0; + NextOp = Op->Asl.Child; + + while (NextOp) + { + PassedArgs++; + NextOp = NextOp->Asl.Next; + } + + if (Node->Value != ASL_EXTERNAL_METHOD) + { + /* + * Check the parsed arguments with the number expected by the + * method declaration itself + */ + if (PassedArgs != Node->Value) + { + sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, + Node->Value); + + if (PassedArgs < Node->Value) + { + AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer); + } + else + { + AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer); + } + } + } + } + + /* 4) Check for an ASL Field definition */ + + else if ((Op->Asl.Parent) && + ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD) || + (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD))) + { + /* + * Offset checking for fields. If the parent operation region has a + * constant length (known at compile time), we can check fields + * defined in that region against the region length. This will catch + * fields and field units that cannot possibly fit within the region. + * + * Note: Index fields do not directly reference an operation region, + * thus they are not included in this check. + */ + if (Op == Op->Asl.Parent->Asl.Child) + { + /* + * This is the first child of the field node, which is + * the name of the region. Get the parse node for the + * region -- which contains the length of the region. + */ + OwningOp = Node->Op; + Op->Asl.Parent->Asl.ExtraValue = + ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer); + + /* Examine the field access width */ + + switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer) + { + case AML_FIELD_ACCESS_ANY: + case AML_FIELD_ACCESS_BYTE: + case AML_FIELD_ACCESS_BUFFER: + default: + MinimumLength = 1; + break; + + case AML_FIELD_ACCESS_WORD: + MinimumLength = 2; + break; + + case AML_FIELD_ACCESS_DWORD: + MinimumLength = 4; + break; + + case AML_FIELD_ACCESS_QWORD: + MinimumLength = 8; + break; + } + + /* + * Is the region at least as big as the access width? + * Note: DataTableRegions have 0 length + */ + if (((UINT32) OwningOp->Asl.Value.Integer) && + ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength)) + { + AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL); + } + + /* + * Check EC/CMOS/SMBUS fields to make sure that the correct + * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS) + */ + SpaceIdOp = OwningOp->Asl.Child->Asl.Next; + switch ((UINT32) SpaceIdOp->Asl.Value.Integer) + { + case ACPI_ADR_SPACE_EC: + case ACPI_ADR_SPACE_CMOS: + case ACPI_ADR_SPACE_GPIO: + + if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE) + { + AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL); + } + break; + + case ACPI_ADR_SPACE_SMBUS: + case ACPI_ADR_SPACE_IPMI: + case ACPI_ADR_SPACE_GSBUS: + + if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER) + { + AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL); + } + break; + + default: + + /* Nothing to do for other address spaces */ + break; + } + } + else + { + /* + * This is one element of the field list. Check to make sure + * that it does not go beyond the end of the parent operation region. + * + * In the code below: + * Op->Asl.Parent->Asl.ExtraValue - Region Length (bits) + * Op->Asl.ExtraValue - Field start offset (bits) + * Op->Asl.Child->Asl.Value.Integer32 - Field length (bits) + * Op->Asl.Child->Asl.ExtraValue - Field access width (bits) + */ + if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child) + { + LkCheckFieldRange (Op, + Op->Asl.Parent->Asl.ExtraValue, + Op->Asl.ExtraValue, + (UINT32) Op->Asl.Child->Asl.Value.Integer, + Op->Asl.Child->Asl.ExtraValue); + } + } + } + + Op->Asl.Node = Node; + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: LkNamespaceLocateEnd + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Ascending callback used during cross reference. We only + * need to worry about scope management here. + * + ******************************************************************************/ + +static ACPI_STATUS +LkNamespaceLocateEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_WALK_STATE *WalkState = (ACPI_WALK_STATE *) Context; + const ACPI_OPCODE_INFO *OpInfo; + + + ACPI_FUNCTION_TRACE (LkNamespaceLocateEnd); + + + /* We are only interested in opcodes that have an associated name */ + + OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); + if (!(OpInfo->Flags & AML_NAMED)) + { + return (AE_OK); + } + + /* Not interested in name references, we did not open a scope for them */ + + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)) + { + return (AE_OK); + } + + /* Pop the scope stack if necessary */ + + if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode))) + { + + ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, + "%s: Popping scope for Op %p\n", + AcpiUtGetTypeName (OpInfo->ObjectType), Op)); + + (void) AcpiDsScopeStackPop (WalkState); + } + + return (AE_OK); +} + + diff --git a/sys/contrib/dev/acpica/compiler/aslmain.c b/sys/contrib/dev/acpica/compiler/aslmain.c new file mode 100644 index 0000000..b5d944e --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslmain.c @@ -0,0 +1,999 @@ + +/****************************************************************************** + * + * Module Name: aslmain - compiler main and utilities + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#define _DECLARE_GLOBALS + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/include/acapps.h> +#include <contrib/dev/acpica/include/acdisasm.h> + +#ifdef _DEBUG +#include <crtdbg.h> +#endif + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslmain") + +/* Local prototypes */ + +static void +Options ( + void); + +static void +HelpMessage ( + void); + +static void +Usage ( + void); + +static void +AslInitialize ( + void); + +static int +AslCommandLine ( + int argc, + char **argv); + +static int +AslDoOptions ( + int argc, + char **argv, + BOOLEAN IsResponseFile); + +static void +AslMergeOptionTokens ( + char *InBuffer, + char *OutBuffer); + +static int +AslDoResponseFile ( + char *Filename); + + +#define ASL_TOKEN_SEPARATORS " \t\n" +#define ASL_SUPPORTED_OPTIONS "@:2b|c|d^D:e:fgh^i|I:l^mno|p:P^r:s|t|T:G^v|w|x:z" + + +/******************************************************************************* + * + * FUNCTION: Options + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Display option help message + * + ******************************************************************************/ + +static void +Options ( + void) +{ + + printf ("\nGlobal:\n"); + ACPI_OPTION ("-@ <file>", "Specify command file"); + ACPI_OPTION ("-I <dir>", "Specify additional include directory"); + + printf ("\nPreprocessor:\n"); + ACPI_OPTION ("-D <symbol>", "Define symbol for preprocessor use"); + ACPI_OPTION ("-li", "Create preprocessed output file (*.i)"); + ACPI_OPTION ("-P", "Preprocess only and create preprocessor output file (*.i)"); + ACPI_OPTION ("-Pn", "Disable preprocessor"); + + printf ("\nGeneral Output:\n"); + ACPI_OPTION ("-p <prefix>", "Specify path/filename prefix for all output files"); + ACPI_OPTION ("-va", "Disable all errors and warnings (summary only)"); + ACPI_OPTION ("-vi", "Less verbose errors and warnings for use with IDEs"); + ACPI_OPTION ("-vo", "Enable optimization comments"); + ACPI_OPTION ("-vr", "Disable remarks"); + ACPI_OPTION ("-vs", "Disable signon"); + ACPI_OPTION ("-w1 -w2 -w3", "Set warning reporting level"); + ACPI_OPTION ("-we", "Report warnings as errors"); + + printf ("\nAML Output Files:\n"); + ACPI_OPTION ("-sa -sc", "Create AML in assembler or C source file (*.asm or *.c)"); + ACPI_OPTION ("-ia -ic", "Create assembler or C include file (*.inc or *.h)"); + ACPI_OPTION ("-ta -tc -ts", "Create AML in assembler, C, or ASL hex table (*.hex)"); + + printf ("\nAML Code Generation:\n"); + ACPI_OPTION ("-oa", "Disable all optimizations (compatibility mode)"); + ACPI_OPTION ("-of", "Disable constant folding"); + ACPI_OPTION ("-oi", "Disable integer optimization to Zero/One/Ones"); + ACPI_OPTION ("-on", "Disable named reference string optimization"); + ACPI_OPTION ("-cr", "Disable Resource Descriptor error checking"); + ACPI_OPTION ("-r <revision>", "Override table header Revision (1-255)"); + + printf ("\nASL Listing Files:\n"); + ACPI_OPTION ("-l", "Create mixed listing file (ASL source and AML) (*.lst)"); + ACPI_OPTION ("-ln", "Create namespace file (*.nsp)"); + ACPI_OPTION ("-ls", "Create combined source file (expanded includes) (*.src)"); + + printf ("\nACPI Data Tables:\n"); + ACPI_OPTION ("-G", "Compile custom table containing generic operators"); + ACPI_OPTION ("-T <sig>|ALL|*", "Create table template file(s) for <Sig>"); + ACPI_OPTION ("-vt", "Create verbose templates (full disassembly)"); + + printf ("\nAML Disassembler:\n"); + ACPI_OPTION ("-d [file]", "Disassemble or decode binary ACPI table to file (*.dsl)"); + ACPI_OPTION ("-da [f1,f2]", "Disassemble multiple tables from single namespace"); + ACPI_OPTION ("-dc [file]", "Disassemble AML and immediately compile it"); + ACPI_OPTION ("", "(Obtain DSDT from current system if no input file)"); + ACPI_OPTION ("-e [f1,f2]", "Include ACPI table(s) for external symbol resolution"); + ACPI_OPTION ("-m", "Do not translate Buffers to Resource Templates"); + ACPI_OPTION ("-2", "Emit ACPI 2.0 compatible ASL code"); + ACPI_OPTION ("-g", "Get ACPI tables and write to files (*.dat)"); + + printf ("\nHelp:\n"); + ACPI_OPTION ("-h", "Additional help and compiler debug options"); + ACPI_OPTION ("-hc", "Display operators allowed in constant expressions"); + ACPI_OPTION ("-hr", "Display ACPI reserved method names"); + ACPI_OPTION ("-ht", "Display currently supported ACPI table names"); +} + + +/******************************************************************************* + * + * FUNCTION: HelpMessage + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Display help message + * + ******************************************************************************/ + +static void +HelpMessage ( + void) +{ + + printf ("\nAML output filename generation:\n"); + printf (" Output filenames are generated by appending an extension to a common\n"); + printf (" filename prefix. The filename prefix is obtained via one of the\n"); + printf (" following methods (in priority order):\n"); + printf (" 1) The -p option specifies the prefix\n"); + printf (" 2) The prefix of the AMLFileName in the ASL Definition Block\n"); + printf (" 3) The prefix of the input filename\n"); + printf ("\n"); + + Options (); + + printf ("\nCompiler/Disassembler Debug Options:\n"); + ACPI_OPTION ("-bb -bp -bt", "Create compiler debug/trace file (*.txt)"); + ACPI_OPTION ("", "Types: Parse/Tree/Both"); + ACPI_OPTION ("-f", "Ignore errors, force creation of AML output file(s)"); + ACPI_OPTION ("-n", "Parse only, no output generation"); + ACPI_OPTION ("-ot", "Display compile times"); + ACPI_OPTION ("-x <level>", "Set debug level for trace output"); + ACPI_OPTION ("-z", "Do not insert new compiler ID for DataTables"); +} + + +/******************************************************************************* + * + * FUNCTION: Usage + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Display usage and option message + * + ******************************************************************************/ + +static void +Usage ( + void) +{ + + printf ("%s\n\n", ASL_COMPLIANCE); + ACPI_USAGE_HEADER ("iasl [Options] [Files]"); + Options (); +} + + +/******************************************************************************* + * + * FUNCTION: AslInitialize + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Initialize compiler globals + * + ******************************************************************************/ + +static void +AslInitialize ( + void) +{ + UINT32 i; + + +#ifdef _DEBUG + _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CrtSetDbgFlag(0)); +#endif + + AcpiDbgLevel = 0; + + for (i = 0; i < ASL_NUM_FILES; i++) + { + Gbl_Files[i].Handle = NULL; + Gbl_Files[i].Filename = NULL; + } + + Gbl_Files[ASL_FILE_STDOUT].Handle = stdout; + Gbl_Files[ASL_FILE_STDOUT].Filename = "STDOUT"; + + Gbl_Files[ASL_FILE_STDERR].Handle = stderr; + Gbl_Files[ASL_FILE_STDERR].Filename = "STDERR"; +} + + +/******************************************************************************* + * + * FUNCTION: AslMergeOptionTokens + * + * PARAMETERS: InBuffer - Input containing an option string + * OutBuffer - Merged output buffer + * + * RETURN: None + * + * DESCRIPTION: Remove all whitespace from an option string. + * + ******************************************************************************/ + +static void +AslMergeOptionTokens ( + char *InBuffer, + char *OutBuffer) +{ + char *Token; + + + *OutBuffer = 0; + + Token = strtok (InBuffer, ASL_TOKEN_SEPARATORS); + while (Token) + { + strcat (OutBuffer, Token); + Token = strtok (NULL, ASL_TOKEN_SEPARATORS); + } +} + + +/******************************************************************************* + * + * FUNCTION: AslDoResponseFile + * + * PARAMETERS: Filename - Name of the response file + * + * RETURN: Status + * + * DESCRIPTION: Open a response file and process all options within. + * + ******************************************************************************/ + +static int +AslDoResponseFile ( + char *Filename) +{ + char *argv = StringBuffer2; + FILE *ResponseFile; + int OptStatus = 0; + int Opterr; + int Optind; + + + ResponseFile = fopen (Filename, "r"); + if (!ResponseFile) + { + printf ("Could not open command file %s, %s\n", + Filename, strerror (errno)); + return -1; + } + + /* Must save the current GetOpt globals */ + + Opterr = AcpiGbl_Opterr; + Optind = AcpiGbl_Optind; + + /* + * Process all lines in the response file. There must be one complete + * option per line + */ + while (fgets (StringBuffer, ASL_MSG_BUFFER_SIZE, ResponseFile)) + { + /* Compress all tokens, allowing us to use a single argv entry */ + + AslMergeOptionTokens (StringBuffer, StringBuffer2); + + /* Process the option */ + + AcpiGbl_Opterr = 0; + AcpiGbl_Optind = 0; + + OptStatus = AslDoOptions (1, &argv, TRUE); + if (OptStatus) + { + printf ("Invalid option in command file %s: %s\n", + Filename, StringBuffer); + break; + } + } + + /* Restore the GetOpt globals */ + + AcpiGbl_Opterr = Opterr; + AcpiGbl_Optind = Optind; + + fclose (ResponseFile); + return (OptStatus); +} + + +/******************************************************************************* + * + * FUNCTION: AslDoOptions + * + * PARAMETERS: argc/argv - Standard argc/argv + * IsResponseFile - TRUE if executing a response file. + * + * RETURN: Status + * + * DESCRIPTION: Command line option processing + * + ******************************************************************************/ + +static int +AslDoOptions ( + int argc, + char **argv, + BOOLEAN IsResponseFile) +{ + int j; + ACPI_STATUS Status; + + + /* Get the command line options */ + + while ((j = AcpiGetopt (argc, argv, ASL_SUPPORTED_OPTIONS)) != EOF) switch (j) + { + case '@': /* Begin a response file */ + + if (IsResponseFile) + { + printf ("Nested command files are not supported\n"); + return (-1); + } + + if (AslDoResponseFile (AcpiGbl_Optarg)) + { + return (-1); + } + break; + + + case '2': /* ACPI 2.0 compatibility mode */ + Gbl_Acpi2 = TRUE; + break; + + + case 'b': /* Debug output options */ + switch (AcpiGbl_Optarg[0]) + { + case 'b': + AslCompilerdebug = 1; /* same as yydebug */ + DtParserdebug = 1; + PrParserdebug = 1; + break; + + case 'p': + AslCompilerdebug = 1; /* same as yydebug */ + DtParserdebug = 1; + PrParserdebug = 1; + break; + + case 't': + break; + + default: + printf ("Unknown option: -b%s\n", AcpiGbl_Optarg); + return (-1); + } + + /* Produce debug output file */ + + Gbl_DebugFlag = TRUE; + break; + + + case 'c': + switch (AcpiGbl_Optarg[0]) + { + case 'r': + Gbl_NoResourceChecking = TRUE; + break; + + default: + printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'd': /* Disassembler */ + switch (AcpiGbl_Optarg[0]) + { + case '^': + Gbl_DoCompile = FALSE; + break; + + case 'a': + Gbl_DoCompile = FALSE; + Gbl_DisassembleAll = TRUE; + break; + + case 'c': + break; + + default: + printf ("Unknown option: -d%s\n", AcpiGbl_Optarg); + return (-1); + } + + Gbl_DisasmFlag = TRUE; + break; + + + case 'D': /* Define a symbol */ + PrAddDefine (AcpiGbl_Optarg, NULL, TRUE); + break; + + + case 'e': /* External files for disassembler */ + Status = AcpiDmAddToExternalFileList (AcpiGbl_Optarg); + if (ACPI_FAILURE (Status)) + { + printf ("Could not add %s to external list\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'f': /* Ignore errors and force creation of aml file */ + Gbl_IgnoreErrors = TRUE; + break; + + + case 'G': + Gbl_CompileGeneric = TRUE; + break; + + + case 'g': /* Get all ACPI tables */ + + Gbl_GetAllTables = TRUE; + Gbl_DoCompile = FALSE; + break; + + + case 'h': + switch (AcpiGbl_Optarg[0]) + { + case '^': + HelpMessage (); + exit (0); + + case 'c': + UtDisplayConstantOpcodes (); + exit (0); + + case 'r': + /* reserved names */ + + ApDisplayReservedNames (); + exit (0); + + case 't': + UtDisplaySupportedTables (); + exit (0); + + default: + printf ("Unknown option: -h%s\n", AcpiGbl_Optarg); + return (-1); + } + + + case 'I': /* Add an include file search directory */ + FlAddIncludeDirectory (AcpiGbl_Optarg); + break; + + + case 'i': /* Output AML as an include file */ + switch (AcpiGbl_Optarg[0]) + { + case 'a': + + /* Produce assembly code include file */ + + Gbl_AsmIncludeOutputFlag = TRUE; + break; + + case 'c': + + /* Produce C include file */ + + Gbl_C_IncludeOutputFlag = TRUE; + break; + + default: + printf ("Unknown option: -i%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'l': /* Listing files */ + switch (AcpiGbl_Optarg[0]) + { + case '^': + /* Produce listing file (Mixed source/aml) */ + + Gbl_ListingFlag = TRUE; + break; + + case 'i': + /* Produce preprocessor output file */ + + Gbl_PreprocessorOutputFlag = TRUE; + break; + + case 'n': + /* Produce namespace file */ + + Gbl_NsOutputFlag = TRUE; + break; + + case 's': + /* Produce combined source file */ + + Gbl_SourceOutputFlag = TRUE; + break; + + default: + printf ("Unknown option: -l%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'm': /* Do not convert buffers to resource descriptors */ + AcpiGbl_NoResourceDisassembly = TRUE; + break; + + + case 'n': /* Parse only */ + Gbl_ParseOnlyFlag = TRUE; + break; + + + case 'o': /* Control compiler AML optimizations */ + switch (AcpiGbl_Optarg[0]) + { + case 'a': + + /* Disable all optimizations */ + + Gbl_FoldConstants = FALSE; + Gbl_IntegerOptimizationFlag = FALSE; + Gbl_ReferenceOptimizationFlag = FALSE; + break; + + case 'f': + + /* Disable folding on "normal" expressions */ + + Gbl_FoldConstants = FALSE; + break; + + case 'i': + + /* Disable integer optimization to constants */ + + Gbl_IntegerOptimizationFlag = FALSE; + break; + + case 'n': + + /* Disable named reference optimization */ + + Gbl_ReferenceOptimizationFlag = FALSE; + break; + + case 't': + + /* Display compile time(s) */ + + Gbl_CompileTimesFlag = TRUE; + break; + + default: + printf ("Unknown option: -c%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'P': /* Preprocessor options */ + switch (AcpiGbl_Optarg[0]) + { + case '^': /* Proprocess only, emit (.i) file */ + Gbl_PreprocessOnly = TRUE; + Gbl_PreprocessorOutputFlag = TRUE; + break; + + case 'n': /* Disable preprocessor */ + Gbl_PreprocessFlag = FALSE; + break; + + default: + printf ("Unknown option: -P%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'p': /* Override default AML output filename */ + Gbl_OutputFilenamePrefix = AcpiGbl_Optarg; + Gbl_UseDefaultAmlFilename = FALSE; + break; + + + case 'r': /* Override revision found in table header */ + Gbl_RevisionOverride = (UINT8) strtoul (AcpiGbl_Optarg, NULL, 0); + break; + + + case 's': /* Create AML in a source code file */ + switch (AcpiGbl_Optarg[0]) + { + case 'a': + + /* Produce assembly code output file */ + + Gbl_AsmOutputFlag = TRUE; + break; + + case 'c': + + /* Produce C hex output file */ + + Gbl_C_OutputFlag = TRUE; + break; + + default: + printf ("Unknown option: -s%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 't': /* Produce hex table output file */ + switch (AcpiGbl_Optarg[0]) + { + case 'a': + Gbl_HexOutputFlag = HEX_OUTPUT_ASM; + break; + + case 'c': + Gbl_HexOutputFlag = HEX_OUTPUT_C; + break; + + case 's': + Gbl_HexOutputFlag = HEX_OUTPUT_ASL; + break; + + default: + printf ("Unknown option: -t%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'T': /* Create a ACPI table template file */ + Gbl_DoTemplates = TRUE; + Gbl_TemplateSignature = AcpiGbl_Optarg; + break; + + + case 'v': /* Verbosity settings */ + switch (AcpiGbl_Optarg[0]) + { + case 'a': + /* Disable All error/warning messages */ + + Gbl_NoErrors = TRUE; + break; + + case 'i': + /* Less verbose error messages */ + + Gbl_VerboseErrors = FALSE; + break; + + case 'o': + Gbl_DisplayOptimizations = TRUE; + break; + + case 'r': + Gbl_DisplayRemarks = FALSE; + break; + + case 's': + Gbl_DoSignon = FALSE; + break; + + case 't': + Gbl_VerboseTemplates = TRUE; + break; + + default: + printf ("Unknown option: -v%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'w': /* Set warning levels */ + switch (AcpiGbl_Optarg[0]) + { + case '1': + Gbl_WarningLevel = ASL_WARNING; + break; + + case '2': + Gbl_WarningLevel = ASL_WARNING2; + break; + + case '3': + Gbl_WarningLevel = ASL_WARNING3; + break; + + case 'e': + Gbl_WarningsAsErrors = TRUE; + break; + + default: + printf ("Unknown option: -w%s\n", AcpiGbl_Optarg); + return (-1); + } + break; + + + case 'x': /* Set debug print output level */ + AcpiDbgLevel = strtoul (AcpiGbl_Optarg, NULL, 16); + break; + + + case 'z': + Gbl_UseOriginalCompilerId = TRUE; + break; + + + default: + return (-1); + } + + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: AslCommandLine + * + * PARAMETERS: argc/argv + * + * RETURN: Last argv index + * + * DESCRIPTION: Command line processing + * + ******************************************************************************/ + +static int +AslCommandLine ( + int argc, + char **argv) +{ + int BadCommandLine = 0; + ACPI_STATUS Status; + + + /* Minimum command line contains at least the command and an input file */ + + if (argc < 2) + { + printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); + Usage (); + exit (1); + } + + /* Process all command line options */ + + BadCommandLine = AslDoOptions (argc, argv, FALSE); + + if (Gbl_DoTemplates) + { + Status = DtCreateTemplates (Gbl_TemplateSignature); + if (ACPI_FAILURE (Status)) + { + exit (-1); + } + exit (1); + } + + /* Next parameter must be the input filename */ + + if (!argv[AcpiGbl_Optind] && + !Gbl_DisasmFlag && + !Gbl_GetAllTables) + { + printf ("Missing input filename\n"); + BadCommandLine = TRUE; + } + + if (Gbl_DoSignon) + { + printf (ACPI_COMMON_SIGNON (ASL_COMPILER_NAME)); + if (Gbl_IgnoreErrors) + { + printf ("Ignoring all errors, forcing AML file generation\n\n"); + } + } + + /* Abort if anything went wrong on the command line */ + + if (BadCommandLine) + { + printf ("\n"); + Usage (); + exit (1); + } + + return (AcpiGbl_Optind); +} + + +/******************************************************************************* + * + * FUNCTION: main + * + * PARAMETERS: Standard argc/argv + * + * RETURN: Program termination code + * + * DESCRIPTION: C main routine for the Asl Compiler. Handle command line + * options and begin the compile for each file on the command line + * + ******************************************************************************/ + +int ACPI_SYSTEM_XFACE +main ( + int argc, + char **argv) +{ + ACPI_STATUS Status; + int Index1; + int Index2; + + + AcpiGbl_ExternalFileList = NULL; + +#ifdef _DEBUG + _CrtSetDbgFlag (_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | + _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); +#endif + + /* Init and command line */ + + AslInitialize (); + PrInitializePreprocessor (); + Index1 = Index2 = AslCommandLine (argc, argv); + + /* Options that have no additional parameters or pathnames */ + + if (Gbl_GetAllTables) + { + Status = AslDoOneFile (NULL); + if (ACPI_FAILURE (Status)) + { + return (-1); + } + return (0); + } + + if (Gbl_DisassembleAll) + { + while (argv[Index1]) + { + Status = AslDoOnePathname (argv[Index1], AcpiDmAddToExternalFileList); + if (ACPI_FAILURE (Status)) + { + return (-1); + } + + Index1++; + } + } + + /* Process each pathname/filename in the list, with possible wildcards */ + + while (argv[Index2]) + { + Status = AslDoOnePathname (argv[Index2], AslDoOneFile); + if (ACPI_FAILURE (Status)) + { + return (-1); + } + + Index2++; + } + + if (AcpiGbl_ExternalFileList) + { + AcpiDmClearExternalFileList(); + } + + return (0); +} + + diff --git a/sys/contrib/dev/acpica/compiler/aslmap.c b/sys/contrib/dev/acpica/compiler/aslmap.c new file mode 100644 index 0000000..46d612c --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslmap.c @@ -0,0 +1,454 @@ + +/****************************************************************************** + * + * Module Name: aslmap - parser to AML opcode mapping table + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/include/amlcode.h> +#include <contrib/dev/acpica/include/acparser.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslmap") + + +/******************************************************************************* + * + * FUNCTION: AslMapNamedOpcodeToDataType + * + * PARAMETERS: Opcode - The Named AML opcode to map + * + * RETURN: The ACPI type associated with the named opcode + * + * DESCRIPTION: Convert a raw Named AML opcode to the associated data type. + * Named opcodes are a subset of the AML opcodes. + * + ******************************************************************************/ + +ACPI_OBJECT_TYPE +AslMapNamedOpcodeToDataType ( + UINT16 Opcode) +{ + const ACPI_OPCODE_INFO *OpInfo; + + + /* + * There are some differences from the opcode table types, we + * catch them here. + */ + OpInfo = AcpiPsGetOpcodeInfo (Opcode); + + if (Opcode == AML_INT_NAMEPATH_OP) + { + return (ACPI_TYPE_ANY); + } + + if (Opcode == AML_INT_METHODCALL_OP) + { + return (ACPI_TYPE_ANY); + } + + if (OpInfo->Flags & AML_NSOBJECT) + { + return (OpInfo->ObjectType); + } + + return (ACPI_TYPE_ANY); +} + + +/******************************************************************************* + * + * DATA STRUCTURE: AslKeywordMapping + * + * DESCRIPTION: Maps the ParseOpcode to the actual AML opcode. The parse + * opcodes are generated from Bison, and this table must + * track any additions to them. + * + * Each entry in the table contains the following items: + * + * AML opcode - Opcode that is written to the AML file + * Value - Value of the object to be written (if applicable) + * Flags - 1) Whether this opcode opens an AML "package". + * + ******************************************************************************/ +/* + * TBD: + * AccessAttrib + * AccessType + * AMlop for DMA? + * ObjectType keywords + * Register + */ + +const ASL_MAPPING_ENTRY AslKeywordMapping [] = +{ +/*! [Begin] no source code translation (keep the table structure) */ + + +/* ACCESSAS */ OP_TABLE_ENTRY (AML_INT_ACCESSFIELD_OP, 0, 0, 0), +/* ACCESSATTRIB_BLOCK */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_BLOCK, 0, 0), +/* ACCESSATTRIB_BLOCK_CALL */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_BLOCK_CALL, 0, 0), +/* ACCESSATTRIB_BYTE */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_BYTE, 0, 0), +/* ACCESSATTRIB_MULTIBYTE */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_MULTIBYTE, 0, 0), +/* ACCESSATTRIB_QUICK */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_QUICK, 0, 0), +/* ACCESSATTRIB_RAW_BYTES */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_RAW_BYTES, 0, 0), +/* ACCESSATTRIB_RAW_PROCESS */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_RAW_PROCESS, 0, 0), +/* ACCESSATTRIB_SND_RCV */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_SEND_RCV, 0, 0), +/* ACCESSATTRIB_WORD */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_WORD, 0, 0), +/* ACCESSATTRIB_WORD_CALL */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_WORD_CALL, 0, 0), +/* ACCESSTYPE_ANY */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ACCESS_ANY, 0, 0), +/* ACCESSTYPE_BUF */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ACCESS_BUFFER, 0, 0), +/* ACCESSTYPE_BYTE */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ACCESS_BYTE, 0, 0), +/* ACCESSTYPE_DWORD */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ACCESS_DWORD, 0, 0), +/* ACCESSTYPE_QWORD */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ACCESS_QWORD, 0, 0), +/* ACCESSTYPE_WORD */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ACCESS_WORD, 0, 0), +/* ACQUIRE */ OP_TABLE_ENTRY (AML_ACQUIRE_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* ADD */ OP_TABLE_ENTRY (AML_ADD_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* ADDRESSINGMODE_7BIT */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* ADDRESSINGMODE_10BIT */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* ADDRESSTYPE_ACPI */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* ADDRESSTYPE_MEMORY */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* ADDRESSTYPE_NVS */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* ADDRESSTYPE_RESERVED */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* ALIAS */ OP_TABLE_ENTRY (AML_ALIAS_OP, 0, 0, 0), +/* AND */ OP_TABLE_ENTRY (AML_BIT_AND_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* ARG0 */ OP_TABLE_ENTRY (AML_ARG0, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* ARG1 */ OP_TABLE_ENTRY (AML_ARG1, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* ARG2 */ OP_TABLE_ENTRY (AML_ARG2, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* ARG3 */ OP_TABLE_ENTRY (AML_ARG3, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* ARG4 */ OP_TABLE_ENTRY (AML_ARG4, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* ARG5 */ OP_TABLE_ENTRY (AML_ARG5, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* ARG6 */ OP_TABLE_ENTRY (AML_ARG6, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* BANKFIELD */ OP_TABLE_ENTRY (AML_BANK_FIELD_OP, 0, NODE_AML_PACKAGE, 0), +/* BITSPERBYTE_EIGHT */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* BITSPERBYTE_FIVE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* BITSPERBYTE_NINE */ OP_TABLE_ENTRY (AML_BYTE_OP, 4, 0, 0), +/* BITSPERBYTE_SEVEN */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* BITSPERBYTE_SIX */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* BREAK */ OP_TABLE_ENTRY (AML_BREAK_OP, 0, 0, 0), +/* BREAKPOINT */ OP_TABLE_ENTRY (AML_BREAK_POINT_OP, 0, 0, 0), +/* BUFFER */ OP_TABLE_ENTRY (AML_BUFFER_OP, 0, NODE_AML_PACKAGE, ACPI_BTYPE_BUFFER), +/* BUSMASTERTYPE_MASTER */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* BUSMASTERTYPE_NOTMASTER */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* BYTECONST */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, 0, 0, ACPI_BTYPE_INTEGER), +/* CASE */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* CLOCKPHASE_FIRST */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* CLOCKPHASE_SECOND */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* CLOCKPOLARITY_HIGH */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* CLOCKPOLARITY_LOW */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* CONCATENATE */ OP_TABLE_ENTRY (AML_CONCAT_OP, 0, 0, ACPI_BTYPE_COMPUTE_DATA), +/* CONCATENATERESTEMPLATE */ OP_TABLE_ENTRY (AML_CONCAT_RES_OP, 0, 0, ACPI_BTYPE_BUFFER), +/* CONDREFOF */ OP_TABLE_ENTRY (AML_COND_REF_OF_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* CONNECTION */ OP_TABLE_ENTRY (AML_INT_CONNECTION_OP, 0, 0, 0), +/* CONTINUE */ OP_TABLE_ENTRY (AML_CONTINUE_OP, 0, 0, 0), +/* COPY */ OP_TABLE_ENTRY (AML_COPY_OP, 0, 0, ACPI_BTYPE_DATA_REFERENCE), +/* CREATEBITFIELD */ OP_TABLE_ENTRY (AML_CREATE_BIT_FIELD_OP, 0, 0, 0), +/* CREATEBYTEFIELD */ OP_TABLE_ENTRY (AML_CREATE_BYTE_FIELD_OP, 0, 0, 0), +/* CREATEDWORDFIELD */ OP_TABLE_ENTRY (AML_CREATE_DWORD_FIELD_OP, 0, 0, 0), +/* CREATEFIELD */ OP_TABLE_ENTRY (AML_CREATE_FIELD_OP, 0, 0, 0), +/* CREATEQWORDFIELD */ OP_TABLE_ENTRY (AML_CREATE_QWORD_FIELD_OP, 0, 0, 0), +/* CREATEWORDFIELD */ OP_TABLE_ENTRY (AML_CREATE_WORD_FIELD_OP, 0, 0, 0), +/* DATABUFFER */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* DATATABLEREGION */ OP_TABLE_ENTRY (AML_DATA_REGION_OP, 0, 0, 0), +/* DEBUG */ OP_TABLE_ENTRY (AML_DEBUG_OP, 0, 0, ACPI_BTYPE_DEBUG_OBJECT), +/* DECODETYPE_POS */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* DECODETYPE_SUB */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* DECREMENT */ OP_TABLE_ENTRY (AML_DECREMENT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* DEFAULT */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* DEFAULT_ARG */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* DEFINITIONBLOCK */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* DEREFOF */ OP_TABLE_ENTRY (AML_DEREF_OF_OP, 0, 0, ACPI_BTYPE_DATA_REFERENCE | ACPI_BTYPE_STRING), +/* DEVICE */ OP_TABLE_ENTRY (AML_DEVICE_OP, 0, NODE_AML_PACKAGE, 0), +/* DEVICEPOLARITY_HIGH */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* DEVICEPOLARITY_LOW */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* DIVIDE */ OP_TABLE_ENTRY (AML_DIVIDE_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* DMA */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* DMATYPE_A */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* DMATYPE_COMPATIBILITY */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* DMATYPE_B */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* DMATYPE_F */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* DWORDCONST */ OP_TABLE_ENTRY (AML_RAW_DATA_DWORD, 0, 0, ACPI_BTYPE_INTEGER), +/* DWORDIO */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* DWORDMEMORY */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* DWORDSPACE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* EISAID */ OP_TABLE_ENTRY (AML_DWORD_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* ELSE */ OP_TABLE_ENTRY (AML_ELSE_OP, 0, NODE_AML_PACKAGE, 0), +/* ELSEIF */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, NODE_AML_PACKAGE, 0), +/* ENDDEPENDENTFN */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* ENDIAN_BIG */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* ENDIAN_LITTLE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* ENDTAG */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* ERRORNODE */ OP_TABLE_ENTRY (AML_NOOP_OP, 0, 0, 0), +/* EVENT */ OP_TABLE_ENTRY (AML_EVENT_OP, 0, 0, 0), +/* EXTENDEDIO */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* EXTENDEDMEMORY */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* EXTENDEDSPACE */ OP_TABLE_ENTRY (AML_RAW_DATA_QWORD, 0, 0, ACPI_BTYPE_INTEGER), +/* EXTERNAL */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* FATAL */ OP_TABLE_ENTRY (AML_FATAL_OP, 0, 0, 0), +/* FIELD */ OP_TABLE_ENTRY (AML_FIELD_OP, 0, NODE_AML_PACKAGE, 0), +/* FINDSETLEFTBIT */ OP_TABLE_ENTRY (AML_FIND_SET_LEFT_BIT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* FINDSETRIGHTBIT */ OP_TABLE_ENTRY (AML_FIND_SET_RIGHT_BIT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* FIXEDDMA */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* FIXEDIO */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* FLOWCONTROL_HW */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* FLOWCONTROL_NONE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* FLOWCONTROL_SW */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* FROMBCD */ OP_TABLE_ENTRY (AML_FROM_BCD_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* FUNCTION */ OP_TABLE_ENTRY (AML_METHOD_OP, 0, NODE_AML_PACKAGE, 0), +/* GPIOINT */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* GPIOIO */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* I2CSERIALBUS */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* IF */ OP_TABLE_ENTRY (AML_IF_OP, 0, NODE_AML_PACKAGE, 0), +/* INCLUDE */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* INCLUDE_END */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* INCREMENT */ OP_TABLE_ENTRY (AML_INCREMENT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* INDEX */ OP_TABLE_ENTRY (AML_INDEX_OP, 0, 0, ACPI_BTYPE_REFERENCE), +/* INDEXFIELD */ OP_TABLE_ENTRY (AML_INDEX_FIELD_OP, 0, NODE_AML_PACKAGE, 0), +/* INTEGER */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* INTERRUPT */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* INTLEVEL_ACTIVEBOTH */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* INTLEVEL_ACTIVEHIGH */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* INTLEVEL_ACTIVELOW */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* INTTYPE_EDGE */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* INTTYPE_LEVEL */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* IO */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* IODECODETYPE_10 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* IODECODETYPE_16 */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* IORESTRICT_IN */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* IORESTRICT_NONE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* IORESTRICT_OUT */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* IORESTRICT_PRESERVE */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* IRQ */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* IRQNOFLAGS */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* LAND */ OP_TABLE_ENTRY (AML_LAND_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LEQUAL */ OP_TABLE_ENTRY (AML_LEQUAL_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LGREATER */ OP_TABLE_ENTRY (AML_LGREATER_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LGREATEREQUAL */ OP_TABLE_ENTRY (AML_LGREATEREQUAL_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LLESS */ OP_TABLE_ENTRY (AML_LLESS_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LLESSEQUAL */ OP_TABLE_ENTRY (AML_LLESSEQUAL_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LNOT */ OP_TABLE_ENTRY (AML_LNOT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LNOTEQUAL */ OP_TABLE_ENTRY (AML_LNOTEQUAL_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* LOAD */ OP_TABLE_ENTRY (AML_LOAD_OP, 0, 0, 0), +/* LOADTABLE */ OP_TABLE_ENTRY (AML_LOAD_TABLE_OP, 0, 0, ACPI_BTYPE_DDB_HANDLE), +/* LOCAL0 */ OP_TABLE_ENTRY (AML_LOCAL0, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCAL1 */ OP_TABLE_ENTRY (AML_LOCAL1, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCAL2 */ OP_TABLE_ENTRY (AML_LOCAL2, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCAL3 */ OP_TABLE_ENTRY (AML_LOCAL3, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCAL4 */ OP_TABLE_ENTRY (AML_LOCAL4, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCAL5 */ OP_TABLE_ENTRY (AML_LOCAL5, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCAL6 */ OP_TABLE_ENTRY (AML_LOCAL6, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCAL7 */ OP_TABLE_ENTRY (AML_LOCAL7, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* LOCKRULE_LOCK */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_LOCK_ALWAYS, 0, 0), +/* LOCKRULE_NOLOCK */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_LOCK_NEVER, 0, 0), +/* LOR */ OP_TABLE_ENTRY (AML_LOR_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* MATCH */ OP_TABLE_ENTRY (AML_MATCH_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* MATCHTYPE_MEQ */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, MATCH_MEQ, 0, ACPI_BTYPE_INTEGER), +/* MATCHTYPE_MGE */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, MATCH_MGE, 0, ACPI_BTYPE_INTEGER), +/* MATCHTYPE_MGT */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, MATCH_MGT, 0, ACPI_BTYPE_INTEGER), +/* MATCHTYPE_MLE */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, MATCH_MLE, 0, ACPI_BTYPE_INTEGER), +/* MATCHTYPE_MLT */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, MATCH_MLT, 0, ACPI_BTYPE_INTEGER), +/* MATCHTYPE_MTR */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, MATCH_MTR, 0, ACPI_BTYPE_INTEGER), +/* MAXTYPE_FIXED */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* MAXTYPE_NOTFIXED */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* MEMORY24 */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* MEMORY32 */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* MEMORY32FIXED */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* MEMTYPE_CACHEABLE */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* MEMTYPE_NONCACHEABLE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* MEMTYPE_PREFETCHABLE */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* MEMTYPE_WRITECOMBINING */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* METHOD */ OP_TABLE_ENTRY (AML_METHOD_OP, 0, NODE_AML_PACKAGE, 0), +/* METHODCALL */ OP_TABLE_ENTRY (AML_INT_METHODCALL_OP, 0, 0, ACPI_BTYPE_OBJECTS_AND_REFS), +/* MID */ OP_TABLE_ENTRY (AML_MID_OP, 0, 0, ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER), +/* MINTYPE_FIXED */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* MINTYPE_NOTFIXED */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* MOD */ OP_TABLE_ENTRY (AML_MOD_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* MULTIPLY */ OP_TABLE_ENTRY (AML_MULTIPLY_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* MUTEX */ OP_TABLE_ENTRY (AML_MUTEX_OP, 0, 0, 0), +/* NAME */ OP_TABLE_ENTRY (AML_NAME_OP, 0, 0, 0), +/* NAMESEG */ OP_TABLE_ENTRY (AML_INT_NAMEPATH_OP, 0, 0, 0), +/* NAMESTRING */ OP_TABLE_ENTRY (AML_INT_NAMEPATH_OP, 0, 0, 0), +/* NAND */ OP_TABLE_ENTRY (AML_BIT_NAND_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* NOOP */ OP_TABLE_ENTRY (AML_NOOP_OP, 0, 0, 0), +/* NOR */ OP_TABLE_ENTRY (AML_BIT_NOR_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* NOT */ OP_TABLE_ENTRY (AML_BIT_NOT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* NOTIFY */ OP_TABLE_ENTRY (AML_NOTIFY_OP, 0, 0, 0), +/* OBJECTTYPE */ OP_TABLE_ENTRY (AML_TYPE_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* OBJECTTYPE_BFF */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_BUFFER_FIELD, 0, 0), +/* OBJECTTYPE_BUF */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_BUFFER, 0, 0), +/* OBJECTTYPE_DDB */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_DDB_HANDLE, 0, 0), +/* OBJECTTYPE_DEV */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_DEVICE, 0, 0), +/* OBJECTTYPE_EVT */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_EVENT, 0, 0), +/* OBJECTTYPE_FLD */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_FIELD_UNIT, 0, 0), +/* OBJECTTYPE_INT */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_INTEGER, 0, 0), +/* OBJECTTYPE_MTH */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_METHOD, 0, 0), +/* OBJECTTYPE_MTX */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_MUTEX, 0, 0), +/* OBJECTTYPE_OPR */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_REGION, 0, 0), +/* OBJECTTYPE_PKG */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_PACKAGE, 0, 0), +/* OBJECTTYPE_POW */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_POWER, 0, 0), +/* OBJECTTYPE_PRO */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_PROCESSOR, 0, 0), +/* OBJECTTYPE_STR */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_STRING, 0, 0), +/* OBJECTTYPE_THZ */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_THERMAL, 0, 0), +/* OBJECTTYPE_UNK */ OP_TABLE_ENTRY (AML_BYTE_OP, ACPI_TYPE_ANY, 0, 0), +/* OFFSET */ OP_TABLE_ENTRY (AML_INT_RESERVEDFIELD_OP, 0, 0, 0), +/* ONE */ OP_TABLE_ENTRY (AML_ONE_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* ONES */ OP_TABLE_ENTRY (AML_ONES_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* OPERATIONREGION */ OP_TABLE_ENTRY (AML_REGION_OP, 0, 0, 0), +/* OR */ OP_TABLE_ENTRY (AML_BIT_OR_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* PACKAGE */ OP_TABLE_ENTRY (AML_PACKAGE_OP, 0, NODE_AML_PACKAGE, ACPI_BTYPE_PACKAGE), +/* PACKAGEP_LENGTH */ OP_TABLE_ENTRY (AML_PACKAGE_LENGTH, 0, NODE_AML_PACKAGE, 0), +/* PARITYTYPE_EVEN */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* PARITYTYPE_MARK */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* PARITYTYPE_NONE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* PARITYTYPE_ODD */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* PARITYTYPE_SPACE */ OP_TABLE_ENTRY (AML_BYTE_OP, 4, 0, 0), +/* PIN_NOPULL */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* PIN_PULLDEFAULT */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* PIN_PULLDOWN */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* PIN_PULLUP */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* POWERRESOURCE */ OP_TABLE_ENTRY (AML_POWER_RES_OP, 0, NODE_AML_PACKAGE, 0), +/* PROCESSOR */ OP_TABLE_ENTRY (AML_PROCESSOR_OP, 0, NODE_AML_PACKAGE, 0), +/* QWORDCONST */ OP_TABLE_ENTRY (AML_RAW_DATA_QWORD, 0, 0, ACPI_BTYPE_INTEGER), +/* QWORDIO */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* QWORDMEMORY */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* QWORDSPACE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* RANGE_TYPE_ENTIRE */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* RANGE_TYPE_ISAONLY */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* RANGE_TYPE_NONISAONLY */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* RAW_DATA */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* READWRITETYPE_BOTH */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* READWRITETYPE_READONLY */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* REFOF */ OP_TABLE_ENTRY (AML_REF_OF_OP, 0, 0, ACPI_BTYPE_REFERENCE), +/* REGIONSPACE_CMOS */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_CMOS, 0, 0), +/* REGIONSPACE_EC */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_EC, 0, 0), +/* REGIONSPACE_FFIXEDHW */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_FIXED_HARDWARE, 0, 0), +/* REGIONSPACE_GPIO */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_GPIO, 0, 0), +/* REGIONSPACE_GSBUS */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_GSBUS, 0, 0), +/* REGIONSPACE_IO */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_SYSTEM_IO, 0, 0), +/* REGIONSPACE_IPMI */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_IPMI, 0, 0), +/* REGIONSPACE_MEM */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_SYSTEM_MEMORY, 0, 0), +/* REGIONSPACE_PCI */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_PCI_CONFIG, 0, 0), +/* REGIONSPACE_PCIBAR */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_PCI_BAR_TARGET, 0, 0), +/* REGIONSPACE_SMBUS */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_SMBUS, 0, 0), +/* REGISTER */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* RELEASE */ OP_TABLE_ENTRY (AML_RELEASE_OP, 0, 0, 0), +/* RESERVED_BYTES */ OP_TABLE_ENTRY (AML_INT_RESERVEDFIELD_OP, 0, 0, 0), +/* RESET */ OP_TABLE_ENTRY (AML_RESET_OP, 0, 0, 0), +/* RESOURCETEMPLATE */ OP_TABLE_ENTRY (AML_BUFFER_OP, 0, 0, ACPI_BTYPE_BUFFER), +/* RESOURCETYPE_CONSUMER */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* RESOURCETYPE_PRODUCER */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* RETURN */ OP_TABLE_ENTRY (AML_RETURN_OP, 0, 0, 0), +/* REVISION */ OP_TABLE_ENTRY (AML_REVISION_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* SCOPE */ OP_TABLE_ENTRY (AML_SCOPE_OP, 0, NODE_AML_PACKAGE, 0), +/* SERIALIZERULE_NOTSERIAL */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* SERIALIZERULE_SERIAL */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* SHARETYPE_EXCLUSIVE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* SHARETYPE_EXCLUSIVEWAKE */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* SHARETYPE_SHARED */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* SHARETYPE_SHAREDWAKE */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* SHIFTLEFT */ OP_TABLE_ENTRY (AML_SHIFT_LEFT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* SHIFTRIGHT */ OP_TABLE_ENTRY (AML_SHIFT_RIGHT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* SIGNAL */ OP_TABLE_ENTRY (AML_SIGNAL_OP, 0, 0, 0), +/* SIZEOF */ OP_TABLE_ENTRY (AML_SIZE_OF_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* SLAVEMODE_CONTROLLERINIT */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* SLAVEMODE_DEVICEINIT */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* SLEEP */ OP_TABLE_ENTRY (AML_SLEEP_OP, 0, 0, 0), +/* SPISERIALBUS */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* STALL */ OP_TABLE_ENTRY (AML_STALL_OP, 0, 0, 0), +/* STARTDEPENDENTFN */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* STARTDEPENDENTFN_NOPRI */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* STOPBITS_ONE */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* STOPBITS_ONEPLUSHALF */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* STOPBITS_TWO */ OP_TABLE_ENTRY (AML_BYTE_OP, 3, 0, 0), +/* STOPBITS_ZERO */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* STORE */ OP_TABLE_ENTRY (AML_STORE_OP, 0, 0, ACPI_BTYPE_DATA_REFERENCE), +/* STRING_LITERAL */ OP_TABLE_ENTRY (AML_STRING_OP, 0, 0, ACPI_BTYPE_STRING), +/* SUBTRACT */ OP_TABLE_ENTRY (AML_SUBTRACT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* SWITCH */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* THERMALZONE */ OP_TABLE_ENTRY (AML_THERMAL_ZONE_OP, 0, NODE_AML_PACKAGE, 0), +/* TIMER */ OP_TABLE_ENTRY (AML_TIMER_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* TOBCD */ OP_TABLE_ENTRY (AML_TO_BCD_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* TOBUFFER */ OP_TABLE_ENTRY (AML_TO_BUFFER_OP, 0, 0, ACPI_BTYPE_BUFFER), +/* TODECIMALSTRING */ OP_TABLE_ENTRY (AML_TO_DECSTRING_OP, 0, 0, ACPI_BTYPE_STRING), +/* TOHEXSTRING */ OP_TABLE_ENTRY (AML_TO_HEXSTRING_OP, 0, 0, ACPI_BTYPE_STRING), +/* TOINTEGER */ OP_TABLE_ENTRY (AML_TO_INTEGER_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* TOSTRING */ OP_TABLE_ENTRY (AML_TO_STRING_OP, 0, 0, ACPI_BTYPE_STRING), +/* TOUUID */ OP_TABLE_ENTRY (AML_DWORD_OP, 0, NODE_AML_PACKAGE, ACPI_BTYPE_INTEGER), +/* TRANSLATIONTYPE_DENSE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* TRANSLATIONTYPE_SPARSE */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* TYPE_STATIC */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* TYPE_TRANSLATION */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* UART_SERIALBUS */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0), +/* UNICODE */ OP_TABLE_ENTRY (AML_BUFFER_OP, 0, NODE_AML_PACKAGE, 0), +/* UNLOAD */ OP_TABLE_ENTRY (AML_UNLOAD_OP, 0, 0, 0), +/* UPDATERULE_ONES */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_UPDATE_WRITE_AS_ONES, 0, 0), +/* UPDATERULE_PRESERVE */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_UPDATE_PRESERVE, 0, 0), +/* UPDATERULE_ZEROS */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_UPDATE_WRITE_AS_ZEROS,0, 0), +/* VAR_PACKAGE */ OP_TABLE_ENTRY (AML_VAR_PACKAGE_OP, 0, NODE_AML_PACKAGE, ACPI_BTYPE_PACKAGE), +/* VENDORLONG */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* VENDORSHORT */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* WAIT */ OP_TABLE_ENTRY (AML_WAIT_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* WHILE */ OP_TABLE_ENTRY (AML_WHILE_OP, 0, NODE_AML_PACKAGE, 0), +/* WIREMODE_FOUR */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* WIREMODE_THREE */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* WORDBUSNUMBER */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* WORDCONST */ OP_TABLE_ENTRY (AML_RAW_DATA_WORD, 0, 0, ACPI_BTYPE_INTEGER), +/* WORDIO */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* WORDSPACE */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERSIZE_8 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERSIZE_16 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERSIZE_32 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERSIZE_64 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERSIZE_128 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERSIZE_256 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERTYPE_8 */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0), +/* XFERTYPE_8_16 */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0), +/* XFERTYPE_16 */ OP_TABLE_ENTRY (AML_BYTE_OP, 2, 0, 0), +/* XOR */ OP_TABLE_ENTRY (AML_BIT_XOR_OP, 0, 0, ACPI_BTYPE_INTEGER), +/* ZERO */ OP_TABLE_ENTRY (AML_ZERO_OP, 0, 0, ACPI_BTYPE_INTEGER), + +/*! [End] no source code translation !*/ + +}; + + diff --git a/sys/contrib/dev/acpica/compiler/aslmessages.h b/sys/contrib/dev/acpica/compiler/aslmessages.h new file mode 100644 index 0000000..45d50da --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslmessages.h @@ -0,0 +1,418 @@ + +/****************************************************************************** + * + * Module Name: aslmessages.h - Compiler error/warning messages + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#ifndef __ASLMESSAGES_H +#define __ASLMESSAGES_H + + +#define ASL_WARNING 0 +#define ASL_WARNING2 1 +#define ASL_WARNING3 2 +#define ASL_ERROR 3 +#define ASL_REMARK 4 +#define ASL_OPTIMIZATION 5 +#define ASL_NUM_REPORT_LEVELS 6 + + +/* Values for all compiler messages */ + +typedef enum +{ + ASL_MSG_RESERVED = 0, + + ASL_MSG_ALIGNMENT, + ASL_MSG_ALPHANUMERIC_STRING, + ASL_MSG_AML_NOT_IMPLEMENTED, + ASL_MSG_ARG_COUNT_HI, + ASL_MSG_ARG_COUNT_LO, + ASL_MSG_ARG_INIT, + ASL_MSG_BACKWARDS_OFFSET, + ASL_MSG_BUFFER_LENGTH, + ASL_MSG_CLOSE, + ASL_MSG_COMPILER_INTERNAL, + ASL_MSG_COMPILER_RESERVED, + ASL_MSG_CONNECTION_MISSING, + ASL_MSG_CONNECTION_INVALID, + ASL_MSG_CONSTANT_EVALUATION, + ASL_MSG_CONSTANT_FOLDED, + ASL_MSG_CORE_EXCEPTION, + ASL_MSG_DEBUG_FILE_OPEN, + ASL_MSG_DEBUG_FILENAME, + ASL_MSG_DEPENDENT_NESTING, + ASL_MSG_DMA_CHANNEL, + ASL_MSG_DMA_LIST, + ASL_MSG_DUPLICATE_CASE, + ASL_MSG_DUPLICATE_ITEM, + ASL_MSG_EARLY_EOF, + ASL_MSG_ENCODING_LENGTH, + ASL_MSG_EX_INTERRUPT_LIST, + ASL_MSG_EX_INTERRUPT_LIST_MIN, + ASL_MSG_EX_INTERRUPT_NUMBER, + ASL_MSG_FIELD_ACCESS_WIDTH, + ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, + ASL_MSG_FIELD_UNIT_OFFSET, + ASL_MSG_GPE_NAME_CONFLICT, + ASL_MSG_HID_LENGTH, + ASL_MSG_HID_PREFIX, + ASL_MSG_HID_SUFFIX, + ASL_MSG_INCLUDE_FILE_OPEN, + ASL_MSG_INPUT_FILE_OPEN, + ASL_MSG_INTEGER_LENGTH, + ASL_MSG_INTEGER_OPTIMIZATION, + ASL_MSG_INTERRUPT_LIST, + ASL_MSG_INTERRUPT_NUMBER, + ASL_MSG_INVALID_ACCESS_SIZE, + ASL_MSG_INVALID_ADDR_FLAGS, + ASL_MSG_INVALID_CONSTANT_OP, + ASL_MSG_INVALID_EISAID, + ASL_MSG_INVALID_ESCAPE, + ASL_MSG_INVALID_GRAN_FIXED, + ASL_MSG_INVALID_GRANULARITY, + ASL_MSG_INVALID_LENGTH, + ASL_MSG_INVALID_LENGTH_FIXED, + ASL_MSG_INVALID_MIN_MAX, + ASL_MSG_INVALID_OPERAND, + ASL_MSG_INVALID_PERFORMANCE, + ASL_MSG_INVALID_PRIORITY, + ASL_MSG_INVALID_STRING, + ASL_MSG_INVALID_TARGET, + ASL_MSG_INVALID_TIME, + ASL_MSG_INVALID_TYPE, + ASL_MSG_INVALID_UUID, + ASL_MSG_ISA_ADDRESS, + ASL_MSG_LEADING_ASTERISK, + ASL_MSG_LIST_LENGTH_LONG, + ASL_MSG_LIST_LENGTH_SHORT, + ASL_MSG_LISTING_FILE_OPEN, + ASL_MSG_LISTING_FILENAME, + ASL_MSG_LOCAL_INIT, + ASL_MSG_LOCAL_OUTSIDE_METHOD, + ASL_MSG_LONG_LINE, + ASL_MSG_MEMORY_ALLOCATION, + ASL_MSG_MISSING_ENDDEPENDENT, + ASL_MSG_MISSING_STARTDEPENDENT, + ASL_MSG_MULTIPLE_DEFAULT, + ASL_MSG_MULTIPLE_TYPES, + ASL_MSG_NAME_EXISTS, + ASL_MSG_NAME_OPTIMIZATION, + ASL_MSG_NAMED_OBJECT_IN_WHILE, + ASL_MSG_NESTED_COMMENT, + ASL_MSG_NO_CASES, + ASL_MSG_NO_REGION, + ASL_MSG_NO_RETVAL, + ASL_MSG_NO_WHILE, + ASL_MSG_NON_ASCII, + ASL_MSG_NON_ZERO, + ASL_MSG_NOT_EXIST, + ASL_MSG_NOT_FOUND, + ASL_MSG_NOT_METHOD, + ASL_MSG_NOT_PARAMETER, + ASL_MSG_NOT_REACHABLE, + ASL_MSG_NOT_REFERENCED, + ASL_MSG_NULL_DESCRIPTOR, + ASL_MSG_NULL_STRING, + ASL_MSG_OPEN, + ASL_MSG_OUTPUT_FILE_OPEN, + ASL_MSG_OUTPUT_FILENAME, + ASL_MSG_PACKAGE_LENGTH, + ASL_MSG_PREPROCESSOR_FILENAME, + ASL_MSG_READ, + ASL_MSG_RECURSION, + ASL_MSG_REGION_BUFFER_ACCESS, + ASL_MSG_REGION_BYTE_ACCESS, + ASL_MSG_RESERVED_ARG_COUNT_HI, + ASL_MSG_RESERVED_ARG_COUNT_LO, + ASL_MSG_RESERVED_METHOD, + ASL_MSG_RESERVED_NO_RETURN_VAL, + ASL_MSG_RESERVED_OPERAND_TYPE, + ASL_MSG_RESERVED_RETURN_VALUE, + ASL_MSG_RESERVED_USE, + ASL_MSG_RESERVED_WORD, + ASL_MSG_RESOURCE_FIELD, + ASL_MSG_RESOURCE_INDEX, + ASL_MSG_RESOURCE_LIST, + ASL_MSG_RESOURCE_SOURCE, + ASL_MSG_RESULT_NOT_USED, + ASL_MSG_RETURN_TYPES, + ASL_MSG_SCOPE_FWD_REF, + ASL_MSG_SCOPE_TYPE, + ASL_MSG_SEEK, + ASL_MSG_SERIALIZED, + ASL_MSG_SINGLE_NAME_OPTIMIZATION, + ASL_MSG_SOME_NO_RETVAL, + ASL_MSG_STRING_LENGTH, + ASL_MSG_SWITCH_TYPE, + ASL_MSG_SYNC_LEVEL, + ASL_MSG_SYNTAX, + ASL_MSG_TABLE_SIGNATURE, + ASL_MSG_TAG_LARGER, + ASL_MSG_TAG_SMALLER, + ASL_MSG_TIMEOUT, + ASL_MSG_TOO_MANY_TEMPS, + ASL_MSG_UNKNOWN_RESERVED_NAME, + ASL_MSG_UNREACHABLE_CODE, + ASL_MSG_UNSUPPORTED, + ASL_MSG_UPPER_CASE, + ASL_MSG_VENDOR_LIST, + ASL_MSG_WRITE, + + /* These messages are used by the Preprocessor only */ + + ASL_MSG_DIRECTIVE_SYNTAX, + ASL_MSG_ENDIF_MISMATCH, + ASL_MSG_ERROR_DIRECTIVE, + ASL_MSG_EXISTING_NAME, + ASL_MSG_INVALID_INVOCATION, + ASL_MSG_MACRO_SYNTAX, + ASL_MSG_TOO_MANY_ARGUMENTS, + ASL_MSG_UNKNOWN_DIRECTIVE, + ASL_MSG_UNKNOWN_PRAGMA, + + + /* These messages are used by the data table compiler only */ + + ASL_MSG_BUFFER_ELEMENT, + ASL_MSG_DIVIDE_BY_ZERO, + ASL_MSG_FLAG_VALUE, + ASL_MSG_INTEGER_SIZE, + ASL_MSG_INVALID_EXPRESSION, + ASL_MSG_INVALID_FIELD_NAME, + ASL_MSG_INVALID_HEX_INTEGER, + ASL_MSG_OEM_TABLE, + ASL_MSG_RESERVED_VALUE, + ASL_MSG_UNKNOWN_LABEL, + ASL_MSG_UNKNOWN_SUBTABLE, + ASL_MSG_UNKNOWN_TABLE, + ASL_MSG_ZERO_VALUE + +} ASL_MESSAGE_IDS; + + +#ifdef ASL_EXCEPTIONS + +/* Actual message strings for each compiler message */ + +char *AslMessages [] = { +/* The zeroth message is reserved */ "", +/* ASL_MSG_ALIGNMENT */ "Must be a multiple of alignment/granularity value", +/* ASL_MSG_ALPHANUMERIC_STRING */ "String must be entirely alphanumeric", +/* ASL_MSG_AML_NOT_IMPLEMENTED */ "Opcode is not implemented in compiler AML code generator", +/* ASL_MSG_ARG_COUNT_HI */ "Too many arguments", +/* ASL_MSG_ARG_COUNT_LO */ "Too few arguments", +/* ASL_MSG_ARG_INIT */ "Method argument is not initialized", +/* ASL_MSG_BACKWARDS_OFFSET */ "Invalid backwards offset", +/* ASL_MSG_BUFFER_LENGTH */ "Effective AML buffer length is zero", +/* ASL_MSG_CLOSE */ "Could not close file", +/* ASL_MSG_COMPILER_INTERNAL */ "Internal compiler error", +/* ASL_MSG_COMPILER_RESERVED */ "Use of compiler reserved name", +/* ASL_MSG_CONNECTION_MISSING */ "A Connection operator is required for this field SpaceId", +/* ASL_MSG_CONNECTION_INVALID */ "Invalid OpRegion SpaceId for use of Connection operator", +/* ASL_MSG_CONSTANT_EVALUATION */ "Could not evaluate constant expression", +/* ASL_MSG_CONSTANT_FOLDED */ "Constant expression evaluated and reduced", +/* ASL_MSG_CORE_EXCEPTION */ "From ACPI CA Subsystem", +/* ASL_MSG_DEBUG_FILE_OPEN */ "Could not open debug file", +/* ASL_MSG_DEBUG_FILENAME */ "Could not create debug filename", +/* ASL_MSG_DEPENDENT_NESTING */ "Dependent function macros cannot be nested",\ +/* ASL_MSG_DMA_CHANNEL */ "Invalid DMA channel (must be 0-7)", +/* ASL_MSG_DMA_LIST */ "Too many DMA channels (8 max)", +/* ASL_MSG_DUPLICATE_CASE */ "Case value already specified", +/* ASL_MSG_DUPLICATE_ITEM */ "Duplicate value in list", +/* ASL_MSG_EARLY_EOF */ "Premature end-of-file reached", +/* ASL_MSG_ENCODING_LENGTH */ "Package length too long to encode", +/* ASL_MSG_EX_INTERRUPT_LIST */ "Too many interrupts (255 max)", +/* ASL_MSG_EX_INTERRUPT_LIST_MIN */ "Too few interrupts (1 minimum required)", +/* ASL_MSG_EX_INTERRUPT_NUMBER */ "Invalid interrupt number (must be 32 bits)", +/* ASL_MSG_FIELD_ACCESS_WIDTH */ "Access width is greater than region size", +/* ASL_MSG_FIELD_UNIT_ACCESS_WIDTH */ "Access width of Field Unit extends beyond region limit", +/* ASL_MSG_FIELD_UNIT_OFFSET */ "Field Unit extends beyond region limit", +/* ASL_MSG_GPE_NAME_CONFLICT */ "Name conflicts with a previous GPE method", +/* ASL_MSG_HID_LENGTH */ "_HID string must be exactly 7 or 8 characters", +/* ASL_MSG_HID_PREFIX */ "_HID prefix must be all uppercase or decimal digits", +/* ASL_MSG_HID_SUFFIX */ "_HID suffix must be all hex digits", +/* ASL_MSG_INCLUDE_FILE_OPEN */ "Could not open include file", +/* ASL_MSG_INPUT_FILE_OPEN */ "Could not open input file", +/* ASL_MSG_INTEGER_LENGTH */ "64-bit integer in 32-bit table, truncating", +/* ASL_MSG_INTEGER_OPTIMIZATION */ "Integer optimized to single-byte AML opcode", +/* ASL_MSG_INTERRUPT_LIST */ "Too many interrupts (16 max)", +/* ASL_MSG_INTERRUPT_NUMBER */ "Invalid interrupt number (must be 0-15)", +/* ASL_MSG_INVALID_ACCESS_SIZE */ "Invalid AccessSize (Maximum is 4 - QWord access)", +/* ASL_MSG_INVALID_ADDR_FLAGS */ "Invalid combination of Length and Min/Max fixed flags", +/* ASL_MSG_INVALID_CONSTANT_OP */ "Invalid operator in constant expression (not type 3/4/5)", +/* ASL_MSG_INVALID_EISAID */ "EISAID string must be of the form \"UUUXXXX\" (3 uppercase, 4 hex digits)", +/* ASL_MSG_INVALID_ESCAPE */ "Invalid or unknown escape sequence", +/* ASL_MSG_INVALID_GRAN_FIXED */ "Granularity must be zero for fixed Min/Max", +/* ASL_MSG_INVALID_GRANULARITY */ "Granularity must be zero or a power of two minus one", +/* ASL_MSG_INVALID_LENGTH */ "Length is larger than Min/Max window", +/* ASL_MSG_INVALID_LENGTH_FIXED */ "Length is not equal to fixed Min/Max window", +/* ASL_MSG_INVALID_MIN_MAX */ "Address Min is greater than Address Max", +/* ASL_MSG_INVALID_OPERAND */ "Invalid operand", +/* ASL_MSG_INVALID_PERFORMANCE */ "Invalid performance/robustness value", +/* ASL_MSG_INVALID_PRIORITY */ "Invalid priority value", +/* ASL_MSG_INVALID_STRING */ "Invalid Hex/Octal Escape - Non-ASCII or NULL", +/* ASL_MSG_INVALID_TARGET */ "Target operand not allowed in constant expression", +/* ASL_MSG_INVALID_TIME */ "Time parameter too long (255 max)", +/* ASL_MSG_INVALID_TYPE */ "Invalid type", +/* ASL_MSG_INVALID_UUID */ "UUID string must be of the form \"aabbccdd-eeff-gghh-iijj-kkllmmnnoopp\"", +/* ASL_MSG_ISA_ADDRESS */ "Maximum 10-bit ISA address (0x3FF)", +/* ASL_MSG_LEADING_ASTERISK */ "Invalid leading asterisk", +/* ASL_MSG_LIST_LENGTH_LONG */ "Initializer list longer than declared package length", +/* ASL_MSG_LIST_LENGTH_SHORT */ "Initializer list shorter than declared package length", +/* ASL_MSG_LISTING_FILE_OPEN */ "Could not open listing file", +/* ASL_MSG_LISTING_FILENAME */ "Could not create listing filename", +/* ASL_MSG_LOCAL_INIT */ "Method local variable is not initialized", +/* ASL_MSG_LOCAL_OUTSIDE_METHOD */ "Local or Arg used outside a control method", +/* ASL_MSG_LONG_LINE */ "Splitting long input line", +/* ASL_MSG_MEMORY_ALLOCATION */ "Memory allocation failure", +/* ASL_MSG_MISSING_ENDDEPENDENT */ "Missing EndDependentFn() macro in dependent resource list", +/* ASL_MSG_MISSING_STARTDEPENDENT */ "Missing StartDependentFn() macro in dependent resource list", +/* ASL_MSG_MULTIPLE_DEFAULT */ "More than one Default statement within Switch construct", +/* ASL_MSG_MULTIPLE_TYPES */ "Multiple types", +/* ASL_MSG_NAME_EXISTS */ "Name already exists in scope", +/* ASL_MSG_NAME_OPTIMIZATION */ "NamePath optimized", +/* ASL_MSG_NAMED_OBJECT_IN_WHILE */ "Creating a named object in a While loop", +/* ASL_MSG_NESTED_COMMENT */ "Nested comment found", +/* ASL_MSG_NO_CASES */ "No Case statements under Switch", +/* ASL_MSG_NO_REGION */ "_REG has no corresponding Operation Region", +/* ASL_MSG_NO_RETVAL */ "Called method returns no value", +/* ASL_MSG_NO_WHILE */ "No enclosing While statement", +/* ASL_MSG_NON_ASCII */ "Invalid characters found in file", +/* ASL_MSG_NON_ZERO */ "Operand evaluates to zero", +/* ASL_MSG_NOT_EXIST */ "Object does not exist", +/* ASL_MSG_NOT_FOUND */ "Object not found or not accessible from scope", +/* ASL_MSG_NOT_METHOD */ "Not a control method, cannot invoke", +/* ASL_MSG_NOT_PARAMETER */ "Not a parameter, used as local only", +/* ASL_MSG_NOT_REACHABLE */ "Object is not accessible from this scope", +/* ASL_MSG_NOT_REFERENCED */ "Namespace object is not referenced", +/* ASL_MSG_NULL_DESCRIPTOR */ "Min/Max/Length/Gran are all zero, but no resource tag", +/* ASL_MSG_NULL_STRING */ "Invalid zero-length (null) string", +/* ASL_MSG_OPEN */ "Could not open file", +/* ASL_MSG_OUTPUT_FILE_OPEN */ "Could not open output AML file", +/* ASL_MSG_OUTPUT_FILENAME */ "Could not create output filename", +/* ASL_MSG_PACKAGE_LENGTH */ "Effective AML package length is zero", +/* ASL_MSG_PREPROCESSOR_FILENAME */ "Could not create preprocessor filename", +/* ASL_MSG_READ */ "Could not read file", +/* ASL_MSG_RECURSION */ "Recursive method call", +/* ASL_MSG_REGION_BUFFER_ACCESS */ "Host Operation Region requires BufferAcc access", +/* ASL_MSG_REGION_BYTE_ACCESS */ "Host Operation Region requires ByteAcc access", +/* ASL_MSG_RESERVED_ARG_COUNT_HI */ "Reserved method has too many arguments", +/* ASL_MSG_RESERVED_ARG_COUNT_LO */ "Reserved method has too few arguments", +/* ASL_MSG_RESERVED_METHOD */ "Reserved name must be a control method", +/* ASL_MSG_RESERVED_NO_RETURN_VAL */ "Reserved method should not return a value", +/* ASL_MSG_RESERVED_OPERAND_TYPE */ "Invalid object type for reserved name", +/* ASL_MSG_RESERVED_RETURN_VALUE */ "Reserved method must return a value", +/* ASL_MSG_RESERVED_USE */ "Invalid use of reserved name", +/* ASL_MSG_RESERVED_WORD */ "Use of reserved name", +/* ASL_MSG_RESOURCE_FIELD */ "Resource field name cannot be used as a target", +/* ASL_MSG_RESOURCE_INDEX */ "Missing ResourceSourceIndex (required)", +/* ASL_MSG_RESOURCE_LIST */ "Too many resource items (internal error)", +/* ASL_MSG_RESOURCE_SOURCE */ "Missing ResourceSource string (required)", +/* ASL_MSG_RESULT_NOT_USED */ "Result is not used, operator has no effect", +/* ASL_MSG_RETURN_TYPES */ "Not all control paths return a value", +/* ASL_MSG_SCOPE_FWD_REF */ "Forward references from Scope operator not allowed", +/* ASL_MSG_SCOPE_TYPE */ "Existing object has invalid type for Scope operator", +/* ASL_MSG_SEEK */ "Could not seek file", +/* ASL_MSG_SERIALIZED */ "Control Method marked Serialized", +/* ASL_MSG_SINGLE_NAME_OPTIMIZATION */ "NamePath optimized to NameSeg (uses run-time search path)", +/* ASL_MSG_SOME_NO_RETVAL */ "Called method may not always return a value", +/* ASL_MSG_STRING_LENGTH */ "String literal too long", +/* ASL_MSG_SWITCH_TYPE */ "Switch expression is not a static Integer/Buffer/String data type, defaulting to Integer", +/* ASL_MSG_SYNC_LEVEL */ "SyncLevel must be in the range 0-15", +/* ASL_MSG_SYNTAX */ "", +/* ASL_MSG_TABLE_SIGNATURE */ "Invalid Table Signature", +/* ASL_MSG_TAG_LARGER */ "ResourceTag larger than Field", +/* ASL_MSG_TAG_SMALLER */ "ResourceTag smaller than Field", +/* ASL_MSG_TIMEOUT */ "Result is not used, possible operator timeout will be missed", +/* ASL_MSG_TOO_MANY_TEMPS */ "Method requires too many temporary variables (_T_x)", +/* ASL_MSG_UNKNOWN_RESERVED_NAME */ "Unknown reserved name", +/* ASL_MSG_UNREACHABLE_CODE */ "Statement is unreachable", +/* ASL_MSG_UNSUPPORTED */ "Unsupported feature", +/* ASL_MSG_UPPER_CASE */ "Non-hex letters must be upper case", +/* ASL_MSG_VENDOR_LIST */ "Too many vendor data bytes (7 max)", +/* ASL_MSG_WRITE */ "Could not write file", + +/* Preprocessor */ + +/* ASL_MSG_DIRECTIVE_SYNTAX */ "Invalid directive syntax", +/* ASL_MSG_ENDIF_MISMATCH */ "Mismatched #endif", +/* ASL_MSG_ERROR_DIRECTIVE */ "#error", +/* ASL_MSG_EXISTING_NAME */ "Name is already defined", +/* ASL_MSG_INVALID_INVOCATION */ "Invalid macro invocation", +/* ASL_MSG_MACRO_SYNTAX */ "Invalid macro syntax", +/* ASL_MSG_TOO_MANY_ARGUMENTS */ "Too many macro arguments", +/* ASL_MSG_UNKNOWN_DIRECTIVE */ "Unknown directive", +/* ASL_MSG_UNKNOWN_PRAGMA */ "Unknown pragma", + +/* Table compiler */ + +/* ASL_MSG_BUFFER_ELEMENT */ "Invalid element in buffer initializer list", +/* ASL_MSG_DIVIDE_BY_ZERO */ "Expression contains divide-by-zero", +/* ASL_MSG_FLAG_VALUE */ "Flag value is too large", +/* ASL_MSG_INTEGER_SIZE */ "Integer too large for target", +/* ASL_MSG_INVALID_EXPRESSION */ "Invalid expression", +/* ASL_MSG_INVALID_FIELD_NAME */ "Invalid Field Name", +/* ASL_MSG_INVALID_HEX_INTEGER */ "Invalid hex integer constant", +/* ASL_MSG_OEM_TABLE */ "OEM table - unknown contents", +/* ASL_MSG_RESERVED_VALUE */ "Reserved field must be zero", +/* ASL_MSG_UNKNOWN_LABEL */ "Label is undefined", +/* ASL_MSG_UNKNOWN_SUBTABLE */ "Unknown subtable type", +/* ASL_MSG_UNKNOWN_TABLE */ "Unknown ACPI table signature", +/* ASL_MSG_ZERO_VALUE */ "Value must be non-zero" +}; + + +char *AslErrorLevel [ASL_NUM_REPORT_LEVELS] = { + "Warning ", + "Warning ", + "Warning ", + "Error ", + "Remark ", + "Optimize" +}; + +#define ASL_ERROR_LEVEL_LENGTH 8 /* Length of strings above */ + +#endif /* ASL_EXCEPTIONS */ + +#endif /* __ASLMESSAGES_H */ diff --git a/sys/contrib/dev/acpica/compiler/aslopcodes.c b/sys/contrib/dev/acpica/compiler/aslopcodes.c new file mode 100644 index 0000000..c9dc0f0 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslopcodes.c @@ -0,0 +1,814 @@ + +/****************************************************************************** + * + * Module Name: aslopcode - AML opcode generation + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslopcodes") + + +/* Local prototypes */ + +static void +OpcDoAccessAs ( + ACPI_PARSE_OBJECT *Op); + +static void +OpcDoConnection ( + ACPI_PARSE_OBJECT *Op); + +static void +OpcDoUnicode ( + ACPI_PARSE_OBJECT *Op); + +static void +OpcDoEisaId ( + ACPI_PARSE_OBJECT *Op); + +static void +OpcDoUuId ( + ACPI_PARSE_OBJECT *Op); + + +/******************************************************************************* + * + * FUNCTION: OpcAmlOpcodeUpdateWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Opcode update walk, ascending callback + * + ******************************************************************************/ + +ACPI_STATUS +OpcAmlOpcodeUpdateWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + + /* + * Handle the Package() case where the actual opcode cannot be determined + * until the PackageLength operand has been folded and minimized. + * (PackageOp versus VarPackageOp) + * + * This is (as of ACPI 3.0) the only case where the AML opcode can change + * based upon the value of a parameter. + * + * The parser always inserts a VarPackage opcode, which can possibly be + * optimized to a Package opcode. + */ + if (Op->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE) + { + OpnDoPackage (Op); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: OpcAmlOpcodeWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML + * operands. + * + ******************************************************************************/ + +ACPI_STATUS +OpcAmlOpcodeWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + + TotalParseNodes++; + + OpcGenerateAmlOpcode (Op); + OpnGenerateAmlOperands (Op); + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: OpcGetIntegerWidth + * + * PARAMETERS: Op - DEFINITION BLOCK op + * + * RETURN: none + * + * DESCRIPTION: Extract integer width from the table revision + * + ******************************************************************************/ + +void +OpcGetIntegerWidth ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Child; + + + if (!Op) + { + return; + } + + if (Gbl_RevisionOverride) + { + AcpiUtSetIntegerWidth (Gbl_RevisionOverride); + } + else + { + Child = Op->Asl.Child; + Child = Child->Asl.Next; + Child = Child->Asl.Next; + + /* Use the revision to set the integer width */ + + AcpiUtSetIntegerWidth ((UINT8) Child->Asl.Value.Integer); + } +} + + +/******************************************************************************* + * + * FUNCTION: OpcSetOptimalIntegerSize + * + * PARAMETERS: Op - A parse tree node + * + * RETURN: Integer width, in bytes. Also sets the node AML opcode to the + * optimal integer AML prefix opcode. + * + * DESCRIPTION: Determine the optimal AML encoding of an integer. All leading + * zeros can be truncated to squeeze the integer into the + * minimal number of AML bytes. + * + ******************************************************************************/ + +UINT32 +OpcSetOptimalIntegerSize ( + ACPI_PARSE_OBJECT *Op) +{ + +#if 0 + /* + * TBD: - we don't want to optimize integers in the block header, but the + * code below does not work correctly. + */ + if (Op->Asl.Parent && + Op->Asl.Parent->Asl.Parent && + (Op->Asl.Parent->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK)) + { + return 0; + } +#endif + + /* + * Check for the special AML integers first - Zero, One, Ones. + * These are single-byte opcodes that are the smallest possible + * representation of an integer. + * + * This optimization is optional. + */ + if (Gbl_IntegerOptimizationFlag) + { + switch (Op->Asl.Value.Integer) + { + case 0: + + Op->Asl.AmlOpcode = AML_ZERO_OP; + AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, + Op, "Zero"); + return 1; + + case 1: + + Op->Asl.AmlOpcode = AML_ONE_OP; + AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, + Op, "One"); + return 1; + + case ACPI_UINT32_MAX: + + /* Check for table integer width (32 or 64) */ + + if (AcpiGbl_IntegerByteWidth == 4) + { + Op->Asl.AmlOpcode = AML_ONES_OP; + AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, + Op, "Ones"); + return 1; + } + break; + + case ACPI_UINT64_MAX: + + /* Check for table integer width (32 or 64) */ + + if (AcpiGbl_IntegerByteWidth == 8) + { + Op->Asl.AmlOpcode = AML_ONES_OP; + AslError (ASL_OPTIMIZATION, ASL_MSG_INTEGER_OPTIMIZATION, + Op, "Ones"); + return 1; + } + break; + + default: + break; + } + } + + /* Find the best fit using the various AML integer prefixes */ + + if (Op->Asl.Value.Integer <= ACPI_UINT8_MAX) + { + Op->Asl.AmlOpcode = AML_BYTE_OP; + return 1; + } + if (Op->Asl.Value.Integer <= ACPI_UINT16_MAX) + { + Op->Asl.AmlOpcode = AML_WORD_OP; + return 2; + } + if (Op->Asl.Value.Integer <= ACPI_UINT32_MAX) + { + Op->Asl.AmlOpcode = AML_DWORD_OP; + return 4; + } + else + { + if (AcpiGbl_IntegerByteWidth == 4) + { + AslError (ASL_WARNING, ASL_MSG_INTEGER_LENGTH, + Op, NULL); + + if (!Gbl_IgnoreErrors) + { + /* Truncate the integer to 32-bit */ + Op->Asl.AmlOpcode = AML_DWORD_OP; + return 4; + } + } + + Op->Asl.AmlOpcode = AML_QWORD_OP; + return 8; + } +} + + +/******************************************************************************* + * + * FUNCTION: OpcDoAccessAs + * + * PARAMETERS: Op - Parse node + * + * RETURN: None + * + * DESCRIPTION: Implement the ACCESS_AS ASL keyword. + * + ******************************************************************************/ + +static void +OpcDoAccessAs ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *TypeOp; + ACPI_PARSE_OBJECT *AttribOp; + ACPI_PARSE_OBJECT *LengthOp; + UINT8 Attribute; + + + Op->Asl.AmlOpcodeLength = 1; + TypeOp = Op->Asl.Child; + + /* First child is the access type */ + + TypeOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; + TypeOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + + /* Second child is the optional access attribute */ + + AttribOp = TypeOp->Asl.Next; + if (AttribOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + AttribOp->Asl.Value.Integer = 0; + } + AttribOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; + AttribOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + + /* Only a few AccessAttributes support AccessLength */ + + Attribute = (UINT8) AttribOp->Asl.Value.Integer; + if ((Attribute != AML_FIELD_ATTRIB_MULTIBYTE) && + (Attribute != AML_FIELD_ATTRIB_RAW_BYTES) && + (Attribute != AML_FIELD_ATTRIB_RAW_PROCESS)) + { + return; + } + + Op->Asl.AmlOpcode = AML_FIELD_EXT_ACCESS_OP; + + /* + * Child of Attributes is the AccessLength (required for Multibyte, + * RawBytes, RawProcess.) + */ + LengthOp = AttribOp->Asl.Child; + if (!LengthOp) + { + return; + } + + /* TBD: probably can remove */ + + if (LengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + LengthOp->Asl.Value.Integer = 16; + } + + LengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; + LengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; +} + + +/******************************************************************************* + * + * FUNCTION: OpcDoConnection + * + * PARAMETERS: Op - Parse node + * + * RETURN: None + * + * DESCRIPTION: Implement the Connection ASL keyword. + * + ******************************************************************************/ + +static void +OpcDoConnection ( + ACPI_PARSE_OBJECT *Op) +{ + ASL_RESOURCE_NODE *Rnode; + ACPI_PARSE_OBJECT *BufferOp; + ACPI_PARSE_OBJECT *BufferLengthOp; + ACPI_PARSE_OBJECT *BufferDataOp; + UINT8 State; + + + Op->Asl.AmlOpcodeLength = 1; + + if (Op->Asl.Child->Asl.AmlOpcode == AML_INT_NAMEPATH_OP) + { + return; + } + + BufferOp = Op->Asl.Child; + BufferLengthOp = BufferOp->Asl.Child; + BufferDataOp = BufferLengthOp->Asl.Next; + + State = ACPI_RSTATE_NORMAL; + Rnode = RsDoOneResourceDescriptor (BufferDataOp->Asl.Next, 0, &State); + if (!Rnode) + { + return; /* error */ + } + + /* + * Transform the nodes into the following + * + * Op -> AML_BUFFER_OP + * First Child -> BufferLength + * Second Child -> Descriptor Buffer (raw byte data) + */ + BufferOp->Asl.ParseOpcode = PARSEOP_BUFFER; + BufferOp->Asl.AmlOpcode = AML_BUFFER_OP; + BufferOp->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC; + UtSetParseOpName (BufferOp); + + BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; + BufferLengthOp->Asl.Value.Integer = Rnode->BufferLength; + (void) OpcSetOptimalIntegerSize (BufferLengthOp); + UtSetParseOpName (BufferLengthOp); + + BufferDataOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + BufferDataOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN; + BufferDataOp->Asl.AmlOpcodeLength = 0; + BufferDataOp->Asl.AmlLength = Rnode->BufferLength; + BufferDataOp->Asl.Value.Buffer = (UINT8 *) Rnode; + UtSetParseOpName (BufferDataOp); +} + + +/******************************************************************************* + * + * FUNCTION: OpcDoUnicode + * + * PARAMETERS: Op - Parse node + * + * RETURN: None + * + * DESCRIPTION: Implement the UNICODE ASL "macro". Convert the input string + * to a unicode buffer. There is no Unicode AML opcode. + * + * Note: The Unicode string is 16 bits per character, no leading signature, + * with a 16-bit terminating NULL. + * + ******************************************************************************/ + +static void +OpcDoUnicode ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *InitializerOp; + UINT32 Length; + UINT32 Count; + UINT32 i; + UINT8 *AsciiString; + UINT16 *UnicodeString; + ACPI_PARSE_OBJECT *BufferLengthOp; + + + /* Change op into a buffer object */ + + Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST; + Op->Asl.ParseOpcode = PARSEOP_BUFFER; + UtSetParseOpName (Op); + + /* Buffer Length is first, followed by the string */ + + BufferLengthOp = Op->Asl.Child; + InitializerOp = BufferLengthOp->Asl.Next; + + AsciiString = (UINT8 *) InitializerOp->Asl.Value.String; + + /* Create a new buffer for the Unicode string */ + + Count = strlen (InitializerOp->Asl.Value.String) + 1; + Length = Count * sizeof (UINT16); + UnicodeString = UtLocalCalloc (Length); + + /* Convert to Unicode string (including null terminator) */ + + for (i = 0; i < Count; i++) + { + UnicodeString[i] = (UINT16) AsciiString[i]; + } + + /* + * Just set the buffer size node to be the buffer length, regardless + * of whether it was previously an integer or a default_arg placeholder + */ + BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; + BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP; + BufferLengthOp->Asl.Value.Integer = Length; + UtSetParseOpName (BufferLengthOp); + + (void) OpcSetOptimalIntegerSize (BufferLengthOp); + + /* The Unicode string is a raw data buffer */ + + InitializerOp->Asl.Value.Buffer = (UINT8 *) UnicodeString; + InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; + InitializerOp->Asl.AmlLength = Length; + InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + InitializerOp->Asl.Child = NULL; + UtSetParseOpName (InitializerOp); +} + + +/******************************************************************************* + * + * FUNCTION: OpcDoEisaId + * + * PARAMETERS: Op - Parse node + * + * RETURN: None + * + * DESCRIPTION: Convert a string EISA ID to numeric representation. See the + * Pnp BIOS Specification for details. Here is an excerpt: + * + * A seven character ASCII representation of the product + * identifier compressed into a 32-bit identifier. The seven + * character ID consists of a three character manufacturer code, + * a three character hexadecimal product identifier, and a one + * character hexadecimal revision number. The manufacturer code + * is a 3 uppercase character code that is compressed into 3 5-bit + * values as follows: + * 1) Find hex ASCII value for each letter + * 2) Subtract 40h from each ASCII value + * 3) Retain 5 least signficant bits for each letter by + * discarding upper 3 bits because they are always 0. + * 4) Compressed code = concatenate 0 and the 3 5-bit values + * + * The format of the compressed product identifier is as follows: + * Byte 0: Bit 7 - Reserved (0) + * Bits 6-2: - 1st character of compressed mfg code + * Bits 1-0 - Upper 2 bits of 2nd character of mfg code + * Byte 1: Bits 7-5 - Lower 3 bits of 2nd character of mfg code + * Bits 4-0 - 3rd character of mfg code + * Byte 2: Bits 7-4 - 1st hex digit of product number + * Bits 3-0 - 2nd hex digit of product number + * Byte 3: Bits 7-4 - 3st hex digit of product number + * Bits 3-0 - Hex digit of the revision number + * + ******************************************************************************/ + +static void +OpcDoEisaId ( + ACPI_PARSE_OBJECT *Op) +{ + UINT32 EisaId = 0; + UINT32 BigEndianId; + char *InString; + ACPI_STATUS Status = AE_OK; + UINT32 i; + + + InString = (char *) Op->Asl.Value.String; + + /* + * The EISAID string must be exactly 7 characters and of the form + * "UUUXXXX" -- 3 uppercase letters and 4 hex digits (e.g., "PNP0001") + */ + if (ACPI_STRLEN (InString) != 7) + { + Status = AE_BAD_PARAMETER; + } + else + { + /* Check all 7 characters for correct format */ + + for (i = 0; i < 7; i++) + { + /* First 3 characters must be uppercase letters */ + + if (i < 3) + { + if (!isupper ((int) InString[i])) + { + Status = AE_BAD_PARAMETER; + } + } + + /* Last 4 characters must be hex digits */ + + else if (!isxdigit ((int) InString[i])) + { + Status = AE_BAD_PARAMETER; + } + } + } + + if (ACPI_FAILURE (Status)) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_EISAID, Op, Op->Asl.Value.String); + } + else + { + /* Create ID big-endian first (bits are contiguous) */ + + BigEndianId = + (UINT32) ((UINT8) (InString[0] - 0x40)) << 26 | + (UINT32) ((UINT8) (InString[1] - 0x40)) << 21 | + (UINT32) ((UINT8) (InString[2] - 0x40)) << 16 | + + (UtHexCharToValue (InString[3])) << 12 | + (UtHexCharToValue (InString[4])) << 8 | + (UtHexCharToValue (InString[5])) << 4 | + UtHexCharToValue (InString[6]); + + /* Swap to little-endian to get final ID (see function header) */ + + EisaId = AcpiUtDwordByteSwap (BigEndianId); + } + + /* + * Morph the Op into an integer, regardless of whether there + * was an error in the EISAID string + */ + Op->Asl.Value.Integer = EisaId; + + Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST; + Op->Asl.ParseOpcode = PARSEOP_INTEGER; + (void) OpcSetOptimalIntegerSize (Op); + + /* Op is now an integer */ + + UtSetParseOpName (Op); +} + + +/******************************************************************************* + * + * FUNCTION: OpcDoUuId + * + * PARAMETERS: Op - Parse node + * + * RETURN: None + * + * DESCRIPTION: Convert UUID string to 16-byte buffer + * + ******************************************************************************/ + +static void +OpcDoUuId ( + ACPI_PARSE_OBJECT *Op) +{ + char *InString; + char *Buffer; + ACPI_STATUS Status = AE_OK; + ACPI_PARSE_OBJECT *NewOp; + + + InString = (char *) Op->Asl.Value.String; + Buffer = UtLocalCalloc (16); + + Status = AuValidateUuid (InString); + if (ACPI_FAILURE (Status)) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_UUID, Op, Op->Asl.Value.String); + } + else + { + (void) AuConvertStringToUuid (InString, Buffer); + } + + /* Change Op to a Buffer */ + + Op->Asl.ParseOpcode = PARSEOP_BUFFER; + Op->Common.AmlOpcode = AML_BUFFER_OP; + + /* Disable further optimization */ + + Op->Asl.CompileFlags &= ~NODE_COMPILE_TIME_CONST; + UtSetParseOpName (Op); + + /* Child node is the buffer length */ + + NewOp = TrAllocateNode (PARSEOP_INTEGER); + + NewOp->Asl.AmlOpcode = AML_BYTE_OP; + NewOp->Asl.Value.Integer = 16; + NewOp->Asl.Parent = Op; + + Op->Asl.Child = NewOp; + Op = NewOp; + + /* Peer to the child is the raw buffer data */ + + NewOp = TrAllocateNode (PARSEOP_RAW_DATA); + NewOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; + NewOp->Asl.AmlLength = 16; + NewOp->Asl.Value.String = (char *) Buffer; + NewOp->Asl.Parent = Op->Asl.Parent; + + Op->Asl.Next = NewOp; +} + + +/******************************************************************************* + * + * FUNCTION: OpcGenerateAmlOpcode + * + * PARAMETERS: Op - Parse node + * + * RETURN: None + * + * DESCRIPTION: Generate the AML opcode associated with the node and its + * parse (lex/flex) keyword opcode. Essentially implements + * a mapping between the parse opcodes and the actual AML opcodes. + * + ******************************************************************************/ + +void +OpcGenerateAmlOpcode ( + ACPI_PARSE_OBJECT *Op) +{ + + UINT16 Index; + + + Index = (UINT16) (Op->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE); + + Op->Asl.AmlOpcode = AslKeywordMapping[Index].AmlOpcode; + Op->Asl.AcpiBtype = AslKeywordMapping[Index].AcpiBtype; + Op->Asl.CompileFlags |= AslKeywordMapping[Index].Flags; + + if (!Op->Asl.Value.Integer) + { + Op->Asl.Value.Integer = AslKeywordMapping[Index].Value; + } + + /* Special handling for some opcodes */ + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_INTEGER: + /* + * Set the opcode based on the size of the integer + */ + (void) OpcSetOptimalIntegerSize (Op); + break; + + case PARSEOP_OFFSET: + + Op->Asl.AmlOpcodeLength = 1; + break; + + case PARSEOP_ACCESSAS: + + OpcDoAccessAs (Op); + break; + + case PARSEOP_CONNECTION: + + OpcDoConnection (Op); + break; + + case PARSEOP_EISAID: + + OpcDoEisaId (Op); + break; + + case PARSEOP_TOUUID: + + OpcDoUuId (Op); + break; + + case PARSEOP_UNICODE: + + OpcDoUnicode (Op); + break; + + case PARSEOP_INCLUDE: + + Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + Gbl_HasIncludeFiles = TRUE; + break; + + case PARSEOP_EXTERNAL: + + Op->Asl.Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + Op->Asl.Child->Asl.Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + break; + + default: + /* Nothing to do for other opcodes */ + break; + } + + return; +} + + diff --git a/sys/contrib/dev/acpica/compiler/asloperands.c b/sys/contrib/dev/acpica/compiler/asloperands.c new file mode 100644 index 0000000..cecf5d9 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asloperands.c @@ -0,0 +1,1184 @@ + +/****************************************************************************** + * + * Module Name: asloperands - AML operand processing + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("asloperands") + +/* Local prototypes */ + +static void +OpnDoField ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoBankField ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoBuffer ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoDefinitionBlock ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoFieldCommon ( + ACPI_PARSE_OBJECT *FieldOp, + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoIndexField ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoLoadTable ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoMethod ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoMutex ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnDoRegion ( + ACPI_PARSE_OBJECT *Op); + +static void +OpnAttachNameToNode ( + ACPI_PARSE_OBJECT *Op); + + +/******************************************************************************* + * + * FUNCTION: OpnDoMutex + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the operands for the MUTEX ASL keyword. + * + ******************************************************************************/ + +static void +OpnDoMutex ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + + Next = Op->Asl.Child; + Next = Next->Asl.Next; + + if (Next->Asl.Value.Integer > 15) + { + AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL); + } + return; +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoMethod + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the operands for the METHOD ASL keyword. + * + ******************************************************************************/ + +static void +OpnDoMethod ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + /* Optional arguments for this opcode with defaults */ + + UINT8 NumArgs = 0; + UINT8 Serialized = 0; + UINT8 Concurrency = 0; + UINT8 MethodFlags; + + + /* Opcode and package length first */ + /* Method name */ + + Next = Op->Asl.Child; + + /* Num args */ + + Next = Next->Asl.Next; + if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + NumArgs = (UINT8) Next->Asl.Value.Integer; + Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + } + + /* Serialized Flag */ + + Next = Next->Asl.Next; + if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + Serialized = (UINT8) Next->Asl.Value.Integer; + Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + } + + /* Concurrency value (valid values are 0-15) */ + + Next = Next->Asl.Next; + if (Next->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + if (Next->Asl.Value.Integer > 15) + { + AslError (ASL_ERROR, ASL_MSG_SYNC_LEVEL, Next, NULL); + } + Concurrency = (UINT8) Next->Asl.Value.Integer; + } + + /* Put the bits in their proper places */ + + MethodFlags = (UINT8) ((NumArgs & 0x7) | + ((Serialized & 0x1) << 3) | + ((Concurrency & 0xF) << 4)); + + /* Use the last node for the combined flags byte */ + + Next->Asl.Value.Integer = MethodFlags; + Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE; + Next->Asl.AmlLength = 1; + Next->Asl.ParseOpcode = PARSEOP_RAW_DATA; + + /* Save the arg count in the first node */ + + Op->Asl.Extra = NumArgs; +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoFieldCommon + * + * PARAMETERS: FieldOp - Node for an ASL field + * Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the various field keywords, + * FIELD, BANKFIELD, INDEXFIELD + * + ******************************************************************************/ + +static void +OpnDoFieldCommon ( + ACPI_PARSE_OBJECT *FieldOp, + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + ACPI_PARSE_OBJECT *PkgLengthNode; + UINT32 CurrentBitOffset; + UINT32 NewBitOffset; + UINT8 AccessType; + UINT8 LockRule; + UINT8 UpdateRule; + UINT8 FieldFlags; + UINT32 MinimumLength; + + + /* AccessType -- not optional, so no need to check for DEFAULT_ARG */ + + AccessType = (UINT8) Op->Asl.Value.Integer; + Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + + /* Set the access type in the parent (field) node for use later */ + + FieldOp->Asl.Value.Integer = AccessType; + + /* LockRule -- not optional, so no need to check for DEFAULT_ARG */ + + Next = Op->Asl.Next; + LockRule = (UINT8) Next->Asl.Value.Integer; + Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + + /* UpdateRule -- not optional, so no need to check for DEFAULT_ARG */ + + Next = Next->Asl.Next; + UpdateRule = (UINT8) Next->Asl.Value.Integer; + + /* + * Generate the flags byte. The various fields are already + * in the right bit position via translation from the + * keywords by the parser. + */ + FieldFlags = (UINT8) (AccessType | LockRule | UpdateRule); + + /* Use the previous node to be the FieldFlags node */ + + /* Set the node to RAW_DATA */ + + Next->Asl.Value.Integer = FieldFlags; + Next->Asl.AmlOpcode = AML_RAW_DATA_BYTE; + Next->Asl.AmlLength = 1; + Next->Asl.ParseOpcode = PARSEOP_RAW_DATA; + + /* Process the FieldUnitList */ + + Next = Next->Asl.Next; + CurrentBitOffset = 0; + + while (Next) + { + /* Save the offset of this field unit */ + + Next->Asl.ExtraValue = CurrentBitOffset; + + switch (Next->Asl.ParseOpcode) + { + case PARSEOP_ACCESSAS: + + PkgLengthNode = Next->Asl.Child; + AccessType = (UINT8) PkgLengthNode->Asl.Value.Integer; + + /* Nothing additional to do */ + break; + + + case PARSEOP_OFFSET: + + /* New offset into the field */ + + PkgLengthNode = Next->Asl.Child; + NewBitOffset = ((UINT32) PkgLengthNode->Asl.Value.Integer) * 8; + + /* + * Examine the specified offset in relation to the + * current offset counter. + */ + if (NewBitOffset < CurrentBitOffset) + { + /* + * Not allowed to specify a backwards offset! + * Issue error and ignore this node. + */ + AslError (ASL_ERROR, ASL_MSG_BACKWARDS_OFFSET, PkgLengthNode, + NULL); + Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + } + else if (NewBitOffset == CurrentBitOffset) + { + /* + * Offset is redundant; we don't need to output an + * offset opcode. Just set these nodes to default + */ + Next->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + PkgLengthNode->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + } + else + { + /* + * Valid new offset - set the value to be inserted into the AML + * and update the offset counter. + */ + PkgLengthNode->Asl.Value.Integer = + NewBitOffset - CurrentBitOffset; + CurrentBitOffset = NewBitOffset; + } + break; + + + case PARSEOP_NAMESEG: + case PARSEOP_RESERVED_BYTES: + + /* Named or reserved field entry */ + + PkgLengthNode = Next->Asl.Child; + NewBitOffset = (UINT32) PkgLengthNode->Asl.Value.Integer; + CurrentBitOffset += NewBitOffset; + + /* Save the current AccessAs value for error checking later */ + + switch (AccessType) + { + case AML_FIELD_ACCESS_ANY: + case AML_FIELD_ACCESS_BYTE: + case AML_FIELD_ACCESS_BUFFER: + default: + MinimumLength = 8; + break; + + case AML_FIELD_ACCESS_WORD: + MinimumLength = 16; + break; + + case AML_FIELD_ACCESS_DWORD: + MinimumLength = 32; + break; + + case AML_FIELD_ACCESS_QWORD: + MinimumLength = 64; + break; + } + + PkgLengthNode->Asl.ExtraValue = MinimumLength; + break; + + default: + /* All supported field opcodes must appear above */ + break; + } + + /* Move on to next entry in the field list */ + + Next = Next->Asl.Next; + } +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoField + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the FIELD ASL keyword + * + ******************************************************************************/ + +static void +OpnDoField ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + + /* Opcode is parent node */ + /* First child is field name */ + + Next = Op->Asl.Child; + + /* Second child is the AccessType */ + + OpnDoFieldCommon (Op, Next->Asl.Next); +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoIndexField + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the INDEXFIELD ASL keyword + * + ******************************************************************************/ + +static void +OpnDoIndexField ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + + /* Opcode is parent node */ + /* First child is the index name */ + + Next = Op->Asl.Child; + + /* Second child is the data name */ + + Next = Next->Asl.Next; + + /* Third child is the AccessType */ + + OpnDoFieldCommon (Op, Next->Asl.Next); +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoBankField + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the BANKFIELD ASL keyword + * + ******************************************************************************/ + +static void +OpnDoBankField ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + + /* Opcode is parent node */ + /* First child is the region name */ + + Next = Op->Asl.Child; + + /* Second child is the bank name */ + + Next = Next->Asl.Next; + + /* Third child is the bank value */ + + Next = Next->Asl.Next; + + /* Fourth child is the AccessType */ + + OpnDoFieldCommon (Op, Next->Asl.Next); +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoRegion + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Tries to get the length of the region. Can only do this at + * compile time if the length is a constant. + * + ******************************************************************************/ + +static void +OpnDoRegion ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + + /* Opcode is parent node */ + /* First child is the region name */ + + Next = Op->Asl.Child; + + /* Second child is the space ID*/ + + Next = Next->Asl.Next; + + /* Third child is the region offset */ + + Next = Next->Asl.Next; + + /* Fourth child is the region length */ + + Next = Next->Asl.Next; + if (Next->Asl.ParseOpcode == PARSEOP_INTEGER) + { + Op->Asl.Value.Integer = Next->Asl.Value.Integer; + } + else + { + Op->Asl.Value.Integer = ACPI_UINT64_MAX; + } +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoBuffer + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the BUFFER ASL keyword. We + * build a single raw byte buffer from the initialization nodes, + * each parse node contains a buffer byte. + * + ******************************************************************************/ + +static void +OpnDoBuffer ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *BufferLengthOp; + + /* Optional arguments for this opcode with defaults */ + + UINT32 BufferLength = 0; + + + /* Opcode and package length first */ + /* Buffer Length is next, followed by the initializer list */ + + BufferLengthOp = Op->Asl.Child; + InitializerOp = BufferLengthOp->Asl.Next; + + /* + * If the BufferLength is not an INTEGER or was not specified in the ASL + * (DEFAULT_ARG), it is a TermArg that is + * evaluated at run-time, and we are therefore finished. + */ + if ((BufferLengthOp->Asl.ParseOpcode != PARSEOP_INTEGER) && + (BufferLengthOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)) + { + return; + } + + /* + * We want to count the number of items in the initializer list, because if + * it is larger than the buffer length, we will define the buffer size + * to be the size of the initializer list (as per the ACPI Specification) + */ + switch (InitializerOp->Asl.ParseOpcode) + { + case PARSEOP_INTEGER: + case PARSEOP_BYTECONST: + case PARSEOP_WORDCONST: + case PARSEOP_DWORDCONST: + + /* The peer list contains the byte list (if any...) */ + + while (InitializerOp) + { + /* For buffers, this is a list of raw bytes */ + + InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; + InitializerOp->Asl.AmlLength = 1; + InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + + BufferLength++; + InitializerOp = ASL_GET_PEER_NODE (InitializerOp); + } + break; + + + case PARSEOP_STRING_LITERAL: + + /* + * Only one initializer, the string. Buffer must be big enough to hold + * the string plus the null termination byte + */ + BufferLength = strlen (InitializerOp->Asl.Value.String) + 1; + + InitializerOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; + InitializerOp->Asl.AmlLength = BufferLength; + InitializerOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + break; + + + case PARSEOP_RAW_DATA: + + /* Buffer nodes are already initialized (e.g. Unicode operator) */ + return; + + + case PARSEOP_DEFAULT_ARG: + break; + + + default: + AslError (ASL_ERROR, ASL_MSG_INVALID_OPERAND, InitializerOp, + "Unknown buffer initializer opcode"); + printf ("Unknown buffer initializer opcode [%s]\n", + UtGetOpName (InitializerOp->Asl.ParseOpcode)); + return; + } + + /* Check if initializer list is longer than the buffer length */ + + if (BufferLengthOp->Asl.Value.Integer > BufferLength) + { + BufferLength = (UINT32) BufferLengthOp->Asl.Value.Integer; + } + + if (!BufferLength) + { + /* No length AND no items -- issue notice */ + + AslError (ASL_REMARK, ASL_MSG_BUFFER_LENGTH, BufferLengthOp, NULL); + + /* But go ahead and put the buffer length of zero into the AML */ + } + + /* + * Just set the buffer size node to be the buffer length, regardless + * of whether it was previously an integer or a default_arg placeholder + */ + BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; + BufferLengthOp->Asl.AmlOpcode = AML_DWORD_OP; + BufferLengthOp->Asl.Value.Integer = BufferLength; + + (void) OpcSetOptimalIntegerSize (BufferLengthOp); + + /* Remaining nodes are handled via the tree walk */ +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoPackage + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the PACKAGE ASL keyword. NOTE: + * can only be called after constants have been folded, to ensure + * that the PackageLength operand has been fully reduced. + * + ******************************************************************************/ + +void +OpnDoPackage ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *PackageLengthOp; + UINT32 PackageLength = 0; + + + /* Opcode and package length first, followed by the initializer list */ + + PackageLengthOp = Op->Asl.Child; + InitializerOp = PackageLengthOp->Asl.Next; + + /* Count the number of items in the initializer list */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + /* The peer list contains the byte list (if any...) */ + + while (InitializerOp) + { + PackageLength++; + InitializerOp = InitializerOp->Asl.Next; + } + } + + /* If package length is a constant, compare to the initializer list */ + + if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) || + (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST)) + { + if (PackageLengthOp->Asl.Value.Integer > PackageLength) + { + /* + * Allow package length to be longer than the initializer + * list -- but if the length of initializer list is nonzero, + * issue a message since this is probably a coding error, + * even though technically legal. + */ + if (PackageLength > 0) + { + AslError (ASL_REMARK, ASL_MSG_LIST_LENGTH_SHORT, + PackageLengthOp, NULL); + } + + PackageLength = (UINT32) PackageLengthOp->Asl.Value.Integer; + } + else if (PackageLengthOp->Asl.Value.Integer < PackageLength) + { + /* + * The package length is smaller than the length of the + * initializer list. This is an error as per the ACPI spec. + */ + AslError (ASL_ERROR, ASL_MSG_LIST_LENGTH_LONG, + PackageLengthOp, NULL); + } + } + + if (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + /* + * This is the case if the PackageLength was left empty - Package() + * The package length becomes the length of the initializer list + */ + Op->Asl.Child->Asl.ParseOpcode = PARSEOP_INTEGER; + Op->Asl.Child->Asl.Value.Integer = PackageLength; + + /* Set the AML opcode */ + + (void) OpcSetOptimalIntegerSize (Op->Asl.Child); + } + + /* If not a variable-length package, check for a zero package length */ + + if ((PackageLengthOp->Asl.ParseOpcode == PARSEOP_INTEGER) || + (PackageLengthOp->Asl.ParseOpcode == PARSEOP_QWORDCONST) || + (PackageLengthOp->Asl.ParseOpcode == PARSEOP_ZERO) || + (PackageLengthOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG)) + { + if (!PackageLength) + { + /* No length AND no initializer list -- issue a remark */ + + AslError (ASL_REMARK, ASL_MSG_PACKAGE_LENGTH, + PackageLengthOp, NULL); + + /* But go ahead and put the buffer length of zero into the AML */ + } + } + + /* + * If the PackageLength is a constant <= 255, we can change the + * AML opcode from VarPackage to a simple (ACPI 1.0) Package opcode. + */ + if (((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) && + (Op->Asl.Child->Asl.Value.Integer <= 255)) || + (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ONE) || + (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ONES)|| + (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_ZERO)) + { + Op->Asl.AmlOpcode = AML_PACKAGE_OP; + Op->Asl.ParseOpcode = PARSEOP_PACKAGE; + + /* + * Just set the package size node to be the package length, regardless + * of whether it was previously an integer or a default_arg placeholder + */ + PackageLengthOp->Asl.AmlOpcode = AML_RAW_DATA_BYTE; + PackageLengthOp->Asl.AmlLength = 1; + PackageLengthOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + PackageLengthOp->Asl.Value.Integer = PackageLength; + } + + /* Remaining nodes are handled via the tree walk */ +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoLoadTable + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the LOADTABLE ASL keyword. + * + ******************************************************************************/ + +static void +OpnDoLoadTable ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + + + /* Opcode is parent node */ + /* First child is the table signature */ + + Next = Op->Asl.Child; + + /* Second child is the OEM ID*/ + + Next = Next->Asl.Next; + + /* Third child is the OEM table ID */ + + Next = Next->Asl.Next; + + /* Fourth child is the RootPath string */ + + Next = Next->Asl.Next; + if (Next->Asl.ParseOpcode == PARSEOP_ZERO) + { + Next->Asl.ParseOpcode = PARSEOP_STRING_LITERAL; + Next->Asl.Value.String = "\\"; + Next->Asl.AmlLength = 2; + OpcGenerateAmlOpcode (Next); + } + +#ifdef ASL_FUTURE_IMPLEMENTATION + + /* TBD: NOT IMPLEMENTED */ + /* Fifth child is the [optional] ParameterPathString */ + /* Sixth child is the [optional] ParameterData */ + + Next = Next->Asl.Next; + if (Next->Asl.ParseOpcode == DEFAULT_ARG) + { + Next->Asl.AmlLength = 1; + Next->Asl.ParseOpcode = ZERO; + OpcGenerateAmlOpcode (Next); + } + + + Next = Next->Asl.Next; + if (Next->Asl.ParseOpcode == DEFAULT_ARG) + { + Next->Asl.AmlLength = 1; + Next->Asl.ParseOpcode = ZERO; + OpcGenerateAmlOpcode (Next); + } +#endif +} + + +/******************************************************************************* + * + * FUNCTION: OpnDoDefinitionBlock + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Construct the AML operands for the DEFINITIONBLOCK ASL keyword + * + ******************************************************************************/ + +static void +OpnDoDefinitionBlock ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Child; + ACPI_SIZE Length; + UINT32 i; + char *Filename; + + + /* + * These nodes get stuffed into the table header. They are special + * cased when the table is written to the output file. + * + * Mark all of these nodes as non-usable so they won't get output + * as AML opcodes! + */ + + /* Get AML filename. Use it if non-null */ + + Child = Op->Asl.Child; + if (Child->Asl.Value.Buffer && + *Child->Asl.Value.Buffer && + (Gbl_UseDefaultAmlFilename)) + { + /* + * We will use the AML filename that is embedded in the source file + * for the output filename. + */ + Filename = ACPI_ALLOCATE (strlen (Gbl_DirectoryPath) + + strlen ((char *) Child->Asl.Value.Buffer) + 1); + + /* Prepend the current directory path */ + + strcpy (Filename, Gbl_DirectoryPath); + strcat (Filename, (char *) Child->Asl.Value.Buffer); + + Gbl_OutputFilenamePrefix = Filename; + } + Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + + /* Signature */ + + Child = Child->Asl.Next; + Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + if (Child->Asl.Value.String) + { + Gbl_TableSignature = Child->Asl.Value.String; + if (ACPI_STRLEN (Gbl_TableSignature) != 4) + { + AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child, + "Length not exactly 4"); + } + + for (i = 0; i < 4; i++) + { + if (!isalnum ((int) Gbl_TableSignature[i])) + { + AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child, + "Contains non-alphanumeric characters"); + } + } + } + + /* Revision */ + + Child = Child->Asl.Next; + Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + /* + * We used the revision to set the integer width earlier + */ + + /* OEMID */ + + Child = Child->Asl.Next; + Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + + /* OEM TableID */ + + Child = Child->Asl.Next; + Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + if (Child->Asl.Value.String) + { + Length = ACPI_STRLEN (Child->Asl.Value.String); + Gbl_TableId = AcpiOsAllocate (Length + 1); + ACPI_STRCPY (Gbl_TableId, Child->Asl.Value.String); + + for (i = 0; i < Length; i++) + { + if (Gbl_TableId[i] == ' ') + { + Gbl_TableId[i] = 0; + break; + } + } + } + + /* OEM Revision */ + + Child = Child->Asl.Next; + Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; +} + + +/******************************************************************************* + * + * FUNCTION: UtGetArg + * + * PARAMETERS: Op - Get an argument for this op + * Argn - Nth argument to get + * + * RETURN: The argument (as an Op object). NULL if argument does not exist + * + * DESCRIPTION: Get the specified op's argument (peer) + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +UtGetArg ( + ACPI_PARSE_OBJECT *Op, + UINT32 Argn) +{ + ACPI_PARSE_OBJECT *Arg = NULL; + + + /* Get the requested argument object */ + + Arg = Op->Asl.Child; + while (Arg && Argn) + { + Argn--; + Arg = Arg->Asl.Next; + } + + return (Arg); +} + + +/******************************************************************************* + * + * FUNCTION: OpnAttachNameToNode + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: For the named ASL/AML operators, get the actual name from the + * argument list and attach it to the parent node so that we + * can get to it quickly later. + * + ******************************************************************************/ + +static void +OpnAttachNameToNode ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Child = NULL; + + + if (Op->Asl.ParseOpcode == PARSEOP_EXTERNAL) + { + Child = UtGetArg (Op, 0); + } + else switch (Op->Asl.AmlOpcode) + { + case AML_DATA_REGION_OP: + case AML_DEVICE_OP: + case AML_EVENT_OP: + case AML_METHOD_OP: + case AML_MUTEX_OP: + case AML_REGION_OP: + case AML_POWER_RES_OP: + case AML_PROCESSOR_OP: + case AML_THERMAL_ZONE_OP: + case AML_NAME_OP: + case AML_SCOPE_OP: + + Child = UtGetArg (Op, 0); + break; + + case AML_ALIAS_OP: + + Child = UtGetArg (Op, 1); + break; + + case AML_CREATE_BIT_FIELD_OP: + case AML_CREATE_BYTE_FIELD_OP: + case AML_CREATE_WORD_FIELD_OP: + case AML_CREATE_DWORD_FIELD_OP: + case AML_CREATE_QWORD_FIELD_OP: + + Child = UtGetArg (Op, 2); + break; + + case AML_CREATE_FIELD_OP: + + Child = UtGetArg (Op, 3); + break; + + case AML_BANK_FIELD_OP: + case AML_INDEX_FIELD_OP: + case AML_FIELD_OP: + + return; + + default: + return; + } + + if (Child) + { + UtAttachNamepathToOwner (Op, Child); + } +} + + +/******************************************************************************* + * + * FUNCTION: OpnGenerateAmlOperands + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more + * complex AML opcodes require processing of the child nodes + * (arguments/operands). + * + ******************************************************************************/ + +void +OpnGenerateAmlOperands ( + ACPI_PARSE_OBJECT *Op) +{ + + + if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE) + { + return; + } + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_DEFINITIONBLOCK: + OpnDoDefinitionBlock (Op); + break; + + case PARSEOP_METHOD: + OpnDoMethod (Op); + break; + + case PARSEOP_MUTEX: + OpnDoMutex (Op); + break; + + case PARSEOP_FIELD: + OpnDoField (Op); + break; + + case PARSEOP_INDEXFIELD: + OpnDoIndexField (Op); + break; + + case PARSEOP_BANKFIELD: + OpnDoBankField (Op); + break; + + case PARSEOP_BUFFER: + OpnDoBuffer (Op); + break; + + case PARSEOP_LOADTABLE: + OpnDoLoadTable (Op); + break; + + case PARSEOP_OPERATIONREGION: + OpnDoRegion (Op); + break; + + case PARSEOP_RESOURCETEMPLATE: + RsDoResourceTemplate (Op); + break; + + case PARSEOP_NAMESEG: + case PARSEOP_NAMESTRING: + case PARSEOP_METHODCALL: + case PARSEOP_STRING_LITERAL: + break; + + default: + break; + } + + /* TBD: move */ + + OpnAttachNameToNode (Op); +} + + diff --git a/sys/contrib/dev/acpica/compiler/aslopt.c b/sys/contrib/dev/acpica/compiler/aslopt.c new file mode 100644 index 0000000..904c329 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslopt.c @@ -0,0 +1,796 @@ +/****************************************************************************** + * + * Module Name: aslopt- Compiler optimizations + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#include <contrib/dev/acpica/include/acparser.h> +#include <contrib/dev/acpica/include/amlcode.h> +#include <contrib/dev/acpica/include/acnamesp.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslopt") + + +static UINT32 OptTotal = 0; + +/* Local prototypes */ + +static ACPI_STATUS +OptSearchToRoot ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState, + ACPI_NAMESPACE_NODE *CurrentNode, + ACPI_NAMESPACE_NODE *TargetNode, + ACPI_BUFFER *TargetPath, + char **NewPath); + +static ACPI_STATUS +OptBuildShortestPath ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState, + ACPI_NAMESPACE_NODE *CurrentNode, + ACPI_NAMESPACE_NODE *TargetNode, + ACPI_BUFFER *CurrentPath, + ACPI_BUFFER *TargetPath, + ACPI_SIZE AmlNameStringLength, + UINT8 IsDeclaration, + char **ReturnNewPath); + +static ACPI_STATUS +OptOptimizeNameDeclaration ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState, + ACPI_NAMESPACE_NODE *CurrentNode, + ACPI_NAMESPACE_NODE *TargetNode, + char *AmlNameString, + char **NewPath); + + +/******************************************************************************* + * + * FUNCTION: OptSearchToRoot + * + * PARAMETERS: Op - Current parser op + * WalkState - Current state + * CurrentNode - Where we are in the namespace + * TargetNode - Node to which we are referring + * TargetPath - External full path to the target node + * NewPath - Where the optimized path is returned + * + * RETURN: Status + * + * DESCRIPTION: Attempt to optimize a reference to a single 4-character ACPI + * name utilizing the search-to-root name resolution algorithm + * that is used by AML interpreters. + * + ******************************************************************************/ + +static ACPI_STATUS +OptSearchToRoot ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState, + ACPI_NAMESPACE_NODE *CurrentNode, + ACPI_NAMESPACE_NODE *TargetNode, + ACPI_BUFFER *TargetPath, + char **NewPath) +{ + ACPI_NAMESPACE_NODE *Node; + ACPI_GENERIC_STATE ScopeInfo; + ACPI_STATUS Status; + char *Path; + + + ACPI_FUNCTION_NAME (OptSearchToRoot); + + + /* + * Check if search-to-root can be utilized. Use the last NameSeg of + * the NamePath and 1) See if can be found and 2) If found, make + * sure that it is the same node that we want. If there is another + * name in the search path before the one we want, the nodes will + * not match, and we cannot use this optimization. + */ + Path = &(((char *) TargetPath->Pointer)[TargetPath->Length - + ACPI_NAME_SIZE]), + ScopeInfo.Scope.Node = CurrentNode; + + /* Lookup the NameSeg using SEARCH_PARENT (search-to-root) */ + + Status = AcpiNsLookup (&ScopeInfo, Path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, + ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, + WalkState, &(Node)); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* + * We found the name, but we must check to make sure that the node + * matches. Otherwise, there is another identical name in the search + * path that precludes the use of this optimization. + */ + if (Node != TargetNode) + { + /* + * This means that another object with the same name was found first, + * and we cannot use this optimization. + */ + return (AE_NOT_FOUND); + } + + /* Found the node, we can use this optimization */ + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + "NAMESEG: %-24s", Path)); + + /* We must allocate a new string for the name (TargetPath gets deleted) */ + + *NewPath = ACPI_ALLOCATE_ZEROED (ACPI_NAME_SIZE + 1); + ACPI_STRCPY (*NewPath, Path); + + if (ACPI_STRNCMP (*NewPath, "_T_", 3)) + { + AslError (ASL_OPTIMIZATION, ASL_MSG_SINGLE_NAME_OPTIMIZATION, Op, + *NewPath); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: OptBuildShortestPath + * + * PARAMETERS: Op - Current parser op + * WalkState - Current state + * CurrentNode - Where we are in the namespace + * TargetNode - Node to which we are referring + * CurrentPath - External full path to the current node + * TargetPath - External full path to the target node + * AmlNameStringLength - Length of the original namepath + * IsDeclaration - TRUE for declaration, FALSE for reference + * ReturnNewPath - Where the optimized path is returned + * + * RETURN: Status + * + * DESCRIPTION: Build an optimal NamePath using carats + * + ******************************************************************************/ + +static ACPI_STATUS +OptBuildShortestPath ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState, + ACPI_NAMESPACE_NODE *CurrentNode, + ACPI_NAMESPACE_NODE *TargetNode, + ACPI_BUFFER *CurrentPath, + ACPI_BUFFER *TargetPath, + ACPI_SIZE AmlNameStringLength, + UINT8 IsDeclaration, + char **ReturnNewPath) +{ + UINT32 NumCommonSegments; + UINT32 MaxCommonSegments; + UINT32 Index; + UINT32 NumCarats; + UINT32 i; + char *NewPath; + char *NewPathExternal; + ACPI_NAMESPACE_NODE *Node; + ACPI_GENERIC_STATE ScopeInfo; + ACPI_STATUS Status; + BOOLEAN SubPath = FALSE; + + + ACPI_FUNCTION_NAME (OptBuildShortestPath); + + + ScopeInfo.Scope.Node = CurrentNode; + + /* + * Determine the maximum number of NameSegs that the Target and Current paths + * can possibly have in common. (To optimize, we have to have at least 1) + * + * Note: The external NamePath string lengths are always a multiple of 5 + * (ACPI_NAME_SIZE + separator) + */ + MaxCommonSegments = TargetPath->Length / ACPI_PATH_SEGMENT_LENGTH; + if (CurrentPath->Length < TargetPath->Length) + { + MaxCommonSegments = CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH; + } + + /* + * Determine how many NameSegs the two paths have in common. + * (Starting from the root) + */ + for (NumCommonSegments = 0; + NumCommonSegments < MaxCommonSegments; + NumCommonSegments++) + { + /* Compare two single NameSegs */ + + if (ACPI_STRNCMP ( + &((char *) TargetPath->Pointer)[(NumCommonSegments * + ACPI_PATH_SEGMENT_LENGTH) + 1], + &((char *) CurrentPath->Pointer)[(NumCommonSegments * + ACPI_PATH_SEGMENT_LENGTH) + 1], + ACPI_NAME_SIZE)) + { + /* Mismatch */ + + break; + } + } + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %u", + NumCommonSegments)); + + /* There must be at least 1 common NameSeg in order to optimize */ + + if (NumCommonSegments == 0) + { + return (AE_NOT_FOUND); + } + + if (NumCommonSegments == MaxCommonSegments) + { + if (CurrentPath->Length == TargetPath->Length) + { + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SAME PATH")); + return (AE_NOT_FOUND); + } + else + { + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SUBPATH")); + SubPath = TRUE; + } + } + + /* Determine how many prefix Carats are required */ + + NumCarats = (CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH) - + NumCommonSegments; + + /* + * Construct a new target string + */ + NewPathExternal = ACPI_ALLOCATE_ZEROED ( + TargetPath->Length + NumCarats + 1); + + /* Insert the Carats into the Target string */ + + for (i = 0; i < NumCarats; i++) + { + NewPathExternal[i] = '^'; + } + + /* + * Copy only the necessary (optimal) segments from the original + * target string + */ + Index = (NumCommonSegments * ACPI_PATH_SEGMENT_LENGTH) + 1; + + /* Special handling for exact subpath in a name declaration */ + + if (IsDeclaration && SubPath && (CurrentPath->Length > TargetPath->Length)) + { + /* + * The current path is longer than the target, and the target is a + * subpath of the current path. We must include one more NameSeg of + * the target path + */ + Index -= ACPI_PATH_SEGMENT_LENGTH; + + /* Special handling for Scope() operator */ + + if (Op->Asl.AmlOpcode == AML_SCOPE_OP) + { + NewPathExternal[i] = '^'; + i++; + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "(EXTRA ^)")); + } + } + + /* Make sure we haven't gone off the end of the target path */ + + if (Index > TargetPath->Length) + { + Index = TargetPath->Length; + } + + ACPI_STRCPY (&NewPathExternal[i], &((char *) TargetPath->Pointer)[Index]); + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " %-24s", NewPathExternal)); + + /* + * Internalize the new target string and check it against the original + * string to make sure that this is in fact an optimization. If the + * original string is already optimal, there is no point in continuing. + */ + Status = AcpiNsInternalizeName (NewPathExternal, &NewPath); + if (ACPI_FAILURE (Status)) + { + AslCoreSubsystemError (Op, Status, "Internalizing new NamePath", + ASL_NO_ABORT); + ACPI_FREE (NewPathExternal); + return (Status); + } + + if (ACPI_STRLEN (NewPath) >= AmlNameStringLength) + { + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + " NOT SHORTER (New %u old %u)", + (UINT32) ACPI_STRLEN (NewPath), (UINT32) AmlNameStringLength)); + ACPI_FREE (NewPathExternal); + return (AE_NOT_FOUND); + } + + /* + * Check to make sure that the optimization finds the node we are + * looking for. This is simply a sanity check on the new + * path that has been created. + */ + Status = AcpiNsLookup (&ScopeInfo, NewPath, + ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, + ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node)); + if (ACPI_SUCCESS (Status)) + { + /* Found the namepath, but make sure the node is correct */ + + if (Node == TargetNode) + { + /* The lookup matched the node, accept this optimization */ + + AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION, + Op, NewPathExternal); + *ReturnNewPath = NewPath; + } + else + { + /* Node is not correct, do not use this optimization */ + + Status = AE_NOT_FOUND; + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** WRONG NODE")); + AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op, + "Not using optimized name - found wrong node"); + } + } + else + { + /* The lookup failed, we obviously cannot use this optimization */ + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** NOT FOUND")); + AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op, + "Not using optimized name - did not find node"); + } + + ACPI_FREE (NewPathExternal); + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: OptOptimizeNameDeclaration + * + * PARAMETERS: Op - Current parser op + * WalkState - Current state + * CurrentNode - Where we are in the namespace + * AmlNameString - Unoptimized namepath + * NewPath - Where the optimized path is returned + * + * RETURN: Status. AE_OK If path is optimized + * + * DESCRIPTION: Perform a simple optimization of removing an extraneous + * backslash prefix if we are already at the root scope. + * + ******************************************************************************/ + +static ACPI_STATUS +OptOptimizeNameDeclaration ( + ACPI_PARSE_OBJECT *Op, + ACPI_WALK_STATE *WalkState, + ACPI_NAMESPACE_NODE *CurrentNode, + ACPI_NAMESPACE_NODE *TargetNode, + char *AmlNameString, + char **NewPath) +{ + ACPI_STATUS Status; + char *NewPathExternal; + ACPI_GENERIC_STATE ScopeInfo; + ACPI_NAMESPACE_NODE *Node; + + + ACPI_FUNCTION_TRACE (OptOptimizeNameDeclaration); + + + if (((CurrentNode == AcpiGbl_RootNode) || + (Op->Common.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK)) && + (AmlNameString[0] == '\\')) + { + /* + * The current scope is the root, and the namepath has a root prefix + * that is therefore extraneous. Remove it. + */ + *NewPath = &AmlNameString[1]; + + /* Debug output */ + + Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, *NewPath, + NULL, &NewPathExternal); + if (ACPI_FAILURE (Status)) + { + AslCoreSubsystemError (Op, Status, "Externalizing NamePath", + ASL_NO_ABORT); + return (Status); + } + + /* + * Check to make sure that the optimization finds the node we are + * looking for. This is simply a sanity check on the new + * path that has been created. + */ + ScopeInfo.Scope.Node = CurrentNode; + Status = AcpiNsLookup (&ScopeInfo, *NewPath, + ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, + ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node)); + if (ACPI_SUCCESS (Status)) + { + /* Found the namepath, but make sure the node is correct */ + + if (Node == TargetNode) + { + /* The lookup matched the node, accept this optimization */ + + AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION, + Op, NewPathExternal); + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + "AT ROOT: %-24s", NewPathExternal)); + } + else + { + /* Node is not correct, do not use this optimization */ + + Status = AE_NOT_FOUND; + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + " ***** WRONG NODE")); + AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op, + "Not using optimized name - found wrong node"); + } + } + else + { + /* The lookup failed, we obviously cannot use this optimization */ + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + " ***** NOT FOUND")); + AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op, + "Not using optimized name - did not find node"); + } + + ACPI_FREE (NewPathExternal); + return (Status); + } + + /* Could not optimize */ + + return (AE_NOT_FOUND); +} + + +/******************************************************************************* + * + * FUNCTION: OptOptimizeNamePath + * + * PARAMETERS: Op - Current parser op + * Flags - Opcode info flags + * WalkState - Current state + * AmlNameString - Unoptimized namepath + * TargetNode - Node to which AmlNameString refers + * + * RETURN: None. If path is optimized, the Op is updated with new path + * + * DESCRIPTION: Optimize a Named Declaration or Reference to the minimal length. + * Must take into account both the current location in the + * namespace and the actual reference path. + * + ******************************************************************************/ + +void +OptOptimizeNamePath ( + ACPI_PARSE_OBJECT *Op, + UINT32 Flags, + ACPI_WALK_STATE *WalkState, + char *AmlNameString, + ACPI_NAMESPACE_NODE *TargetNode) +{ + ACPI_STATUS Status; + ACPI_BUFFER TargetPath; + ACPI_BUFFER CurrentPath; + ACPI_SIZE AmlNameStringLength; + ACPI_NAMESPACE_NODE *CurrentNode; + char *ExternalNameString; + char *NewPath = NULL; + ACPI_SIZE HowMuchShorter; + ACPI_PARSE_OBJECT *NextOp; + + + ACPI_FUNCTION_TRACE (OptOptimizeNamePath); + + + /* This is an optional optimization */ + + if (!Gbl_ReferenceOptimizationFlag) + { + return_VOID; + } + + /* Various required items */ + + if (!TargetNode || !WalkState || !AmlNameString || !Op->Common.Parent) + { + return_VOID; + } + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "%5d [%12.12s] [%12.12s] ", + Op->Asl.LogicalLineNumber, + AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode), + AcpiPsGetOpcodeName (Op->Common.AmlOpcode))); + + if (!(Flags & (AML_NAMED | AML_CREATE))) + { + if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION) + { + /* We don't want to fuss with actual name declaration nodes here */ + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + "******* NAME DECLARATION\n")); + return_VOID; + } + } + + /* + * The original path must be longer than one NameSeg (4 chars) for there + * to be any possibility that it can be optimized to a shorter string + */ + AmlNameStringLength = ACPI_STRLEN (AmlNameString); + if (AmlNameStringLength <= ACPI_NAME_SIZE) + { + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + "NAMESEG %4.4s\n", AmlNameString)); + return_VOID; + } + + /* + * We need to obtain the node that represents the current scope -- where + * we are right now in the namespace. We will compare this path + * against the Namepath, looking for commonality. + */ + CurrentNode = AcpiGbl_RootNode; + if (WalkState->ScopeInfo) + { + CurrentNode = WalkState->ScopeInfo->Scope.Node; + } + + if (Flags & (AML_NAMED | AML_CREATE)) + { + /* This is the declaration of a new name */ + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "NAME")); + + /* + * The node of interest is the parent of this node + * (the containing scope) + */ + CurrentNode = Op->Asl.Parent->Asl.Node; + if (!CurrentNode) + { + CurrentNode = AcpiGbl_RootNode; + } + } + else + { + /* This is a reference to an existing named object */ + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "REF ")); + } + + /* + * Obtain the full paths to the two nodes that we are interested in + * (Target and current namespace location) in external + * format -- something we can easily manipulate + */ + TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER; + Status = AcpiNsHandleToPathname (TargetNode, &TargetPath); + if (ACPI_FAILURE (Status)) + { + AslCoreSubsystemError (Op, Status, "Getting Target NamePath", + ASL_NO_ABORT); + return_VOID; + } + TargetPath.Length--; /* Subtract one for null terminator */ + + /* CurrentPath is the path to this scope (where we are in the namespace) */ + + CurrentPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER; + Status = AcpiNsHandleToPathname (CurrentNode, &CurrentPath); + if (ACPI_FAILURE (Status)) + { + AslCoreSubsystemError (Op, Status, "Getting Current NamePath", + ASL_NO_ABORT); + return_VOID; + } + CurrentPath.Length--; /* Subtract one for null terminator */ + + /* Debug output only */ + + Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, AmlNameString, + NULL, &ExternalNameString); + if (ACPI_FAILURE (Status)) + { + AslCoreSubsystemError (Op, Status, "Externalizing NamePath", + ASL_NO_ABORT); + return_VOID; + } + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, + "%37s (%2u) ==> %-32s(%2u) %-32s", + (char *) CurrentPath.Pointer, (UINT32) CurrentPath.Length, + (char *) TargetPath.Pointer, (UINT32) TargetPath.Length, ExternalNameString)); + + ACPI_FREE (ExternalNameString); + + /* + * Attempt an optmization depending on the type of namepath + */ + if (Flags & (AML_NAMED | AML_CREATE)) + { + /* + * This is a named opcode and the namepath is a name declaration, not + * a reference. + */ + Status = OptOptimizeNameDeclaration (Op, WalkState, CurrentNode, + TargetNode, AmlNameString, &NewPath); + if (ACPI_FAILURE (Status)) + { + /* + * 2) now attempt to + * optimize the namestring with carats (up-arrow) + */ + Status = OptBuildShortestPath (Op, WalkState, CurrentNode, + TargetNode, &CurrentPath, &TargetPath, + AmlNameStringLength, 1, &NewPath); + } + } + else + { + /* + * This is a reference to an existing named object + * + * 1) Check if search-to-root can be utilized using the last + * NameSeg of the NamePath + */ + Status = OptSearchToRoot (Op, WalkState, CurrentNode, + TargetNode, &TargetPath, &NewPath); + if (ACPI_FAILURE (Status)) + { + /* + * 2) Search-to-root could not be used, now attempt to + * optimize the namestring with carats (up-arrow) + */ + Status = OptBuildShortestPath (Op, WalkState, CurrentNode, + TargetNode, &CurrentPath, &TargetPath, + AmlNameStringLength, 0, &NewPath); + } + } + + /* + * Success from above indicates that the NamePath was successfully + * optimized. We need to update the parse op with the new name + */ + if (ACPI_SUCCESS (Status)) + { + HowMuchShorter = (AmlNameStringLength - ACPI_STRLEN (NewPath)); + OptTotal += HowMuchShorter; + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " REDUCED %2u (%u)", + (UINT32) HowMuchShorter, OptTotal)); + + if (Flags & AML_NAMED) + { + if (Op->Asl.AmlOpcode == AML_ALIAS_OP) + { + /* + * ALIAS is the only oddball opcode, the name declaration + * (alias name) is the second operand + */ + Op->Asl.Child->Asl.Next->Asl.Value.String = NewPath; + Op->Asl.Child->Asl.Next->Asl.AmlLength = ACPI_STRLEN (NewPath); + } + else + { + Op->Asl.Child->Asl.Value.String = NewPath; + Op->Asl.Child->Asl.AmlLength = ACPI_STRLEN (NewPath); + } + } + else if (Flags & AML_CREATE) + { + /* Name must appear as the last parameter */ + + NextOp = Op->Asl.Child; + while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)) + { + NextOp = NextOp->Asl.Next; + } + /* Update the parse node with the new NamePath */ + + NextOp->Asl.Value.String = NewPath; + NextOp->Asl.AmlLength = ACPI_STRLEN (NewPath); + } + else + { + /* Update the parse node with the new NamePath */ + + Op->Asl.Value.String = NewPath; + Op->Asl.AmlLength = ACPI_STRLEN (NewPath); + } + } + else + { + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ALREADY OPTIMAL")); + } + + /* Cleanup path buffers */ + + ACPI_FREE (TargetPath.Pointer); + ACPI_FREE (CurrentPath.Pointer); + + ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "\n")); + return_VOID; +} + diff --git a/sys/contrib/dev/acpica/compiler/aslpredef.c b/sys/contrib/dev/acpica/compiler/aslpredef.c new file mode 100644 index 0000000..a5ebb83 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslpredef.c @@ -0,0 +1,839 @@ +/****************************************************************************** + * + * Module Name: aslpredef - support for ACPI predefined names + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define ACPI_CREATE_PREDEFINED_TABLE + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/acpredef.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslpredef") + + +/* Local prototypes */ + +static void +ApCheckForUnexpectedReturnValue ( + ACPI_PARSE_OBJECT *Op, + ASL_METHOD_INFO *MethodInfo); + +static UINT32 +ApCheckForSpecialName ( + ACPI_PARSE_OBJECT *Op, + char *Name); + +static void +ApCheckObjectType ( + ACPI_PARSE_OBJECT *Op, + UINT32 ExpectedBtypes); + +static void +ApGetExpectedTypes ( + char *Buffer, + UINT32 ExpectedBtypes); + + +/* + * Names for the types that can be returned by the predefined objects. + * Used for warning messages. Must be in the same order as the ACPI_RTYPEs + */ +static const char *AcpiRtypeNames[] = +{ + "/Integer", + "/String", + "/Buffer", + "/Package", + "/Reference", +}; + +/* + * Predefined names for use in Resource Descriptors. These names do not + * appear in the global Predefined Name table (since these names never + * appear in actual AML byte code, only in the original ASL) + */ +static const ACPI_PREDEFINED_INFO ResourceNames[] = { + {{"_ALN", 0, 0}}, + {{"_ASI", 0, 0}}, + {{"_ASZ", 0, 0}}, + {{"_ATT", 0, 0}}, + {{"_BAS", 0, 0}}, + {{"_BM_", 0, 0}}, + {{"_DBT", 0, 0}}, /* Acpi 5.0 */ + {{"_DEC", 0, 0}}, + {{"_DPL", 0, 0}}, /* Acpi 5.0 */ + {{"_DRS", 0, 0}}, /* Acpi 5.0 */ + {{"_END", 0, 0}}, /* Acpi 5.0 */ + {{"_FLC", 0, 0}}, /* Acpi 5.0 */ + {{"_GRA", 0, 0}}, + {{"_HE_", 0, 0}}, + {{"_INT", 0, 0}}, + {{"_IOR", 0, 0}}, /* Acpi 5.0 */ + {{"_LEN", 0, 0}}, + {{"_LIN", 0, 0}}, /* Acpi 5.0 */ + {{"_LL_", 0, 0}}, + {{"_MAF", 0, 0}}, + {{"_MAX", 0, 0}}, + {{"_MEM", 0, 0}}, + {{"_MIF", 0, 0}}, + {{"_MIN", 0, 0}}, + {{"_MOD", 0, 0}}, /* Acpi 5.0 */ + {{"_MTP", 0, 0}}, + {{"_PAR", 0, 0}}, /* Acpi 5.0 */ + {{"_PHA", 0, 0}}, /* Acpi 5.0 */ + {{"_PIN", 0, 0}}, /* Acpi 5.0 */ + {{"_PPI", 0, 0}}, /* Acpi 5.0 */ + {{"_POL", 0, 0}}, /* Acpi 5.0 */ + {{"_RBO", 0, 0}}, + {{"_RBW", 0, 0}}, + {{"_RNG", 0, 0}}, + {{"_RT_", 0, 0}}, /* Acpi 3.0 */ + {{"_RW_", 0, 0}}, + {{"_RXL", 0, 0}}, /* Acpi 5.0 */ + {{"_SHR", 0, 0}}, + {{"_SIZ", 0, 0}}, + {{"_SLV", 0, 0}}, /* Acpi 5.0 */ + {{"_SPE", 0, 0}}, /* Acpi 5.0 */ + {{"_STB", 0, 0}}, /* Acpi 5.0 */ + {{"_TRA", 0, 0}}, + {{"_TRS", 0, 0}}, + {{"_TSF", 0, 0}}, /* Acpi 3.0 */ + {{"_TTP", 0, 0}}, + {{"_TXL", 0, 0}}, /* Acpi 5.0 */ + {{"_TYP", 0, 0}}, + {{"_VEN", 0, 0}}, /* Acpi 5.0 */ + {{{0,0,0,0}, 0, 0}} /* Table terminator */ +}; + +static const ACPI_PREDEFINED_INFO ScopeNames[] = { + {{"_SB_", 0, 0}}, + {{"_SI_", 0, 0}}, + {{"_TZ_", 0, 0}}, + {{{0,0,0,0}, 0, 0}} /* Table terminator */ +}; + + +/******************************************************************************* + * + * FUNCTION: ApCheckForPredefinedMethod + * + * PARAMETERS: Op - A parse node of type "METHOD". + * MethodInfo - Saved info about this method + * + * RETURN: None + * + * DESCRIPTION: If method is a predefined name, check that the number of + * arguments and the return type (returns a value or not) + * is correct. + * + ******************************************************************************/ + +BOOLEAN +ApCheckForPredefinedMethod ( + ACPI_PARSE_OBJECT *Op, + ASL_METHOD_INFO *MethodInfo) +{ + UINT32 Index; + UINT32 RequiredArgsCurrent; + UINT32 RequiredArgsOld; + + + /* Check for a match against the predefined name list */ + + Index = ApCheckForPredefinedName (Op, Op->Asl.NameSeg); + + switch (Index) + { + case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ + case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ + case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ + + /* Just return, nothing to do */ + return (FALSE); + + + case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */ + + Gbl_ReservedMethods++; + + /* NumArguments must be zero for all _Lxx/_Exx/_Wxx/_Qxx methods */ + + if (MethodInfo->NumArguments != 0) + { + sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName, 0); + + AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, + MsgBuffer); + } + break; + + + default: + /* + * Matched a predefined method name + * + * Validate the ASL-defined argument count. Allow two different legal + * arg counts. + */ + Gbl_ReservedMethods++; + + RequiredArgsCurrent = PredefinedNames[Index].Info.ParamCount & 0x0F; + RequiredArgsOld = PredefinedNames[Index].Info.ParamCount >> 4; + + if ((MethodInfo->NumArguments != RequiredArgsCurrent) && + (MethodInfo->NumArguments != RequiredArgsOld)) + { + sprintf (MsgBuffer, "%4.4s requires %u", + PredefinedNames[Index].Info.Name, RequiredArgsCurrent); + + if (MethodInfo->NumArguments > RequiredArgsCurrent) + { + AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_HI, Op, + MsgBuffer); + } + else + { + AslError (ASL_WARNING, ASL_MSG_RESERVED_ARG_COUNT_LO, Op, + MsgBuffer); + } + } + + /* + * Check if method returns no value, but the predefined name is + * required to return a value + */ + if (MethodInfo->NumReturnNoValue && + PredefinedNames[Index].Info.ExpectedBtypes) + { + ApGetExpectedTypes (StringBuffer, + PredefinedNames[Index].Info.ExpectedBtypes); + + sprintf (MsgBuffer, "%s required for %4.4s", + StringBuffer, PredefinedNames[Index].Info.Name); + + AslError (ASL_WARNING, ASL_MSG_RESERVED_RETURN_VALUE, Op, + MsgBuffer); + } + break; + } + + return (TRUE); +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckForUnexpectedReturnValue + * + * PARAMETERS: Op - A parse node of type "RETURN". + * MethodInfo - Saved info about this method + * + * RETURN: None + * + * DESCRIPTION: Check for an unexpected return value from a predefined method. + * Invoked for predefined methods that are defined to not return + * any value. If there is a return value, issue a remark, since + * the ASL writer may be confused as to the method definition + * and/or functionality. + * + * Note: We ignore all return values of "Zero", since this is what a standalone + * Return() statement will always generate -- so we ignore it here -- + * i.e., there is no difference between Return() and Return(Zero). + * Also, a null Return() will be disassembled to return(Zero) -- so, we + * don't want to generate extraneous remarks/warnings for a disassembled + * ASL file. + * + ******************************************************************************/ + +static void +ApCheckForUnexpectedReturnValue ( + ACPI_PARSE_OBJECT *Op, + ASL_METHOD_INFO *MethodInfo) +{ + ACPI_PARSE_OBJECT *ReturnValueOp; + + + /* Ignore Return() and Return(Zero) (they are the same) */ + + ReturnValueOp = Op->Asl.Child; + if (ReturnValueOp->Asl.ParseOpcode == PARSEOP_ZERO) + { + return; + } + + /* We have a valid return value, but the reserved name did not expect it */ + + AslError (ASL_WARNING, ASL_MSG_RESERVED_NO_RETURN_VAL, + Op, MethodInfo->Op->Asl.ExternalName); +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckPredefinedReturnValue + * + * PARAMETERS: Op - A parse node of type "RETURN". + * MethodInfo - Saved info about this method + * + * RETURN: None + * + * DESCRIPTION: If method is a predefined name, attempt to validate the return + * value. Only "static" types can be validated - a simple return + * of an integer/string/buffer/package or a named reference to + * a static object. Values such as a Localx or Argx or a control + * method invocation are not checked. Issue a warning if there is + * a valid return value, but the reserved method defines no + * return value. + * + ******************************************************************************/ + +void +ApCheckPredefinedReturnValue ( + ACPI_PARSE_OBJECT *Op, + ASL_METHOD_INFO *MethodInfo) +{ + UINT32 Index; + ACPI_PARSE_OBJECT *ReturnValueOp; + + + /* Check parent method for a match against the predefined name list */ + + Index = ApCheckForPredefinedName (MethodInfo->Op, + MethodInfo->Op->Asl.NameSeg); + + switch (Index) + { + case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */ + + /* No return value expected, warn if there is one */ + + ApCheckForUnexpectedReturnValue (Op, MethodInfo); + return; + + case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ + case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ + case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ + + /* Just return, nothing to do */ + return; + + default: /* A standard predefined ACPI name */ + + if (!PredefinedNames[Index].Info.ExpectedBtypes) + { + /* No return value expected, warn if there is one */ + + ApCheckForUnexpectedReturnValue (Op, MethodInfo); + return; + } + + /* Get the object returned, it is the next argument */ + + ReturnValueOp = Op->Asl.Child; + switch (ReturnValueOp->Asl.ParseOpcode) + { + case PARSEOP_ZERO: + case PARSEOP_ONE: + case PARSEOP_ONES: + case PARSEOP_INTEGER: + case PARSEOP_STRING_LITERAL: + case PARSEOP_BUFFER: + case PARSEOP_PACKAGE: + + /* Static data return object - check against expected type */ + + ApCheckObjectType (ReturnValueOp, + PredefinedNames[Index].Info.ExpectedBtypes); + break; + + default: + + /* + * All other ops are very difficult or impossible to typecheck at + * compile time. These include all Localx, Argx, and method + * invocations. Also, NAMESEG and NAMESTRING because the type of + * any named object can be changed at runtime (for example, + * CopyObject will change the type of the target object.) + */ + break; + } + } +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckForPredefinedObject + * + * PARAMETERS: Op - A parse node + * Name - The ACPI name to be checked + * + * RETURN: None + * + * DESCRIPTION: Check for a predefined name for a static object (created via + * the ASL Name operator). If it is a predefined ACPI name, ensure + * that the name does not require any arguments (which would + * require a control method implemenation of the name), and that + * the type of the object is one of the expected types for the + * predefined name. + * + ******************************************************************************/ + +void +ApCheckForPredefinedObject ( + ACPI_PARSE_OBJECT *Op, + char *Name) +{ + UINT32 Index; + + + /* + * Check for a real predefined name -- not a resource descriptor name + * or a predefined scope name + */ + Index = ApCheckForPredefinedName (Op, Name); + + switch (Index) + { + case ACPI_NOT_RESERVED_NAME: /* No underscore or _Txx or _xxx name not matched */ + case ACPI_PREDEFINED_NAME: /* Resource Name or reserved scope name */ + case ACPI_COMPILER_RESERVED_NAME: /* A _Txx that was not emitted by compiler */ + + /* Nothing to do */ + return; + + case ACPI_EVENT_RESERVED_NAME: /* _Lxx/_Exx/_Wxx/_Qxx methods */ + + /* + * These names must be control methods, by definition in ACPI spec. + * Also because they are defined to return no value. None of them + * require any arguments. + */ + AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op, + "with zero arguments"); + return; + + default: /* A standard predefined ACPI name */ + + /* + * If this predefined name requires input arguments, then + * it must be implemented as a control method + */ + if (PredefinedNames[Index].Info.ParamCount > 0) + { + AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op, + "with arguments"); + return; + } + + /* + * If no return value is expected from this predefined name, then + * it follows that it must be implemented as a control method + * (with zero args, because the args > 0 case was handled above) + * Examples are: _DIS, _INI, _IRC, _OFF, _ON, _PSx + */ + if (!PredefinedNames[Index].Info.ExpectedBtypes) + { + AslError (ASL_ERROR, ASL_MSG_RESERVED_METHOD, Op, + "with zero arguments"); + return; + } + + /* Typecheck the actual object, it is the next argument */ + + ApCheckObjectType (Op->Asl.Child->Asl.Next, + PredefinedNames[Index].Info.ExpectedBtypes); + return; + } +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckForPredefinedName + * + * PARAMETERS: Op - A parse node + * Name - NameSeg to check + * + * RETURN: None + * + * DESCRIPTION: Check a NameSeg against the reserved list. + * + ******************************************************************************/ + +UINT32 +ApCheckForPredefinedName ( + ACPI_PARSE_OBJECT *Op, + char *Name) +{ + UINT32 i; + + + if (Name[0] == 0) + { + AcpiOsPrintf ("Found a null name, external = %s\n", + Op->Asl.ExternalName); + } + + /* All reserved names are prefixed with a single underscore */ + + if (Name[0] != '_') + { + return (ACPI_NOT_RESERVED_NAME); + } + + /* Check for a standard predefined method name */ + + for (i = 0; PredefinedNames[i].Info.Name[0]; i++) + { + if (ACPI_COMPARE_NAME (Name, PredefinedNames[i].Info.Name)) + { + /* Return index into predefined array */ + return (i); + } + } + + /* Check for resource names and predefined scope names */ + + for (i = 0; ResourceNames[i].Info.Name[0]; i++) + { + if (ACPI_COMPARE_NAME (Name, ResourceNames[i].Info.Name)) + { + return (ACPI_PREDEFINED_NAME); + } + } + + for (i = 0; ScopeNames[i].Info.Name[0]; i++) + { + if (ACPI_COMPARE_NAME (Name, ScopeNames[i].Info.Name)) + { + return (ACPI_PREDEFINED_NAME); + } + } + + /* Check for _Lxx/_Exx/_Wxx/_Qxx/_T_x. Warning if unknown predefined name */ + + return (ApCheckForSpecialName (Op, Name)); +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckForSpecialName + * + * PARAMETERS: Op - A parse node + * Name - NameSeg to check + * + * RETURN: None + * + * DESCRIPTION: Check for the "special" predefined names - + * _Lxx, _Exx, _Qxx, _Wxx, and _T_x + * + ******************************************************************************/ + +static UINT32 +ApCheckForSpecialName ( + ACPI_PARSE_OBJECT *Op, + char *Name) +{ + + /* + * Check for the "special" predefined names. We already know that the + * first character is an underscore. + * GPE: _Lxx + * GPE: _Exx + * GPE: _Wxx + * EC: _Qxx + */ + if ((Name[1] == 'L') || + (Name[1] == 'E') || + (Name[1] == 'W') || + (Name[1] == 'Q')) + { + /* The next two characters must be hex digits */ + + if ((isxdigit ((int) Name[2])) && + (isxdigit ((int) Name[3]))) + { + return (ACPI_EVENT_RESERVED_NAME); + } + } + + /* Check for the names reserved for the compiler itself: _T_x */ + + else if ((Op->Asl.ExternalName[1] == 'T') && + (Op->Asl.ExternalName[2] == '_')) + { + /* Ignore if actually emitted by the compiler */ + + if (Op->Asl.CompileFlags & NODE_COMPILER_EMITTED) + { + return (ACPI_NOT_RESERVED_NAME); + } + + /* + * Was not actually emitted by the compiler. This is a special case, + * however. If the ASL code being compiled was the result of a + * dissasembly, it may possibly contain valid compiler-emitted names + * of the form "_T_x". We don't want to issue an error or even a + * warning and force the user to manually change the names. So, we + * will issue a remark instead. + */ + AslError (ASL_REMARK, ASL_MSG_COMPILER_RESERVED, Op, Op->Asl.ExternalName); + return (ACPI_COMPILER_RESERVED_NAME); + } + + /* + * The name didn't match any of the known predefined names. Flag it as a + * warning, since the entire namespace starting with an underscore is + * reserved by the ACPI spec. + */ + AslError (ASL_WARNING, ASL_MSG_UNKNOWN_RESERVED_NAME, Op, + Op->Asl.ExternalName); + + return (ACPI_NOT_RESERVED_NAME); +} + + +/******************************************************************************* + * + * FUNCTION: ApCheckObjectType + * + * PARAMETERS: Op - Current parse node + * ExpectedBtypes - Bitmap of expected return type(s) + * + * RETURN: None + * + * DESCRIPTION: Check if the object type is one of the types that is expected + * by the predefined name. Only a limited number of object types + * can be returned by the predefined names. + * + ******************************************************************************/ + +static void +ApCheckObjectType ( + ACPI_PARSE_OBJECT *Op, + UINT32 ExpectedBtypes) +{ + UINT32 ReturnBtype; + + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_ZERO: + case PARSEOP_ONE: + case PARSEOP_ONES: + case PARSEOP_INTEGER: + ReturnBtype = ACPI_RTYPE_INTEGER; + break; + + case PARSEOP_BUFFER: + ReturnBtype = ACPI_RTYPE_BUFFER; + break; + + case PARSEOP_STRING_LITERAL: + ReturnBtype = ACPI_RTYPE_STRING; + break; + + case PARSEOP_PACKAGE: + case PARSEOP_VAR_PACKAGE: + ReturnBtype = ACPI_RTYPE_PACKAGE; + break; + + default: + /* Not one of the supported object types */ + + goto TypeErrorExit; + } + + /* Exit if the object is one of the expected types */ + + if (ReturnBtype & ExpectedBtypes) + { + return; + } + + +TypeErrorExit: + + /* Format the expected types and emit an error message */ + + ApGetExpectedTypes (StringBuffer, ExpectedBtypes); + + sprintf (MsgBuffer, "found %s, requires %s", + UtGetOpName (Op->Asl.ParseOpcode), StringBuffer); + + AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, + MsgBuffer); +} + + +/******************************************************************************* + * + * FUNCTION: ApDisplayReservedNames + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Dump information about the ACPI predefined names and predefined + * resource descriptor names. + * + ******************************************************************************/ + +void +ApDisplayReservedNames ( + void) +{ + const ACPI_PREDEFINED_INFO *ThisName; + char TypeBuffer[48]; /* Room for 5 types */ + UINT32 Count; + + + /* + * Predefined names/methods + */ + printf ("\nPredefined Name Information\n\n"); + + Count = 0; + ThisName = PredefinedNames; + while (ThisName->Info.Name[0]) + { + printf ("%4.4s Requires %u arguments, ", + ThisName->Info.Name, ThisName->Info.ParamCount & 0x0F); + + if (ThisName->Info.ExpectedBtypes) + { + ApGetExpectedTypes (TypeBuffer, ThisName->Info.ExpectedBtypes); + printf ("Must return: %s\n", TypeBuffer); + } + else + { + printf ("No return value\n"); + } + + /* + * Skip next entry in the table if this name returns a Package + * (next entry contains the package info) + */ + if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE) + { + ThisName++; + } + + Count++; + ThisName++; + } + + printf ("%u Predefined Names are recognized\n", Count); + + /* + * Resource Descriptor names + */ + printf ("\nResource Descriptor Predefined Names\n\n"); + + Count = 0; + ThisName = ResourceNames; + while (ThisName->Info.Name[0]) + { + printf ("%4.4s Resource Descriptor\n", ThisName->Info.Name); + Count++; + ThisName++; + } + + printf ("%u Resource Descriptor Names are recognized\n", Count); + + /* + * Predefined scope names + */ + printf ("\nPredefined Scope Names\n\n"); + + ThisName = ScopeNames; + while (ThisName->Info.Name[0]) + { + printf ("%4.4s Scope\n", ThisName->Info.Name); + ThisName++; + } +} + + +/******************************************************************************* + * + * FUNCTION: ApGetExpectedTypes + * + * PARAMETERS: Buffer - Where the formatted string is returned + * ExpectedBTypes - Bitfield of expected data types + * + * RETURN: None, formatted string + * + * DESCRIPTION: Format the expected object types into a printable string. + * + ******************************************************************************/ + +static void +ApGetExpectedTypes ( + char *Buffer, + UINT32 ExpectedBtypes) +{ + UINT32 ThisRtype; + UINT32 i; + UINT32 j; + + + j = 1; + Buffer[0] = 0; + ThisRtype = ACPI_RTYPE_INTEGER; + + for (i = 0; i < ACPI_NUM_RTYPES; i++) + { + /* If one of the expected types, concatenate the name of this type */ + + if (ExpectedBtypes & ThisRtype) + { + ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]); + j = 0; /* Use name separator from now on */ + } + ThisRtype <<= 1; /* Next Rtype */ + } +} diff --git a/sys/contrib/dev/acpica/compiler/aslresource.c b/sys/contrib/dev/acpica/compiler/aslresource.c new file mode 100644 index 0000000..2a576a8 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslresource.c @@ -0,0 +1,1066 @@ + +/****************************************************************************** + * + * Module Name: aslresource - Resource template/descriptor utilities + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslresource") + + +/******************************************************************************* + * + * FUNCTION: RsSmallAddressCheck + * + * PARAMETERS: Minimum - Address Min value + * Maximum - Address Max value + * Length - Address range value + * Alignment - Address alignment value + * MinOp - Original Op for Address Min + * MaxOp - Original Op for Address Max + * LengthOp - Original Op for address range + * AlignOp - Original Op for address alignment. If + * NULL, means "zero value for alignment is + * OK, and means 64K alignment" (for + * Memory24 descriptor) + * Op - Parent Op for entire construct + * + * RETURN: None. Adds error messages to error log if necessary + * + * DESCRIPTION: Perform common value checks for "small" address descriptors. + * Currently: + * Io, Memory24, Memory32 + * + ******************************************************************************/ + +void +RsSmallAddressCheck ( + UINT8 Type, + UINT32 Minimum, + UINT32 Maximum, + UINT32 Length, + UINT32 Alignment, + ACPI_PARSE_OBJECT *MinOp, + ACPI_PARSE_OBJECT *MaxOp, + ACPI_PARSE_OBJECT *LengthOp, + ACPI_PARSE_OBJECT *AlignOp, + ACPI_PARSE_OBJECT *Op) +{ + + if (Gbl_NoResourceChecking) + { + return; + } + + /* + * Check for a so-called "null descriptor". These are descriptors that are + * created with most fields set to zero. The intent is that the descriptor + * will be updated/completed at runtime via a BufferField. + * + * If the descriptor does NOT have a resource tag, it cannot be referenced + * by a BufferField and we will flag this as an error. Conversely, if + * the descriptor has a resource tag, we will assume that a BufferField + * will be used to dynamically update it, so no error. + * + * A possible enhancement to this check would be to verify that in fact + * a BufferField is created using the resource tag, and perhaps even + * verify that a Store is performed to the BufferField. + * + * Note: for these descriptors, Alignment is allowed to be zero + */ + if (!Minimum && !Maximum && !Length) + { + if (!Op->Asl.ExternalName) + { + /* No resource tag. Descriptor is fixed and is also illegal */ + + AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL); + } + + return; + } + + /* Special case for Memory24, values are compressed */ + + if (Type == ACPI_RESOURCE_NAME_MEMORY24) + { + if (!Alignment) /* Alignment==0 means 64K - no invalid alignment */ + { + Alignment = ACPI_UINT16_MAX + 1; + } + + Minimum <<= 8; + Maximum <<= 8; + Length *= 256; + } + + /* IO descriptor has different definition of min/max, don't check */ + + if (Type != ACPI_RESOURCE_NAME_IO) + { + /* Basic checks on Min/Max/Length */ + + if (Minimum > Maximum) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL); + } + else if (Length > (Maximum - Minimum + 1)) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL); + } + } + + /* Alignment of zero is not in ACPI spec, but is used to mean byte acc */ + + if (!Alignment) + { + Alignment = 1; + } + + /* Addresses must be an exact multiple of the alignment value */ + + if (Minimum % Alignment) + { + AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL); + } + if (Maximum % Alignment) + { + AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, NULL); + } +} + + +/******************************************************************************* + * + * FUNCTION: RsLargeAddressCheck + * + * PARAMETERS: Minimum - Address Min value + * Maximum - Address Max value + * Length - Address range value + * Granularity - Address granularity value + * Flags - General flags for address descriptors: + * _MIF, _MAF, _DEC + * MinOp - Original Op for Address Min + * MaxOp - Original Op for Address Max + * LengthOp - Original Op for address range + * GranOp - Original Op for address granularity + * Op - Parent Op for entire construct + * + * RETURN: None. Adds error messages to error log if necessary + * + * DESCRIPTION: Perform common value checks for "large" address descriptors. + * Currently: + * WordIo, WordBusNumber, WordSpace + * DWordIo, DWordMemory, DWordSpace + * QWordIo, QWordMemory, QWordSpace + * ExtendedIo, ExtendedMemory, ExtendedSpace + * + * _MIF flag set means that the minimum address is fixed and is not relocatable + * _MAF flag set means that the maximum address is fixed and is not relocatable + * Length of zero means that the record size is variable + * + * This function implements the LEN/MIF/MAF/MIN/MAX/GRA rules within Table 6-40 + * of the ACPI 4.0a specification. Added 04/2010. + * + ******************************************************************************/ + +void +RsLargeAddressCheck ( + UINT64 Minimum, + UINT64 Maximum, + UINT64 Length, + UINT64 Granularity, + UINT8 Flags, + ACPI_PARSE_OBJECT *MinOp, + ACPI_PARSE_OBJECT *MaxOp, + ACPI_PARSE_OBJECT *LengthOp, + ACPI_PARSE_OBJECT *GranOp, + ACPI_PARSE_OBJECT *Op) +{ + + if (Gbl_NoResourceChecking) + { + return; + } + + /* + * Check for a so-called "null descriptor". These are descriptors that are + * created with most fields set to zero. The intent is that the descriptor + * will be updated/completed at runtime via a BufferField. + * + * If the descriptor does NOT have a resource tag, it cannot be referenced + * by a BufferField and we will flag this as an error. Conversely, if + * the descriptor has a resource tag, we will assume that a BufferField + * will be used to dynamically update it, so no error. + * + * A possible enhancement to this check would be to verify that in fact + * a BufferField is created using the resource tag, and perhaps even + * verify that a Store is performed to the BufferField. + */ + if (!Minimum && !Maximum && !Length && !Granularity) + { + if (!Op->Asl.ExternalName) + { + /* No resource tag. Descriptor is fixed and is also illegal */ + + AslError (ASL_ERROR, ASL_MSG_NULL_DESCRIPTOR, Op, NULL); + } + + return; + } + + /* Basic checks on Min/Max/Length */ + + if (Minimum > Maximum) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_MIN_MAX, MinOp, NULL); + return; + } + else if (Length > (Maximum - Minimum + 1)) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH, LengthOp, NULL); + return; + } + + /* If specified (non-zero), ensure granularity is a power-of-two minus one */ + + if (Granularity) + { + if ((Granularity + 1) & + Granularity) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_GRANULARITY, GranOp, NULL); + return; + } + } + + /* + * Check the various combinations of Length, MinFixed, and MaxFixed + */ + if (Length) + { + /* Fixed non-zero length */ + + switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF)) + { + case 0: + /* + * Fixed length, variable locations (both _MIN and _MAX). + * Length must be a multiple of granularity + */ + if (Granularity & Length) + { + AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, LengthOp, NULL); + } + break; + + case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF): + + /* Fixed length, fixed location. Granularity must be zero */ + + if (Granularity != 0) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_GRAN_FIXED, GranOp, NULL); + } + + /* Length must be exactly the size of the min/max window */ + + if (Length != (Maximum - Minimum + 1)) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_LENGTH_FIXED, LengthOp, NULL); + } + break; + + /* All other combinations are invalid */ + + case ACPI_RESOURCE_FLAG_MIF: + case ACPI_RESOURCE_FLAG_MAF: + default: + AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL); + } + } + else + { + /* Variable length (length==0) */ + + switch (Flags & (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF)) + { + case 0: + /* + * Both _MIN and _MAX are variable. + * No additional requirements, just exit + */ + break; + + case ACPI_RESOURCE_FLAG_MIF: + + /* _MIN is fixed. _MIN must be multiple of _GRA */ + + /* + * The granularity is defined by the ACPI specification to be a + * power-of-two minus one, therefore the granularity is a + * bitmask which can be used to easily validate the addresses. + */ + if (Granularity & Minimum) + { + AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MinOp, NULL); + } + break; + + case ACPI_RESOURCE_FLAG_MAF: + + /* _MAX is fixed. (_MAX + 1) must be multiple of _GRA */ + + if (Granularity & (Maximum + 1)) + { + AslError (ASL_ERROR, ASL_MSG_ALIGNMENT, MaxOp, "-1"); + } + break; + + /* Both MIF/MAF set is invalid if length is zero */ + + case (ACPI_RESOURCE_FLAG_MIF | ACPI_RESOURCE_FLAG_MAF): + default: + AslError (ASL_ERROR, ASL_MSG_INVALID_ADDR_FLAGS, LengthOp, NULL); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: RsGetStringDataLength + * + * PARAMETERS: InitializerOp - Start of a subtree of init nodes + * + * RETURN: Valid string length if a string node is found (otherwise 0) + * + * DESCRIPTION: In a list of peer nodes, find the first one that contains a + * string and return the length of the string. + * + ******************************************************************************/ + +UINT16 +RsGetStringDataLength ( + ACPI_PARSE_OBJECT *InitializerOp) +{ + + while (InitializerOp) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_STRING_LITERAL) + { + return ((UINT16) (strlen (InitializerOp->Asl.Value.String) + 1)); + } + InitializerOp = ASL_GET_PEER_NODE (InitializerOp); + } + + return 0; +} + + +/******************************************************************************* + * + * FUNCTION: RsAllocateResourceNode + * + * PARAMETERS: Size - Size of node in bytes + * + * RETURN: The allocated node - aborts on allocation failure + * + * DESCRIPTION: Allocate a resource description node and the resource + * descriptor itself (the nodes are used to link descriptors). + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsAllocateResourceNode ( + UINT32 Size) +{ + ASL_RESOURCE_NODE *Rnode; + + + /* Allocate the node */ + + Rnode = UtLocalCalloc (sizeof (ASL_RESOURCE_NODE)); + + /* Allocate the resource descriptor itself */ + + Rnode->Buffer = UtLocalCalloc (Size); + Rnode->BufferLength = Size; + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsCreateResourceField + * + * PARAMETERS: Op - Resource field node + * Name - Name of the field (Used only to reference + * the field in the ASL, not in the AML) + * ByteOffset - Offset from the field start + * BitOffset - Additional bit offset + * BitLength - Number of bits in the field + * + * RETURN: None, sets fields within the input node + * + * DESCRIPTION: Utility function to generate a named bit field within a + * resource descriptor. Mark a node as 1) a field in a resource + * descriptor, and 2) set the value to be a BIT offset + * + ******************************************************************************/ + +void +RsCreateResourceField ( + ACPI_PARSE_OBJECT *Op, + char *Name, + UINT32 ByteOffset, + UINT32 BitOffset, + UINT32 BitLength) +{ + + Op->Asl.ExternalName = Name; + Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD; + + + Op->Asl.Value.Tag.BitOffset = (ByteOffset * 8) + BitOffset; + Op->Asl.Value.Tag.BitLength = BitLength; +} + + +/******************************************************************************* + * + * FUNCTION: RsSetFlagBits + * + * PARAMETERS: *Flags - Pointer to the flag byte + * Op - Flag initialization node + * Position - Bit position within the flag byte + * Default - Used if the node is DEFAULT. + * + * RETURN: Sets bits within the *Flags output byte. + * + * DESCRIPTION: Set a bit in a cumulative flags word from an initialization + * node. Will use a default value if the node is DEFAULT, meaning + * that no value was specified in the ASL. Used to merge multiple + * keywords into a single flags byte. + * + ******************************************************************************/ + +void +RsSetFlagBits ( + UINT8 *Flags, + ACPI_PARSE_OBJECT *Op, + UINT8 Position, + UINT8 DefaultBit) +{ + + if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + /* Use the default bit */ + + *Flags |= (DefaultBit << Position); + } + else + { + /* Use the bit specified in the initialization node */ + + *Flags |= (((UINT8) Op->Asl.Value.Integer) << Position); + } +} + + +void +RsSetFlagBits16 ( + UINT16 *Flags, + ACPI_PARSE_OBJECT *Op, + UINT8 Position, + UINT8 DefaultBit) +{ + + if (Op->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + /* Use the default bit */ + + *Flags |= (DefaultBit << Position); + } + else + { + /* Use the bit specified in the initialization node */ + + *Flags |= (((UINT16) Op->Asl.Value.Integer) << Position); + } +} + + +/******************************************************************************* + * + * FUNCTION: RsCompleteNodeAndGetNext + * + * PARAMETERS: Op - Resource node to be completed + * + * RETURN: The next peer to the input node. + * + * DESCRIPTION: Mark the current node completed and return the next peer. + * The node ParseOpcode is set to DEFAULT_ARG, meaning that + * this node is to be ignored from now on. + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +RsCompleteNodeAndGetNext ( + ACPI_PARSE_OBJECT *Op) +{ + + /* Mark this node unused */ + + Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + + /* Move on to the next peer node in the initializer list */ + + return (ASL_GET_PEER_NODE (Op)); +} + + +/******************************************************************************* + * + * FUNCTION: RsCheckListForDuplicates + * + * PARAMETERS: Op - First op in the initializer list + * + * RETURN: None + * + * DESCRIPTION: Check an initializer list for duplicate values. Emits an error + * if any duplicates are found. + * + ******************************************************************************/ + +void +RsCheckListForDuplicates ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *NextValueOp = Op; + ACPI_PARSE_OBJECT *NextOp; + UINT32 Value; + + + if (!Op) + { + return; + } + + /* Search list once for each value in the list */ + + while (NextValueOp) + { + Value = (UINT32) NextValueOp->Asl.Value.Integer; + + /* Compare this value to all remaining values in the list */ + + NextOp = ASL_GET_PEER_NODE (NextValueOp); + while (NextOp) + { + if (NextOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + /* Compare values */ + + if (Value == (UINT32) NextOp->Asl.Value.Integer) + { + /* Emit error only once per duplicate node */ + + if (!(NextOp->Asl.CompileFlags & NODE_IS_DUPLICATE)) + { + NextOp->Asl.CompileFlags |= NODE_IS_DUPLICATE; + AslError (ASL_ERROR, ASL_MSG_DUPLICATE_ITEM, + NextOp, NULL); + } + } + } + + NextOp = ASL_GET_PEER_NODE (NextOp); + } + + NextValueOp = ASL_GET_PEER_NODE (NextValueOp); + } +} + + +/******************************************************************************* + * + * FUNCTION: RsDoOneResourceDescriptor + * + * PARAMETERS: DescriptorTypeOp - Parent parse node of the descriptor + * CurrentByteOffset - Offset in the resource descriptor + * buffer. + * + * RETURN: A valid resource node for the descriptor + * + * DESCRIPTION: Dispatches the processing of one resource descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoOneResourceDescriptor ( + ACPI_PARSE_OBJECT *DescriptorTypeOp, + UINT32 CurrentByteOffset, + UINT8 *State) +{ + ASL_RESOURCE_NODE *Rnode = NULL; + + + /* Construct the resource */ + + switch (DescriptorTypeOp->Asl.ParseOpcode) + { + case PARSEOP_DMA: + Rnode = RsDoDmaDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_FIXEDDMA: + Rnode = RsDoFixedDmaDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_DWORDIO: + Rnode = RsDoDwordIoDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_DWORDMEMORY: + Rnode = RsDoDwordMemoryDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_DWORDSPACE: + Rnode = RsDoDwordSpaceDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_ENDDEPENDENTFN: + switch (*State) + { + case ACPI_RSTATE_NORMAL: + AslError (ASL_ERROR, ASL_MSG_MISSING_STARTDEPENDENT, + DescriptorTypeOp, NULL); + break; + + case ACPI_RSTATE_START_DEPENDENT: + AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING, + DescriptorTypeOp, NULL); + break; + + case ACPI_RSTATE_DEPENDENT_LIST: + default: + break; + } + + *State = ACPI_RSTATE_NORMAL; + Rnode = RsDoEndDependentDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_ENDTAG: + Rnode = RsDoEndTagDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_EXTENDEDIO: + Rnode = RsDoExtendedIoDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_EXTENDEDMEMORY: + Rnode = RsDoExtendedMemoryDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_EXTENDEDSPACE: + Rnode = RsDoExtendedSpaceDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_FIXEDIO: + Rnode = RsDoFixedIoDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_INTERRUPT: + Rnode = RsDoInterruptDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_IO: + Rnode = RsDoIoDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_IRQ: + Rnode = RsDoIrqDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_IRQNOFLAGS: + Rnode = RsDoIrqNoFlagsDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_MEMORY24: + Rnode = RsDoMemory24Descriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_MEMORY32: + Rnode = RsDoMemory32Descriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_MEMORY32FIXED: + Rnode = RsDoMemory32FixedDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_QWORDIO: + Rnode = RsDoQwordIoDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_QWORDMEMORY: + Rnode = RsDoQwordMemoryDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_QWORDSPACE: + Rnode = RsDoQwordSpaceDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_REGISTER: + Rnode = RsDoGeneralRegisterDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_STARTDEPENDENTFN: + switch (*State) + { + case ACPI_RSTATE_START_DEPENDENT: + AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING, + DescriptorTypeOp, NULL); + break; + + case ACPI_RSTATE_NORMAL: + case ACPI_RSTATE_DEPENDENT_LIST: + default: + break; + } + + *State = ACPI_RSTATE_START_DEPENDENT; + Rnode = RsDoStartDependentDescriptor (DescriptorTypeOp, + CurrentByteOffset); + *State = ACPI_RSTATE_DEPENDENT_LIST; + break; + + case PARSEOP_STARTDEPENDENTFN_NOPRI: + switch (*State) + { + case ACPI_RSTATE_START_DEPENDENT: + AslError (ASL_ERROR, ASL_MSG_DEPENDENT_NESTING, + DescriptorTypeOp, NULL); + break; + + case ACPI_RSTATE_NORMAL: + case ACPI_RSTATE_DEPENDENT_LIST: + default: + break; + } + + *State = ACPI_RSTATE_START_DEPENDENT; + Rnode = RsDoStartDependentNoPriDescriptor (DescriptorTypeOp, + CurrentByteOffset); + *State = ACPI_RSTATE_DEPENDENT_LIST; + break; + + case PARSEOP_VENDORLONG: + Rnode = RsDoVendorLargeDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_VENDORSHORT: + Rnode = RsDoVendorSmallDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_WORDBUSNUMBER: + Rnode = RsDoWordBusNumberDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_WORDIO: + Rnode = RsDoWordIoDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_WORDSPACE: + Rnode = RsDoWordSpaceDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_GPIO_INT: + Rnode = RsDoGpioIntDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_GPIO_IO: + Rnode = RsDoGpioIoDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_I2C_SERIALBUS: + Rnode = RsDoI2cSerialBusDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_SPI_SERIALBUS: + Rnode = RsDoSpiSerialBusDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_UART_SERIALBUS: + Rnode = RsDoUartSerialBusDescriptor (DescriptorTypeOp, + CurrentByteOffset); + break; + + case PARSEOP_DEFAULT_ARG: + /* Just ignore any of these, they are used as fillers/placeholders */ + break; + + default: + printf ("Unknown resource descriptor type [%s]\n", + DescriptorTypeOp->Asl.ParseOpName); + break; + } + + /* + * Mark original node as unused, but head of a resource descriptor. + * This allows the resource to be installed in the namespace so that + * references to the descriptor can be resolved. + */ + DescriptorTypeOp->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + DescriptorTypeOp->Asl.CompileFlags = NODE_IS_RESOURCE_DESC; + DescriptorTypeOp->Asl.Value.Integer = CurrentByteOffset; + + if (Rnode) + { + DescriptorTypeOp->Asl.FinalAmlLength = Rnode->BufferLength; + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsLinkDescriptorChain + * + * PARAMETERS: PreviousRnode - Pointer to the node that will be previous + * to the linked node, At exit, set to the + * last node in the new chain. + * Rnode - Resource node to link into the list + * + * RETURN: Cumulative buffer byte offset of the new segment of chain + * + * DESCRIPTION: Link a descriptor chain at the end of an existing chain. + * + ******************************************************************************/ + +UINT32 +RsLinkDescriptorChain ( + ASL_RESOURCE_NODE **PreviousRnode, + ASL_RESOURCE_NODE *Rnode) +{ + ASL_RESOURCE_NODE *LastRnode; + UINT32 CurrentByteOffset; + + + /* Anything to do? */ + + if (!Rnode) + { + return 0; + } + + /* Point the previous node to the new node */ + + (*PreviousRnode)->Next = Rnode; + CurrentByteOffset = Rnode->BufferLength; + + /* Walk to the end of the chain headed by Rnode */ + + LastRnode = Rnode; + while (LastRnode->Next) + { + LastRnode = LastRnode->Next; + CurrentByteOffset += LastRnode->BufferLength; + } + + /* Previous node becomes the last node in the chain */ + + *PreviousRnode = LastRnode; + return CurrentByteOffset; +} + + +/******************************************************************************* + * + * FUNCTION: RsDoResourceTemplate + * + * PARAMETERS: Op - Parent of a resource template list + * + * RETURN: None. Sets input node to point to a list of AML code + * + * DESCRIPTION: Merge a list of resource descriptors into a single AML buffer, + * in preparation for output to the AML output file. + * + ******************************************************************************/ + +void +RsDoResourceTemplate ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *BufferLengthOp; + ACPI_PARSE_OBJECT *BufferOp; + ACPI_PARSE_OBJECT *DescriptorTypeOp; + ACPI_PARSE_OBJECT *LastOp = NULL; + UINT32 CurrentByteOffset = 0; + ASL_RESOURCE_NODE HeadRnode; + ASL_RESOURCE_NODE *PreviousRnode; + ASL_RESOURCE_NODE *Rnode; + UINT8 State; + + + /* Mark parent as containing a resource template */ + + if (Op->Asl.Parent) + { + Op->Asl.Parent->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC; + } + + /* ResourceTemplate Opcode is first (Op) */ + /* Buffer Length node is first child */ + + BufferLengthOp = ASL_GET_CHILD_NODE (Op); + + /* Buffer Op is first peer */ + + BufferOp = ASL_GET_PEER_NODE (BufferLengthOp); + + /* First Descriptor type is next */ + + DescriptorTypeOp = ASL_GET_PEER_NODE (BufferOp); + + /* + * Process all resource descriptors in the list + * Note: It is assumed that the EndTag node has been automatically + * inserted at the end of the template by the parser. + */ + State = ACPI_RSTATE_NORMAL; + PreviousRnode = &HeadRnode; + while (DescriptorTypeOp) + { + DescriptorTypeOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DESC; + Rnode = RsDoOneResourceDescriptor (DescriptorTypeOp, CurrentByteOffset, + &State); + + /* + * Update current byte offset to indicate the number of bytes from the + * start of the buffer. Buffer can include multiple descriptors, we + * must keep track of the offset of not only each descriptor, but each + * element (field) within each descriptor as well. + */ + CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, Rnode); + + /* Get the next descriptor in the list */ + + LastOp = DescriptorTypeOp; + DescriptorTypeOp = ASL_GET_PEER_NODE (DescriptorTypeOp); + } + + if (State == ACPI_RSTATE_DEPENDENT_LIST) + { + if (LastOp) + { + LastOp = LastOp->Asl.Parent; + } + AslError (ASL_ERROR, ASL_MSG_MISSING_ENDDEPENDENT, LastOp, NULL); + } + + /* + * Transform the nodes into the following + * + * Op -> AML_BUFFER_OP + * First Child -> BufferLength + * Second Child -> Descriptor Buffer (raw byte data) + */ + Op->Asl.ParseOpcode = PARSEOP_BUFFER; + Op->Asl.AmlOpcode = AML_BUFFER_OP; + Op->Asl.CompileFlags = NODE_AML_PACKAGE | NODE_IS_RESOURCE_DESC; + UtSetParseOpName (Op); + + BufferLengthOp->Asl.ParseOpcode = PARSEOP_INTEGER; + BufferLengthOp->Asl.Value.Integer = CurrentByteOffset; + (void) OpcSetOptimalIntegerSize (BufferLengthOp); + UtSetParseOpName (BufferLengthOp); + + BufferOp->Asl.ParseOpcode = PARSEOP_RAW_DATA; + BufferOp->Asl.AmlOpcode = AML_RAW_DATA_CHAIN; + BufferOp->Asl.AmlOpcodeLength = 0; + BufferOp->Asl.AmlLength = CurrentByteOffset; + BufferOp->Asl.Value.Buffer = (UINT8 *) HeadRnode.Next; + BufferOp->Asl.CompileFlags |= NODE_IS_RESOURCE_DATA; + UtSetParseOpName (BufferOp); + + return; +} diff --git a/sys/contrib/dev/acpica/compiler/aslrestype1.c b/sys/contrib/dev/acpica/compiler/aslrestype1.c new file mode 100644 index 0000000..23421dc --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype1.c @@ -0,0 +1,653 @@ + +/****************************************************************************** + * + * Module Name: aslrestype1 - Miscellaneous small resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype1") + +/* + * This module contains miscellaneous small resource descriptors: + * + * EndTag + * EndDependentFn + * Memory24 + * Memory32 + * Memory32Fixed + * StartDependentFn + * StartDependentFnNoPri + * VendorShort + */ + +/******************************************************************************* + * + * FUNCTION: RsDoEndTagDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "EndDependentFn" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoEndTagDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ASL_RESOURCE_NODE *Rnode; + + + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_END_TAG)); + + Descriptor = Rnode->Buffer; + Descriptor->EndTag.DescriptorType = ACPI_RESOURCE_NAME_END_TAG | + ASL_RDESC_END_TAG_SIZE; + Descriptor->EndTag.Checksum = 0; + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoEndDependentDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "EndDependentFn" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoEndDependentDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ASL_RESOURCE_NODE *Rnode; + + + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_END_DEPENDENT)); + + Descriptor = Rnode->Buffer; + Descriptor->EndDpf.DescriptorType = ACPI_RESOURCE_NAME_END_DEPENDENT | + ASL_RDESC_END_DEPEND_SIZE; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoMemory24Descriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "Memory24" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoMemory24Descriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_MEMORY24)); + + Descriptor = Rnode->Buffer; + Descriptor->Memory24.DescriptorType = ACPI_RESOURCE_NAME_MEMORY24; + Descriptor->Memory24.ResourceLength = 9; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Read/Write type */ + + RsSetFlagBits (&Descriptor->Memory24.Flags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Flags), 0); + break; + + case 1: /* Min Address */ + + Descriptor->Memory24.Minimum = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Minimum)); + MinOp = InitializerOp; + break; + + case 2: /* Max Address */ + + Descriptor->Memory24.Maximum = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Maximum)); + MaxOp = InitializerOp; + break; + + case 3: /* Alignment */ + + Descriptor->Memory24.Alignment = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_ALIGNMENT, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.Alignment)); + break; + + case 4: /* Length */ + + Descriptor->Memory24.AddressLength = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory24.AddressLength)); + LengthOp = InitializerOp; + break; + + case 5: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Align values (Alignment==0 means 64K) */ + + RsSmallAddressCheck (ACPI_RESOURCE_NAME_MEMORY24, + Descriptor->Memory24.Minimum, + Descriptor->Memory24.Maximum, + Descriptor->Memory24.AddressLength, + Descriptor->Memory24.Alignment, + MinOp, MaxOp, LengthOp, NULL, Op); + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoMemory32Descriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "Memory32" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoMemory32Descriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *AlignOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_MEMORY32)); + + Descriptor = Rnode->Buffer; + Descriptor->Memory32.DescriptorType = ACPI_RESOURCE_NAME_MEMORY32; + Descriptor->Memory32.ResourceLength = 17; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Read/Write type */ + + RsSetFlagBits (&Descriptor->Memory32.Flags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Flags), 0); + break; + + case 1: /* Min Address */ + + Descriptor->Memory32.Minimum = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Minimum)); + MinOp = InitializerOp; + break; + + case 2: /* Max Address */ + + Descriptor->Memory32.Maximum = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Maximum)); + MaxOp = InitializerOp; + break; + + case 3: /* Alignment */ + + Descriptor->Memory32.Alignment = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_ALIGNMENT, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.Alignment)); + AlignOp = InitializerOp; + break; + + case 4: /* Length */ + + Descriptor->Memory32.AddressLength = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Memory32.AddressLength)); + LengthOp = InitializerOp; + break; + + case 5: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Align values */ + + RsSmallAddressCheck (ACPI_RESOURCE_NAME_MEMORY32, + Descriptor->Memory32.Minimum, + Descriptor->Memory32.Maximum, + Descriptor->Memory32.AddressLength, + Descriptor->Memory32.Alignment, + MinOp, MaxOp, LengthOp, AlignOp, Op); + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoMemory32FixedDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "Memory32Fixed" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoMemory32FixedDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_FIXED_MEMORY32)); + + Descriptor = Rnode->Buffer; + Descriptor->FixedMemory32.DescriptorType = ACPI_RESOURCE_NAME_FIXED_MEMORY32; + Descriptor->FixedMemory32.ResourceLength = 9; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Read/Write type */ + + RsSetFlagBits (&Descriptor->FixedMemory32.Flags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedMemory32.Flags), 0); + break; + + case 1: /* Address */ + + Descriptor->FixedMemory32.Address = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_BASEADDRESS, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedMemory32.Address)); + break; + + case 2: /* Length */ + + Descriptor->FixedMemory32.AddressLength = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedMemory32.AddressLength)); + break; + + case 3: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoStartDependentDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "StartDependentFn" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoStartDependentDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + ASL_RESOURCE_NODE *PreviousRnode; + ASL_RESOURCE_NODE *NextRnode; + UINT32 i; + UINT8 State; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_START_DEPENDENT)); + + PreviousRnode = Rnode; + Descriptor = Rnode->Buffer; + + /* Increment offset past StartDependent descriptor */ + + CurrentByteOffset += sizeof (AML_RESOURCE_START_DEPENDENT); + + /* Descriptor has priority byte */ + + Descriptor->StartDpf.DescriptorType = ACPI_RESOURCE_NAME_START_DEPENDENT | + (ASL_RDESC_ST_DEPEND_SIZE + 0x01); + + /* Process all child initialization nodes */ + + State = ACPI_RSTATE_START_DEPENDENT; + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Compatibility Priority */ + + if ((UINT8) InitializerOp->Asl.Value.Integer > 2) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_PRIORITY, + InitializerOp, NULL); + } + + RsSetFlagBits (&Descriptor->StartDpf.Flags, InitializerOp, 0, 0); + break; + + case 1: /* Performance/Robustness Priority */ + + if ((UINT8) InitializerOp->Asl.Value.Integer > 2) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_PERFORMANCE, + InitializerOp, NULL); + } + + RsSetFlagBits (&Descriptor->StartDpf.Flags, InitializerOp, 2, 0); + break; + + default: + + NextRnode = RsDoOneResourceDescriptor (InitializerOp, + CurrentByteOffset, &State); + + /* + * Update current byte offset to indicate the number of bytes from the + * start of the buffer. Buffer can include multiple descriptors, we + * must keep track of the offset of not only each descriptor, but each + * element (field) within each descriptor as well. + */ + CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, + NextRnode); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoStartDependentNoPriDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "StartDependentNoPri" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoStartDependentNoPriDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + ASL_RESOURCE_NODE *PreviousRnode; + ASL_RESOURCE_NODE *NextRnode; + UINT8 State; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_START_DEPENDENT_NOPRIO)); + + Descriptor = Rnode->Buffer; + Descriptor->StartDpf.DescriptorType = ACPI_RESOURCE_NAME_START_DEPENDENT | + ASL_RDESC_ST_DEPEND_SIZE; + PreviousRnode = Rnode; + + /* Increment offset past StartDependentNoPri descriptor */ + + CurrentByteOffset += sizeof (AML_RESOURCE_START_DEPENDENT_NOPRIO); + + /* Process all child initialization nodes */ + + State = ACPI_RSTATE_START_DEPENDENT; + while (InitializerOp) + { + NextRnode = RsDoOneResourceDescriptor (InitializerOp, + CurrentByteOffset, &State); + + /* + * Update current byte offset to indicate the number of bytes from the + * start of the buffer. Buffer can include multiple descriptors, we + * must keep track of the offset of not only each descriptor, but each + * element (field) within each descriptor as well. + */ + CurrentByteOffset += RsLinkDescriptorChain (&PreviousRnode, NextRnode); + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoVendorSmallDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "VendorShort" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoVendorSmallDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT8 *VendorData; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + + /* Allocate worst case - 7 vendor bytes */ + + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_VENDOR_SMALL) + 7); + + Descriptor = Rnode->Buffer; + Descriptor->VendorSmall.DescriptorType = ACPI_RESOURCE_NAME_VENDOR_SMALL; + VendorData = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_SMALL_HEADER); + + /* Process all child initialization nodes */ + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + for (i = 0; InitializerOp; i++) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + break; + } + + /* Maximum 7 vendor data bytes allowed (0-6) */ + + if (i >= 7) + { + AslError (ASL_ERROR, ASL_MSG_VENDOR_LIST, InitializerOp, NULL); + + /* Eat the excess initializers */ + + while (InitializerOp) + { + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + break; + } + + VendorData[i] = (UINT8) InitializerOp->Asl.Value.Integer; + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Adjust the Rnode buffer size, so correct number of bytes are emitted */ + + Rnode->BufferLength -= (7 - i); + + /* Set the length in the Type Tag */ + + Descriptor->VendorSmall.DescriptorType |= (UINT8) i; + return (Rnode); +} + diff --git a/sys/contrib/dev/acpica/compiler/aslrestype1i.c b/sys/contrib/dev/acpica/compiler/aslrestype1i.c new file mode 100644 index 0000000..68f31e9 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype1i.c @@ -0,0 +1,672 @@ + +/****************************************************************************** + * + * Module Name: aslrestype1i - Small I/O-related resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype1i") + +/* + * This module contains the I/O-related small resource descriptors: + * + * DMA + * FixedDMA + * FixedIO + * IO + * IRQ + * IRQNoFlags + */ + +/******************************************************************************* + * + * FUNCTION: RsDoDmaDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "DMA" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoDmaDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + UINT8 DmaChannelMask = 0; + UINT8 DmaChannels = 0; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_DMA)); + + Descriptor = Rnode->Buffer; + Descriptor->Dma.DescriptorType = ACPI_RESOURCE_NAME_DMA | + ASL_RDESC_DMA_SIZE; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* DMA type */ + + RsSetFlagBits (&Descriptor->Dma.Flags, InitializerOp, 5, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_DMATYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Dma.Flags), 5, 2); + break; + + case 1: /* Bus Master */ + + RsSetFlagBits (&Descriptor->Dma.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_BUSMASTER, + CurrentByteOffset + ASL_RESDESC_OFFSET (Dma.Flags), 2); + break; + + case 2: /* Xfer Type (transfer width) */ + + RsSetFlagBits (&Descriptor->Dma.Flags, InitializerOp, 0, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_XFERTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Dma.Flags), 0, 2); + break; + + case 3: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + /* All DMA channel bytes are handled here, after flags and name */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + /* Up to 8 channels can be specified in the list */ + + DmaChannels++; + if (DmaChannels > 8) + { + AslError (ASL_ERROR, ASL_MSG_DMA_LIST, + InitializerOp, NULL); + return (Rnode); + } + + /* Only DMA channels 0-7 are allowed (mask is 8 bits) */ + + if (InitializerOp->Asl.Value.Integer > 7) + { + AslError (ASL_ERROR, ASL_MSG_DMA_CHANNEL, + InitializerOp, NULL); + } + + /* Build the mask */ + + DmaChannelMask |= + (1 << ((UINT8) InitializerOp->Asl.Value.Integer)); + } + + if (i == 4) /* case 4: First DMA byte */ + { + /* Check now for duplicates in list */ + + RsCheckListForDuplicates (InitializerOp); + + /* Create a named field at the start of the list */ + + RsCreateByteField (InitializerOp, ACPI_RESTAG_DMA, + CurrentByteOffset + + ASL_RESDESC_OFFSET (Dma.DmaChannelMask)); + } + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Now we can set the channel mask */ + + Descriptor->Dma.DmaChannelMask = DmaChannelMask; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoFixedDmaDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "FixedDMA" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoFixedDmaDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_FIXED_DMA)); + + Descriptor = Rnode->Buffer; + Descriptor->FixedDma.DescriptorType = + ACPI_RESOURCE_NAME_FIXED_DMA | ASL_RDESC_FIXED_DMA_SIZE; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* DMA Request Lines [WORD] (_DMA) */ + + Descriptor->FixedDma.RequestLines = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_DMA, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedDma.RequestLines)); + break; + + case 1: /* DMA Channel [WORD] (_TYP) */ + + Descriptor->FixedDma.Channels = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_DMATYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedDma.Channels)); + break; + + case 2: /* Transfer Width [BYTE] (_SIZ) */ + + Descriptor->FixedDma.Width = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_XFERTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedDma.Width)); + break; + + case 3: /* Descriptor Name (optional) */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: /* Ignore any extra nodes */ + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoFixedIoDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "FixedIO" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoFixedIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *AddressOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_FIXED_IO)); + + Descriptor = Rnode->Buffer; + Descriptor->Io.DescriptorType = ACPI_RESOURCE_NAME_FIXED_IO | + ASL_RDESC_FIXED_IO_SIZE; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Base Address */ + + Descriptor->FixedIo.Address = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_BASEADDRESS, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedIo.Address)); + AddressOp = InitializerOp; + break; + + case 1: /* Length */ + + Descriptor->FixedIo.AddressLength = + (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (FixedIo.AddressLength)); + break; + + case 2: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Error checks */ + + if (Descriptor->FixedIo.Address > 0x03FF) + { + AslError (ASL_WARNING, ASL_MSG_ISA_ADDRESS, AddressOp, NULL); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoIoDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "IO" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *AlignOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_IO)); + + Descriptor = Rnode->Buffer; + Descriptor->Io.DescriptorType = ACPI_RESOURCE_NAME_IO | + ASL_RDESC_IO_SIZE; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Decode size */ + + RsSetFlagBits (&Descriptor->Io.Flags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Flags), 0); + break; + + case 1: /* Min Address */ + + Descriptor->Io.Minimum = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Minimum)); + MinOp = InitializerOp; + break; + + case 2: /* Max Address */ + + Descriptor->Io.Maximum = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Maximum)); + MaxOp = InitializerOp; + break; + + case 3: /* Alignment */ + + Descriptor->Io.Alignment = + (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_ALIGNMENT, + CurrentByteOffset + ASL_RESDESC_OFFSET (Io.Alignment)); + AlignOp = InitializerOp; + break; + + case 4: /* Length */ + + Descriptor->Io.AddressLength = + (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Io.AddressLength)); + LengthOp = InitializerOp; + break; + + case 5: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Align values */ + + RsSmallAddressCheck (ACPI_RESOURCE_NAME_IO, + Descriptor->Io.Minimum, + Descriptor->Io.Maximum, + Descriptor->Io.AddressLength, + Descriptor->Io.Alignment, + MinOp, MaxOp, LengthOp, AlignOp, Op); + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoIrqDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "IRQ" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoIrqDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT32 Interrupts = 0; + UINT16 IrqMask = 0; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_IRQ)); + + /* Length = 3 (with flag byte) */ + + Descriptor = Rnode->Buffer; + Descriptor->Irq.DescriptorType = ACPI_RESOURCE_NAME_IRQ | + (ASL_RDESC_IRQ_SIZE + 0x01); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Interrupt Type (or Mode - edge/level) */ + + RsSetFlagBits (&Descriptor->Irq.Flags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.Flags), 0); + break; + + case 1: /* Interrupt Level (or Polarity - Active high/low) */ + + RsSetFlagBits (&Descriptor->Irq.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTLEVEL, + CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.Flags), 3); + break; + + case 2: /* Share Type - Default: exclusive (0) */ + + RsSetFlagBits (&Descriptor->Irq.Flags, InitializerOp, 4, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.Flags), 4); + break; + + case 3: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + /* All IRQ bytes are handled here, after the flags and name */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + /* Up to 16 interrupts can be specified in the list */ + + Interrupts++; + if (Interrupts > 16) + { + AslError (ASL_ERROR, ASL_MSG_INTERRUPT_LIST, + InitializerOp, NULL); + return (Rnode); + } + + /* Only interrupts 0-15 are allowed (mask is 16 bits) */ + + if (InitializerOp->Asl.Value.Integer > 15) + { + AslError (ASL_ERROR, ASL_MSG_INTERRUPT_NUMBER, + InitializerOp, NULL); + } + else + { + IrqMask |= (1 << (UINT8) InitializerOp->Asl.Value.Integer); + } + } + + /* Case 4: First IRQ value in list */ + + if (i == 4) + { + /* Check now for duplicates in list */ + + RsCheckListForDuplicates (InitializerOp); + + /* Create a named field at the start of the list */ + + RsCreateWordField (InitializerOp, ACPI_RESTAG_INTERRUPT, + CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.IrqMask)); + } + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Now we can set the channel mask */ + + Descriptor->Irq.IrqMask = IrqMask; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoIrqNoFlagsDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a short "IRQNoFlags" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoIrqNoFlagsDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT16 IrqMask = 0; + UINT32 Interrupts = 0; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_IRQ_NOFLAGS)); + + Descriptor = Rnode->Buffer; + Descriptor->Irq.DescriptorType = ACPI_RESOURCE_NAME_IRQ | + ASL_RDESC_IRQ_SIZE; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Name */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + /* IRQ bytes are handled here, after the flags and name */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + /* Up to 16 interrupts can be specified in the list */ + + Interrupts++; + if (Interrupts > 16) + { + AslError (ASL_ERROR, ASL_MSG_INTERRUPT_LIST, + InitializerOp, NULL); + return (Rnode); + } + + /* Only interrupts 0-15 are allowed (mask is 16 bits) */ + + if (InitializerOp->Asl.Value.Integer > 15) + { + AslError (ASL_ERROR, ASL_MSG_INTERRUPT_NUMBER, + InitializerOp, NULL); + } + else + { + IrqMask |= (1 << ((UINT8) InitializerOp->Asl.Value.Integer)); + } + } + + /* Case 1: First IRQ value in list */ + + if (i == 1) + { + /* Check now for duplicates in list */ + + RsCheckListForDuplicates (InitializerOp); + + /* Create a named field at the start of the list */ + + RsCreateWordField (InitializerOp, ACPI_RESTAG_INTERRUPT, + CurrentByteOffset + ASL_RESDESC_OFFSET (Irq.IrqMask)); + } + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Now we can set the interrupt mask */ + + Descriptor->Irq.IrqMask = IrqMask; + return (Rnode); +} diff --git a/sys/contrib/dev/acpica/compiler/aslrestype2.c b/sys/contrib/dev/acpica/compiler/aslrestype2.c new file mode 100644 index 0000000..4784f86 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype2.c @@ -0,0 +1,461 @@ +/****************************************************************************** + * + * Module Name: aslrestype2 - Miscellaneous Large resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype2") + +/* + * This module contains miscellaneous large resource descriptors: + * + * Register + * Interrupt + * VendorLong + */ + +/******************************************************************************* + * + * FUNCTION: RsDoGeneralRegisterDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "Register" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoGeneralRegisterDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_GENERIC_REGISTER)); + + Descriptor = Rnode->Buffer; + Descriptor->GenericReg.DescriptorType = ACPI_RESOURCE_NAME_GENERIC_REGISTER; + Descriptor->GenericReg.ResourceLength = 12; + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Address space */ + + Descriptor->GenericReg.AddressSpaceId = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_ADDRESSSPACE, + CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.AddressSpaceId)); + break; + + case 1: /* Register Bit Width */ + + Descriptor->GenericReg.BitWidth = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_REGISTERBITWIDTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.BitWidth)); + break; + + case 2: /* Register Bit Offset */ + + Descriptor->GenericReg.BitOffset = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_REGISTERBITOFFSET, + CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.BitOffset)); + break; + + case 3: /* Register Address */ + + Descriptor->GenericReg.Address = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_ADDRESS, + CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.Address)); + break; + + case 4: /* Access Size (ACPI 3.0) */ + + Descriptor->GenericReg.AccessSize = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_ACCESSSIZE, + CurrentByteOffset + ASL_RESDESC_OFFSET (GenericReg.AccessSize)); + + if (Descriptor->GenericReg.AccessSize > AML_FIELD_ACCESS_QWORD) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_ACCESS_SIZE, + InitializerOp, NULL); + } + break; + + case 5: /* ResourceTag (ACPI 3.0b) */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoInterruptDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "Interrupt" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoInterruptDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + AML_RESOURCE *Rover = NULL; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN HasResSourceIndex = FALSE; + UINT8 ResSourceIndex = 0; + UINT8 *ResSourceString = NULL; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + /* Count the interrupt numbers */ + + for (i = 0; InitializerOp; i++) + { + InitializerOp = ASL_GET_PEER_NODE (InitializerOp); + + if (i <= 6) + { + if (i == 3 && + InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + /* + * ResourceSourceIndex was specified, always make room for + * it, even if the ResourceSource was omitted. + */ + OptionIndex++; + } + + continue; + } + + OptionIndex += 4; + } + + InitializerOp = Op->Asl.Child; + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_EXTENDED_IRQ) + + 1 + OptionIndex + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->ExtendedIrq.DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_IRQ; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + Descriptor->ExtendedIrq.ResourceLength = 2; /* Flags and table length byte */ + Descriptor->ExtendedIrq.InterruptCount = 0; + + Rover = ACPI_CAST_PTR (AML_RESOURCE, + (&(Descriptor->ExtendedIrq.Interrupts[0]))); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage (Default: consumer (1) */ + + RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 0, 1); + break; + + case 1: /* Interrupt Type (or Mode - edge/level) */ + + RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 1); + break; + + case 2: /* Interrupt Level (or Polarity - Active high/low) */ + + RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTLEVEL, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 2); + break; + + case 3: /* Share Type - Default: exclusive (0) */ + + RsSetFlagBits (&Descriptor->ExtendedIrq.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtendedIrq.Flags), 3); + break; + + case 4: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + HasResSourceIndex = TRUE; + ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer; + } + break; + + case 5: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + ResSourceString = (UINT8 *) InitializerOp->Asl.Value.String; + } + + /* ResourceSourceIndex must also be valid */ + + if (!HasResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (HasResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 6: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + /* + * Interrupt Numbers come through here, repeatedly + */ + + /* Maximum 255 interrupts allowed for this descriptor */ + + if (Descriptor->ExtendedIrq.InterruptCount == 255) + { + AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST, + InitializerOp, NULL); + return (Rnode); + } + + /* Each interrupt number must be a 32-bit value */ + + if (InitializerOp->Asl.Value.Integer > ACPI_UINT32_MAX) + { + AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_NUMBER, + InitializerOp, NULL); + } + + /* Save the integer and move pointer to the next one */ + + Rover->DwordItem = (UINT32) InitializerOp->Asl.Value.Integer; + Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->DwordItem), 4); + Descriptor->ExtendedIrq.InterruptCount++; + Descriptor->ExtendedIrq.ResourceLength += 4; + + /* Case 7: First interrupt number in list */ + + if (i == 7) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + /* Must be at least one interrupt */ + + AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST_MIN, + InitializerOp, NULL); + } + + /* Check now for duplicates in list */ + + RsCheckListForDuplicates (InitializerOp); + + /* Create a named field at the start of the list */ + + RsCreateDwordField (InitializerOp, ACPI_RESTAG_INTERRUPT, + CurrentByteOffset + + ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0])); + } + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + + /* Add optional ResSourceIndex if present */ + + if (HasResSourceIndex) + { + Rover->ByteItem = ResSourceIndex; + Rover = ACPI_ADD_PTR (AML_RESOURCE, &(Rover->ByteItem), 1); + Descriptor->ExtendedIrq.ResourceLength += 1; + } + + /* Add optional ResSource string if present */ + + if (StringLength && ResSourceString) + { + + strcpy ((char *) Rover, (char *) ResSourceString); + Rover = ACPI_ADD_PTR ( + AML_RESOURCE, &(Rover->ByteItem), StringLength); + + Descriptor->ExtendedIrq.ResourceLength = (UINT16) + (Descriptor->ExtendedIrq.ResourceLength + StringLength); + } + + Rnode->BufferLength = (ASL_RESDESC_OFFSET (ExtendedIrq.Interrupts[0]) - + ASL_RESDESC_OFFSET (ExtendedIrq.DescriptorType)) + + OptionIndex + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoVendorLargeDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "VendorLong" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoVendorLargeDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + UINT8 *VendorData; + UINT32 i; + + + /* Count the number of data bytes */ + + InitializerOp = Op->Asl.Child; + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + + for (i = 0; InitializerOp; i++) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + break; + } + InitializerOp = InitializerOp->Asl.Next; + } + + InitializerOp = Op->Asl.Child; + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + Rnode = RsAllocateResourceNode (sizeof (AML_RESOURCE_VENDOR_LARGE) + i); + + Descriptor = Rnode->Buffer; + Descriptor->VendorLarge.DescriptorType = ACPI_RESOURCE_NAME_VENDOR_LARGE; + Descriptor->VendorLarge.ResourceLength = (UINT16) i; + + /* Point to end-of-descriptor for vendor data */ + + VendorData = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_LARGE_HEADER); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + break; + } + + VendorData[i] = (UINT8) InitializerOp->Asl.Value.Integer; + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} diff --git a/sys/contrib/dev/acpica/compiler/aslrestype2d.c b/sys/contrib/dev/acpica/compiler/aslrestype2d.c new file mode 100644 index 0000000..70988f0 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype2d.c @@ -0,0 +1,742 @@ + +/****************************************************************************** + * + * Module Name: aslrestype2d - Large DWord address resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype2d") + +/* + * This module contains the Dword (32-bit) address space descriptors: + * + * DwordIO + * DwordMemory + * DwordSpace + */ + +/******************************************************************************* + * + * FUNCTION: RsDoDwordIoDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "DwordIO" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoDwordIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT8 *OptionalFields; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32; + Descriptor->Address32.ResourceType = ACPI_ADDRESS_TYPE_IO_RANGE; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32); + Descriptor->Address32.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS32) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1); + break; + + case 1: /* MinType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2); + break; + + case 2: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3); + break; + + case 3: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1); + break; + + case 4: /* Range Type */ + + RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 0, 3); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 0, 2); + break; + + case 5: /* Address Granularity */ + + Descriptor->Address32.Granularity = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity)); + GranOp = InitializerOp; + break; + + case 6: /* Address Min */ + + Descriptor->Address32.Minimum = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum)); + MinOp = InitializerOp; + break; + + case 7: /* Address Max */ + + Descriptor->Address32.Maximum = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum)); + MaxOp = InitializerOp; + break; + + case 8: /* Translation Offset */ + + Descriptor->Address32.TranslationOffset = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset)); + break; + + case 9: /* Address Length */ + + Descriptor->Address32.AddressLength = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength)); + LengthOp = InitializerOp; + break; + + case 10: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + /* Found a valid ResourceSourceIndex */ + + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address32.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 11: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + /* Found a valid ResourceSource */ + + Descriptor->Address32.ResourceLength = (UINT16) + (Descriptor->Address32.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 12: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 13: /* Type */ + + RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 4, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 4); + break; + + case 14: /* Translation Type */ + + RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 5, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 5); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + (UINT64) Descriptor->Address32.Minimum, + (UINT64) Descriptor->Address32.Maximum, + (UINT64) Descriptor->Address32.AddressLength, + (UINT64) Descriptor->Address32.Granularity, + Descriptor->Address32.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) + + OptionIndex + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoDwordMemoryDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "DwordMemory" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoDwordMemoryDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32; + Descriptor->Address32.ResourceType = ACPI_ADDRESS_TYPE_MEMORY_RANGE; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32); + Descriptor->Address32.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS32) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1); + break; + + case 1: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1); + break; + + case 2: /* MinType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2); + break; + + case 3: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3); + break; + + case 4: /* Memory Type */ + + RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 1, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 1, 2); + break; + + case 5: /* Read/Write Type */ + + RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 0); + break; + + case 6: /* Address Granularity */ + + Descriptor->Address32.Granularity = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity)); + GranOp = InitializerOp; + break; + + case 7: /* Min Address */ + + Descriptor->Address32.Minimum = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum)); + MinOp = InitializerOp; + break; + + case 8: /* Max Address */ + + Descriptor->Address32.Maximum = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum)); + MaxOp = InitializerOp; + break; + + case 9: /* Translation Offset */ + + Descriptor->Address32.TranslationOffset = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset)); + break; + + case 10: /* Address Length */ + + Descriptor->Address32.AddressLength = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength)); + LengthOp = InitializerOp; + break; + + case 11: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address32.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 12: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address32.ResourceLength = (UINT16) + (Descriptor->Address32.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 13: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + + case 14: /* Address Range */ + + RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 3, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMATTRIBUTES, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 3, 2); + break; + + case 15: /* Type */ + + RsSetFlagBits (&Descriptor->Address32.SpecificFlags, InitializerOp, 5, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.SpecificFlags), 5); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + (UINT64) Descriptor->Address32.Minimum, + (UINT64) Descriptor->Address32.Maximum, + (UINT64) Descriptor->Address32.AddressLength, + (UINT64) Descriptor->Address32.Granularity, + Descriptor->Address32.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) + + OptionIndex + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoDwordSpaceDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "DwordSpace" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoDwordSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS32) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address32.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS32; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS32); + Descriptor->Address32.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS32) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Type */ + + Descriptor->Address32.ResourceType = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 1: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 0, 1); + break; + + case 2: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 1); + break; + + case 3: /* MinType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 2); + break; + + case 4: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address32.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Flags), 3); + break; + + case 5: /* Type-Specific flags */ + + Descriptor->Address32.SpecificFlags = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 6: /* Address Granularity */ + + Descriptor->Address32.Granularity = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Granularity)); + GranOp = InitializerOp; + break; + + case 7: /* Min Address */ + + Descriptor->Address32.Minimum = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Minimum)); + MinOp = InitializerOp; + break; + + case 8: /* Max Address */ + + Descriptor->Address32.Maximum = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.Maximum)); + MaxOp = InitializerOp; + break; + + case 9: /* Translation Offset */ + + Descriptor->Address32.TranslationOffset = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.TranslationOffset)); + break; + + case 10: /* Address Length */ + + Descriptor->Address32.AddressLength = + (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address32.AddressLength)); + LengthOp = InitializerOp; + break; + + case 11: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address32.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 12: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address32.ResourceLength = (UINT16) + (Descriptor->Address32.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 13: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, + InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + (UINT64) Descriptor->Address32.Minimum, + (UINT64) Descriptor->Address32.Maximum, + (UINT64) Descriptor->Address32.AddressLength, + (UINT64) Descriptor->Address32.Granularity, + Descriptor->Address32.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS32) + + OptionIndex + StringLength; + return (Rnode); +} diff --git a/sys/contrib/dev/acpica/compiler/aslrestype2e.c b/sys/contrib/dev/acpica/compiler/aslrestype2e.c new file mode 100644 index 0000000..3be19ec --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype2e.c @@ -0,0 +1,573 @@ + +/****************************************************************************** + * + * Module Name: aslrestype2e - Large Extended address resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype2e") + +/* + * This module contains the Extended (64-bit) address space descriptors: + * + * ExtendedIO + * ExtendedMemory + * ExtendedSpace + */ + +/******************************************************************************* + * + * FUNCTION: RsDoExtendedIoDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "ExtendedIO" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoExtendedIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT16 StringLength = 0; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->ExtAddress64.DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64; + Descriptor->ExtAddress64.ResourceType = ACPI_ADDRESS_TYPE_IO_RANGE; + Descriptor->ExtAddress64.RevisionID = AML_RESOURCE_EXTENDED_ADDRESS_REVISION; + + Descriptor->ExtAddress64.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 0, 1); + break; + + case 1: /* MinType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 2); + break; + + case 2: /* MaxType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 3); + break; + + case 3: /* DecodeType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 1); + break; + + case 4: /* Range Type */ + + RsSetFlagBits (&Descriptor->ExtAddress64.SpecificFlags, InitializerOp, 0, 3); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.SpecificFlags), 0, 2); + break; + + case 5: /* Address Granularity */ + + Descriptor->ExtAddress64.Granularity = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Granularity)); + GranOp = InitializerOp; + break; + + case 6: /* Address Min */ + + Descriptor->ExtAddress64.Minimum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Minimum)); + MinOp = InitializerOp; + break; + + case 7: /* Address Max */ + + Descriptor->ExtAddress64.Maximum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Maximum)); + MaxOp = InitializerOp; + break; + + case 8: /* Translation Offset */ + + Descriptor->ExtAddress64.TranslationOffset = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.TranslationOffset)); + break; + + case 9: /* Address Length */ + + Descriptor->ExtAddress64.AddressLength = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.AddressLength)); + LengthOp = InitializerOp; + break; + + case 10: /* Type-Specific Attributes */ + + Descriptor->ExtAddress64.TypeSpecific = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TYPESPECIFICATTRIBUTES, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.TypeSpecific)); + break; + + case 11: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 12: /* Type */ + + RsSetFlagBits (&Descriptor->ExtAddress64.SpecificFlags, InitializerOp, 4, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.SpecificFlags), 4); + break; + + case 13: /* Translation Type */ + + RsSetFlagBits (&Descriptor->ExtAddress64.SpecificFlags, InitializerOp, 5, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.SpecificFlags), 5); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + Descriptor->ExtAddress64.Minimum, + Descriptor->ExtAddress64.Maximum, + Descriptor->ExtAddress64.AddressLength, + Descriptor->ExtAddress64.Granularity, + Descriptor->ExtAddress64.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoExtendedMemoryDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "ExtendedMemory" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoExtendedMemoryDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT16 StringLength = 0; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->ExtAddress64.DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64; + Descriptor->ExtAddress64.ResourceType = ACPI_ADDRESS_TYPE_MEMORY_RANGE; + Descriptor->ExtAddress64.RevisionID = AML_RESOURCE_EXTENDED_ADDRESS_REVISION; + + Descriptor->ExtAddress64.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 0, 1); + break; + + case 1: /* DecodeType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 1); + break; + + case 2: /* MinType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 2); + break; + + case 3: /* MaxType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 3); + break; + + case 4: /* Memory Type */ + + RsSetFlagBits (&Descriptor->ExtAddress64.SpecificFlags, InitializerOp, 1, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.SpecificFlags), 1, 2); + break; + + case 5: /* Read/Write Type */ + + RsSetFlagBits (&Descriptor->ExtAddress64.SpecificFlags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.SpecificFlags), 0); + break; + + case 6: /* Address Granularity */ + + Descriptor->ExtAddress64.Granularity = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Granularity)); + GranOp = InitializerOp; + break; + + case 7: /* Min Address */ + + Descriptor->ExtAddress64.Minimum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Minimum)); + MinOp = InitializerOp; + break; + + case 8: /* Max Address */ + + Descriptor->ExtAddress64.Maximum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Maximum)); + MaxOp = InitializerOp; + break; + + case 9: /* Translation Offset */ + + Descriptor->ExtAddress64.TranslationOffset = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.TranslationOffset)); + break; + + case 10: /* Address Length */ + + Descriptor->ExtAddress64.AddressLength = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.AddressLength)); + LengthOp = InitializerOp; + break; + + case 11: /* Type-Specific Attributes */ + + Descriptor->ExtAddress64.TypeSpecific = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TYPESPECIFICATTRIBUTES, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.TypeSpecific)); + break; + + case 12: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + + case 13: /* Address Range */ + + RsSetFlagBits (&Descriptor->ExtAddress64.SpecificFlags, InitializerOp, 3, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMATTRIBUTES, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.SpecificFlags), 3, 2); + break; + + case 14: /* Type */ + + RsSetFlagBits (&Descriptor->ExtAddress64.SpecificFlags, InitializerOp, 5, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.SpecificFlags), 5); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + Descriptor->ExtAddress64.Minimum, + Descriptor->ExtAddress64.Maximum, + Descriptor->ExtAddress64.AddressLength, + Descriptor->ExtAddress64.Granularity, + Descriptor->ExtAddress64.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoExtendedSpaceDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "ExtendedSpace" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoExtendedSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT16 StringLength = 0; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->ExtAddress64.DescriptorType = ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64; + Descriptor->ExtAddress64.RevisionID = AML_RESOURCE_EXTENDED_ADDRESS_REVISION; + + Descriptor->ExtAddress64.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Type */ + + Descriptor->ExtAddress64.ResourceType = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 1: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 0, 1); + break; + + case 2: /* DecodeType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 1); + break; + + case 3: /* MinType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 2); + break; + + case 4: /* MaxType */ + + RsSetFlagBits (&Descriptor->ExtAddress64.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Flags), 3); + break; + + case 5: /* Type-Specific flags */ + + Descriptor->ExtAddress64.SpecificFlags = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 6: /* Address Granularity */ + + Descriptor->ExtAddress64.Granularity = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Granularity)); + GranOp = InitializerOp; + break; + + case 7: /* Min Address */ + + Descriptor->ExtAddress64.Minimum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Minimum)); + MinOp = InitializerOp; + break; + + case 8: /* Max Address */ + + Descriptor->ExtAddress64.Maximum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.Maximum)); + MaxOp = InitializerOp; + break; + + case 9: /* Translation Offset */ + + Descriptor->ExtAddress64.TranslationOffset = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.TranslationOffset)); + break; + + case 10: /* Address Length */ + + Descriptor->ExtAddress64.AddressLength = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.AddressLength)); + LengthOp = InitializerOp; + break; + + case 11: /* Type-Specific Attributes */ + + Descriptor->ExtAddress64.TypeSpecific = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TYPESPECIFICATTRIBUTES, + CurrentByteOffset + ASL_RESDESC_OFFSET (ExtAddress64.TypeSpecific)); + break; + + case 12: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + Descriptor->ExtAddress64.Minimum, + Descriptor->ExtAddress64.Maximum, + Descriptor->ExtAddress64.AddressLength, + Descriptor->ExtAddress64.Granularity, + Descriptor->ExtAddress64.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_EXTENDED_ADDRESS64) + StringLength; + return (Rnode); +} diff --git a/sys/contrib/dev/acpica/compiler/aslrestype2q.c b/sys/contrib/dev/acpica/compiler/aslrestype2q.c new file mode 100644 index 0000000..804702e --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype2q.c @@ -0,0 +1,721 @@ + +/****************************************************************************** + * + * Module Name: aslrestype2q - Large QWord address resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype2q") + +/* + * This module contains the QWord (64-bit) address space descriptors: + * + * QWordIO + * QWordMemory + * QWordSpace + */ + +/******************************************************************************* + * + * FUNCTION: RsDoQwordIoDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "QwordIO" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoQwordIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64; + Descriptor->Address64.ResourceType = ACPI_ADDRESS_TYPE_IO_RANGE; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64); + Descriptor->Address64.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS64) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1); + break; + + case 1: /* MinType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2); + break; + + case 2: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3); + break; + + case 3: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1); + break; + + case 4: /* Range Type */ + + RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 0, 3); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 0, 2); + break; + + case 5: /* Address Granularity */ + + Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity)); + GranOp = InitializerOp; + break; + + case 6: /* Address Min */ + + Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum)); + MinOp = InitializerOp; + break; + + case 7: /* Address Max */ + + Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum)); + MaxOp = InitializerOp; + break; + + case 8: /* Translation Offset */ + + Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset)); + break; + + case 9: /* Address Length */ + + Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength)); + LengthOp = InitializerOp; + break; + + case 10: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address64.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 11: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address64.ResourceLength = (UINT16) + (Descriptor->Address64.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 12: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 13: /* Type */ + + RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 4, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 4); + break; + + case 14: /* Translation Type */ + + RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 5, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 5); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + Descriptor->Address64.Minimum, + Descriptor->Address64.Maximum, + Descriptor->Address64.AddressLength, + Descriptor->Address64.Granularity, + Descriptor->Address64.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) + + OptionIndex + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoQwordMemoryDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "QwordMemory" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoQwordMemoryDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64; + Descriptor->Address64.ResourceType = ACPI_ADDRESS_TYPE_MEMORY_RANGE; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64); + Descriptor->Address64.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS64) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1); + break; + + case 1: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1); + break; + + case 2: /* MinType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2); + break; + + case 3: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3); + break; + + case 4: /* Memory Type */ + + RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 1, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 1, 2); + break; + + case 5: /* Read/Write Type */ + + RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 0, 1); + RsCreateBitField (InitializerOp, ACPI_RESTAG_READWRITETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 0); + break; + + case 6: /* Address Granularity */ + + Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity)); + GranOp = InitializerOp; + break; + + case 7: /* Min Address */ + + Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum)); + MinOp = InitializerOp; + break; + + case 8: /* Max Address */ + + Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum)); + MaxOp = InitializerOp; + break; + + case 9: /* Translation Offset */ + + Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset)); + break; + + case 10: /* Address Length */ + + Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength)); + LengthOp = InitializerOp; + break; + + case 11: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address64.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 12: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address64.ResourceLength = (UINT16) + (Descriptor->Address64.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 13: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + + case 14: /* Address Range */ + + RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 3, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_MEMATTRIBUTES, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 3, 2); + break; + + case 15: /* Type */ + + RsSetFlagBits (&Descriptor->Address64.SpecificFlags, InitializerOp, 5, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.SpecificFlags), 5); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + Descriptor->Address64.Minimum, + Descriptor->Address64.Maximum, + Descriptor->Address64.AddressLength, + Descriptor->Address64.Granularity, + Descriptor->Address64.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) + + OptionIndex + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoQwordSpaceDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "QwordSpace" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoQwordSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS64) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address64.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS64; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS64); + Descriptor->Address64.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS64) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Type */ + + Descriptor->Address64.ResourceType = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 1: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 0, 1); + break; + + case 2: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 1); + break; + + case 3: /* MinType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 2); + break; + + case 4: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address64.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Flags), 3); + break; + + case 5: /* Type-Specific flags */ + + Descriptor->Address64.SpecificFlags = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 6: /* Address Granularity */ + + Descriptor->Address64.Granularity = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Granularity)); + GranOp = InitializerOp; + break; + + case 7: /* Min Address */ + + Descriptor->Address64.Minimum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Minimum)); + MinOp = InitializerOp; + break; + + case 8: /* Max Address */ + + Descriptor->Address64.Maximum = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.Maximum)); + MaxOp = InitializerOp; + break; + + case 9: /* Translation Offset */ + + Descriptor->Address64.TranslationOffset = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.TranslationOffset)); + break; + + case 10: /* Address Length */ + + Descriptor->Address64.AddressLength = InitializerOp->Asl.Value.Integer; + RsCreateQwordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address64.AddressLength)); + LengthOp = InitializerOp; + break; + + case 11: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address64.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 12: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address64.ResourceLength = (UINT16) + (Descriptor->Address64.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 13: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + Descriptor->Address64.Minimum, + Descriptor->Address64.Maximum, + Descriptor->Address64.AddressLength, + Descriptor->Address64.Granularity, + Descriptor->Address64.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS64) + + OptionIndex + StringLength; + return (Rnode); +} diff --git a/sys/contrib/dev/acpica/compiler/aslrestype2s.c b/sys/contrib/dev/acpica/compiler/aslrestype2s.c new file mode 100644 index 0000000..fa30b58 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype2s.c @@ -0,0 +1,1187 @@ +/****************************************************************************** + * + * Module Name: aslrestype2s - Serial Large resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/amlcode.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype2s") + + +static UINT16 +RsGetBufferDataLength ( + ACPI_PARSE_OBJECT *InitializerOp); + +static UINT16 +RsGetInterruptDataLength ( + ACPI_PARSE_OBJECT *InitializerOp); + +static BOOLEAN +RsGetVendorData ( + ACPI_PARSE_OBJECT *InitializerOp, + UINT8 *VendorData, + ACPI_SIZE DescriptorOffset); + +/* + * This module contains descriptors for serial buses and GPIO: + * + * GpioInt + * GpioIo + * I2cSerialBus + * SpiSerialBus + * UartSerialBus + */ + + +/******************************************************************************* + * + * FUNCTION: RsGetBufferDataLength + * + * PARAMETERS: InitializerOp - Current parse op, start of the resource + * descriptor + * + * RETURN: Length of the data buffer + * + * DESCRIPTION: Get the length of a RawDataBuffer, used for vendor data. + * + ******************************************************************************/ + +static UINT16 +RsGetBufferDataLength ( + ACPI_PARSE_OBJECT *InitializerOp) +{ + UINT16 ExtraDataSize = 0; + ACPI_PARSE_OBJECT *DataList; + + + /* Find the byte-initializer list */ + + while (InitializerOp) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DATABUFFER) + { + /* First child is the optional length (ignore it here) */ + + DataList = InitializerOp->Asl.Child; + DataList = ASL_GET_PEER_NODE (DataList); + + /* Count the data items (each one is a byte of data) */ + + while (DataList) + { + ExtraDataSize++; + DataList = ASL_GET_PEER_NODE (DataList); + } + + return (ExtraDataSize); + } + + InitializerOp = ASL_GET_PEER_NODE (InitializerOp); + } + + return (ExtraDataSize); +} + + +/******************************************************************************* + * + * FUNCTION: RsGetInterruptDataLength + * + * PARAMETERS: InitializerOp - Current parse op, start of the resource + * descriptor + * + * RETURN: Length of the interrupt data list + * + * DESCRIPTION: Get the length of a list of interrupt DWORDs for the GPIO + * descriptors. + * + ******************************************************************************/ + +static UINT16 +RsGetInterruptDataLength ( + ACPI_PARSE_OBJECT *InitializerOp) +{ + UINT16 InterruptLength; + UINT32 i; + + + /* Count the interrupt numbers */ + + InterruptLength = 0; + for (i = 0; InitializerOp; i++) + { + InitializerOp = ASL_GET_PEER_NODE (InitializerOp); + + /* Interrupt list starts at offset 10 (Gpio descriptors) */ + + if (i >= 10) + { + InterruptLength += 2; + } + } + + return (InterruptLength); +} + + +/******************************************************************************* + * + * FUNCTION: RsGetVendorData + * + * PARAMETERS: InitializerOp - Current parse op, start of the resource + * descriptor. + * VendorData - Where the vendor data is returned + * DescriptorOffset - Where vendor data begins in descriptor + * + * RETURN: TRUE if valid vendor data was returned, FALSE otherwise. + * + * DESCRIPTION: Extract the vendor data and construct a vendor data buffer. + * + ******************************************************************************/ + +static BOOLEAN +RsGetVendorData ( + ACPI_PARSE_OBJECT *InitializerOp, + UINT8 *VendorData, + ACPI_SIZE DescriptorOffset) +{ + ACPI_PARSE_OBJECT *BufferOp; + UINT32 SpecifiedLength = ACPI_UINT32_MAX; + UINT16 ActualLength = 0; + + + /* Vendor Data field is always optional */ + + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + return (FALSE); + } + + BufferOp = InitializerOp->Asl.Child; + if (!BufferOp) + { + AslError (ASL_ERROR, ASL_MSG_SYNTAX, InitializerOp, ""); + return (FALSE); + } + + /* First child is the optional buffer length (WORD) */ + + if (BufferOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + SpecifiedLength = (UINT16) BufferOp->Asl.Value.Integer; + } + + /* Insert field tag _VEN */ + + RsCreateByteField (InitializerOp, ACPI_RESTAG_VENDORDATA, + (UINT16) DescriptorOffset); + + /* Walk the list of buffer initializers (each is one byte) */ + + BufferOp = RsCompleteNodeAndGetNext (BufferOp); + if (BufferOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + while (BufferOp) + { + *VendorData = (UINT8) BufferOp->Asl.Value.Integer; + VendorData++; + ActualLength++; + BufferOp = RsCompleteNodeAndGetNext (BufferOp); + } + } + + /* Length validation. Buffer cannot be of zero length */ + + if ((SpecifiedLength == 0) || + ((SpecifiedLength == ACPI_UINT32_MAX) && (ActualLength == 0))) + { + AslError (ASL_ERROR, ASL_MSG_BUFFER_LENGTH, InitializerOp, NULL); + return (FALSE); + } + + if (SpecifiedLength != ACPI_UINT32_MAX) + { + /* ActualLength > SpecifiedLength -> error */ + + if (ActualLength > SpecifiedLength) + { + AslError (ASL_ERROR, ASL_MSG_LIST_LENGTH_LONG, InitializerOp, NULL); + return (FALSE); + } + + /* ActualLength < SpecifiedLength -> remark */ + + else if (ActualLength < SpecifiedLength) + { + AslError (ASL_REMARK, ASL_MSG_LIST_LENGTH_SHORT, InitializerOp, NULL); + return (FALSE); + } + } + + return (TRUE); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoGpioIntDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "GpioInt" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoGpioIntDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + char *ResourceSource = NULL; + UINT8 *VendorData = NULL; + UINT16 *InterruptList = NULL; + UINT16 ResSourceLength; + UINT16 VendorLength; + UINT16 InterruptLength; + UINT16 DescriptorSize; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + + /* + * Calculate lengths for fields that have variable length: + * 1) Resource Source string + * 2) Vendor Data buffer + * 3) PIN (interrupt) list + */ + ResSourceLength = RsGetStringDataLength (InitializerOp); + VendorLength = RsGetBufferDataLength (InitializerOp); + InterruptLength = RsGetInterruptDataLength (InitializerOp); + + DescriptorSize = ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO) + + ResSourceLength + VendorLength + InterruptLength; + + /* Allocate the local resource node and initialize */ + + Rnode = RsAllocateResourceNode (DescriptorSize + sizeof (AML_RESOURCE_LARGE_HEADER)); + + Descriptor = Rnode->Buffer; + Descriptor->Gpio.ResourceLength = DescriptorSize; + Descriptor->Gpio.DescriptorType = ACPI_RESOURCE_NAME_GPIO; + Descriptor->Gpio.RevisionId = AML_RESOURCE_GPIO_REVISION; + Descriptor->Gpio.ConnectionType = AML_RESOURCE_GPIO_TYPE_INT; + + /* Build pointers to optional areas */ + + InterruptList = ACPI_ADD_PTR (UINT16, Descriptor, sizeof (AML_RESOURCE_GPIO)); + ResourceSource = ACPI_ADD_PTR (char, InterruptList, InterruptLength); + VendorData = ACPI_ADD_PTR (UINT8, ResourceSource, ResSourceLength); + + /* Setup offsets within the descriptor */ + + Descriptor->Gpio.PinTableOffset = (UINT16) + ACPI_PTR_DIFF (InterruptList, Descriptor); + + Descriptor->Gpio.ResSourceOffset = (UINT16) + ACPI_PTR_DIFF (ResourceSource, Descriptor); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%16s - Actual: %.2X, Base: %.2X, ResLen: %.2X, VendLen: %.2X, IntLen: %.2X\n", + "GpioInt", Descriptor->Gpio.ResourceLength, (UINT16) sizeof (AML_RESOURCE_GPIO), + ResSourceLength, VendorLength, InterruptLength); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Interrupt Mode - edge/level [Flag] (_MOD) */ + + RsSetFlagBits16 (&Descriptor->Gpio.IntFlags, InitializerOp, 0, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.IntFlags), 0); + break; + + case 1: /* Interrupt Polarity - Active high/low [Flags] (_POL) */ + + RsSetFlagBits16 (&Descriptor->Gpio.IntFlags, InitializerOp, 1, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_POLARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.IntFlags), 1, 2); + break; + + case 2: /* Share Type - Default: exclusive (0) [Flags] (_SHR) */ + + RsSetFlagBits16 (&Descriptor->Gpio.IntFlags, InitializerOp, 3, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.IntFlags), 3, 2); + break; + + case 3: /* Pin Config [BYTE] (_PPI) */ + + Descriptor->Gpio.PinConfig = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_PINCONFIG, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.PinConfig)); + break; + + case 4: /* Debounce Timeout [WORD] (_DBT) */ + + Descriptor->Gpio.DebounceTimeout = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_DEBOUNCETIME, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.DebounceTimeout)); + break; + + case 5: /* ResSource [Optional Field - STRING] */ + + if (ResSourceLength) + { + /* Copy string to the descriptor */ + + strcpy (ResourceSource, + InitializerOp->Asl.Value.String); + } + break; + + case 6: /* Resource Index */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + Descriptor->Gpio.ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer; + } + break; + + case 7: /* Resource Usage (consumer/producer) */ + + RsSetFlagBits16 (&Descriptor->Gpio.Flags, InitializerOp, 0, 1); + break; + + case 8: /* Resource Tag (Descriptor Name) */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 9: /* Vendor Data (Optional - Buffer of BYTEs) (_VEN) */ + + /* + * Always set the VendorOffset even if there is no Vendor Data. + * This field is required in order to calculate the length + * of the ResourceSource at runtime. + */ + Descriptor->Gpio.VendorOffset = (UINT16) + ACPI_PTR_DIFF (VendorData, Descriptor); + + if (RsGetVendorData (InitializerOp, VendorData, + (CurrentByteOffset + Descriptor->Gpio.VendorOffset))) + { + Descriptor->Gpio.VendorLength = VendorLength; + } + break; + + default: + /* + * PINs come through here, repeatedly. Each PIN must be a DWORD. + * NOTE: there is no "length" field for this, so from ACPI spec: + * The number of pins in the table can be calculated from: + * PinCount = (Resource Source Name Offset - Pin Table Offset) / 2 + * (implies resource source must immediately follow the pin list.) + * Name: _PIN + */ + *InterruptList = (UINT16) InitializerOp->Asl.Value.Integer; + InterruptList++; + + /* Case 10: First interrupt number in list */ + + if (i == 10) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + /* Must be at least one interrupt */ + + AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST_MIN, + InitializerOp, NULL); + } + + /* Check now for duplicates in list */ + + RsCheckListForDuplicates (InitializerOp); + + /* Create a named field at the start of the list */ + + RsCreateDwordField (InitializerOp, ACPI_RESTAG_PIN, + CurrentByteOffset + Descriptor->Gpio.PinTableOffset); + } + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoGpioIoDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "GpioIo" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoGpioIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + char *ResourceSource = NULL; + UINT8 *VendorData = NULL; + UINT16 *InterruptList = NULL; + UINT16 ResSourceLength; + UINT16 VendorLength; + UINT16 InterruptLength; + UINT16 DescriptorSize; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + + /* + * Calculate lengths for fields that have variable length: + * 1) Resource Source string + * 2) Vendor Data buffer + * 3) PIN (interrupt) list + */ + ResSourceLength = RsGetStringDataLength (InitializerOp); + VendorLength = RsGetBufferDataLength (InitializerOp); + InterruptLength = RsGetInterruptDataLength (InitializerOp); + + DescriptorSize = ACPI_AML_SIZE_LARGE (AML_RESOURCE_GPIO) + + ResSourceLength + VendorLength + InterruptLength; + + /* Allocate the local resource node and initialize */ + + Rnode = RsAllocateResourceNode (DescriptorSize + sizeof (AML_RESOURCE_LARGE_HEADER)); + + Descriptor = Rnode->Buffer; + Descriptor->Gpio.ResourceLength = DescriptorSize; + Descriptor->Gpio.DescriptorType = ACPI_RESOURCE_NAME_GPIO; + Descriptor->Gpio.RevisionId = AML_RESOURCE_GPIO_REVISION; + Descriptor->Gpio.ConnectionType = AML_RESOURCE_GPIO_TYPE_IO; + + /* Build pointers to optional areas */ + + InterruptList = ACPI_ADD_PTR (UINT16, Descriptor, sizeof (AML_RESOURCE_GPIO)); + ResourceSource = ACPI_ADD_PTR (char, InterruptList, InterruptLength); + VendorData = ACPI_ADD_PTR (UINT8, ResourceSource, ResSourceLength); + + /* Setup offsets within the descriptor */ + + Descriptor->Gpio.PinTableOffset = (UINT16) + ACPI_PTR_DIFF (InterruptList, Descriptor); + + Descriptor->Gpio.ResSourceOffset = (UINT16) + ACPI_PTR_DIFF (ResourceSource, Descriptor); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%16s - Actual: %.2X, Base: %.2X, ResLen: %.2X, VendLen: %.2X, IntLen: %.2X\n", + "GpioIo", Descriptor->Gpio.ResourceLength, (UINT16) sizeof (AML_RESOURCE_GPIO), + ResSourceLength, VendorLength, InterruptLength); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Share Type [Flags] (_SHR) */ + + RsSetFlagBits16 (&Descriptor->Gpio.IntFlags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_INTERRUPTSHARE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.IntFlags), 3); + break; + + case 1: /* Pin Config [BYTE] (_PPI) */ + + Descriptor->Gpio.PinConfig = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_PINCONFIG, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.PinConfig)); + break; + + case 2: /* Debounce Timeout [WORD] (_DBT) */ + + Descriptor->Gpio.DebounceTimeout = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_DEBOUNCETIME, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.DebounceTimeout)); + break; + + case 3: /* Drive Strength [WORD] (_DRS) */ + + Descriptor->Gpio.DriveStrength = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_DRIVESTRENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.DriveStrength)); + break; + + case 4: /* I/O Restriction [Flag] (_IOR) */ + + RsSetFlagBits16 (&Descriptor->Gpio.IntFlags, InitializerOp, 0, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_IORESTRICTION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Gpio.IntFlags), 0, 2); + break; + + case 5: /* ResSource [Optional Field - STRING] */ + + if (ResSourceLength) + { + /* Copy string to the descriptor */ + + strcpy (ResourceSource, + InitializerOp->Asl.Value.String); + } + break; + + case 6: /* Resource Index */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + Descriptor->Gpio.ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer; + } + break; + + case 7: /* Resource Usage (consumer/producer) */ + + RsSetFlagBits16 (&Descriptor->Gpio.Flags, InitializerOp, 0, 1); + break; + + case 8: /* Resource Tag (Descriptor Name) */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 9: /* Vendor Data (Optional - Buffer of BYTEs) (_VEN) */ + + /* + * Always set the VendorOffset even if there is no Vendor Data. + * This field is required in order to calculate the length + * of the ResourceSource at runtime. + */ + Descriptor->Gpio.VendorOffset = (UINT16) + ACPI_PTR_DIFF (VendorData, Descriptor); + + if (RsGetVendorData (InitializerOp, VendorData, + (CurrentByteOffset + Descriptor->Gpio.VendorOffset))) + { + Descriptor->Gpio.VendorLength = VendorLength; + } + break; + + default: + /* + * PINs come through here, repeatedly. Each PIN must be a DWORD. + * NOTE: there is no "length" field for this, so from ACPI spec: + * The number of pins in the table can be calculated from: + * PinCount = (Resource Source Name Offset - Pin Table Offset) / 2 + * (implies resource source must immediately follow the pin list.) + * Name: _PIN + */ + *InterruptList = (UINT16) InitializerOp->Asl.Value.Integer; + InterruptList++; + + /* Case 10: First interrupt number in list */ + + if (i == 10) + { + if (InitializerOp->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + /* Must be at least one interrupt */ + + AslError (ASL_ERROR, ASL_MSG_EX_INTERRUPT_LIST_MIN, + InitializerOp, NULL); + } + + /* Check now for duplicates in list */ + + RsCheckListForDuplicates (InitializerOp); + + /* Create a named field at the start of the list */ + + RsCreateDwordField (InitializerOp, ACPI_RESTAG_PIN, + CurrentByteOffset + Descriptor->Gpio.PinTableOffset); + } + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoI2cSerialBusDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "I2cSerialBus" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoI2cSerialBusDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + char *ResourceSource = NULL; + UINT8 *VendorData = NULL; + UINT16 ResSourceLength; + UINT16 VendorLength; + UINT16 DescriptorSize; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + + /* + * Calculate lengths for fields that have variable length: + * 1) Resource Source string + * 2) Vendor Data buffer + */ + ResSourceLength = RsGetStringDataLength (InitializerOp); + VendorLength = RsGetBufferDataLength (InitializerOp); + + DescriptorSize = ACPI_AML_SIZE_LARGE (AML_RESOURCE_I2C_SERIALBUS) + + ResSourceLength + VendorLength; + + /* Allocate the local resource node and initialize */ + + Rnode = RsAllocateResourceNode (DescriptorSize + sizeof (AML_RESOURCE_LARGE_HEADER)); + + Descriptor = Rnode->Buffer; + Descriptor->I2cSerialBus.ResourceLength = DescriptorSize; + Descriptor->I2cSerialBus.DescriptorType = ACPI_RESOURCE_NAME_SERIAL_BUS; + Descriptor->I2cSerialBus.RevisionId = AML_RESOURCE_I2C_REVISION; + Descriptor->I2cSerialBus.TypeRevisionId = AML_RESOURCE_I2C_TYPE_REVISION; + Descriptor->I2cSerialBus.Type = AML_RESOURCE_I2C_SERIALBUSTYPE; + Descriptor->I2cSerialBus.TypeDataLength = AML_RESOURCE_I2C_MIN_DATA_LEN + VendorLength; + + /* Build pointers to optional areas */ + + VendorData = ACPI_ADD_PTR (UINT8, Descriptor, sizeof (AML_RESOURCE_I2C_SERIALBUS)); + ResourceSource = ACPI_ADD_PTR (char, VendorData, VendorLength); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%16s - Actual: %.2X, Base: %.2X, ResLen: %.2X, VendLen: %.2X, TypLen: %.2X\n", + "I2cSerialBus", Descriptor->I2cSerialBus.ResourceLength, + (UINT16) sizeof (AML_RESOURCE_I2C_SERIALBUS), ResSourceLength, + VendorLength, Descriptor->I2cSerialBus.TypeDataLength); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Slave Address [WORD] (_ADR) */ + + Descriptor->I2cSerialBus.SlaveAddress = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_ADDRESS, + CurrentByteOffset + ASL_RESDESC_OFFSET (I2cSerialBus.SlaveAddress)); + break; + + case 1: /* Slave Mode [Flag] (_SLV) */ + + RsSetFlagBits (&Descriptor->I2cSerialBus.Flags, InitializerOp, 0, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_SLAVEMODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (I2cSerialBus.Flags), 0); + break; + + case 2: /* Connection Speed [DWORD] (_SPE) */ + + Descriptor->I2cSerialBus.ConnectionSpeed = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_SPEED, + CurrentByteOffset + ASL_RESDESC_OFFSET (I2cSerialBus.ConnectionSpeed)); + break; + + case 3: /* Addressing Mode [Flag] (_MOD) */ + + RsSetFlagBits16 (&Descriptor->I2cSerialBus.TypeSpecificFlags, InitializerOp, 0, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (I2cSerialBus.TypeSpecificFlags), 0); + break; + + case 4: /* ResSource [Optional Field - STRING] */ + + if (ResSourceLength) + { + /* Copy string to the descriptor */ + + strcpy (ResourceSource, + InitializerOp->Asl.Value.String); + } + break; + + case 5: /* Resource Index */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + Descriptor->I2cSerialBus.ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer; + } + break; + + case 6: /* Resource Usage (consumer/producer) */ + + RsSetFlagBits (&Descriptor->I2cSerialBus.Flags, InitializerOp, 1, 1); + break; + + case 7: /* Resource Tag (Descriptor Name) */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 8: /* Vendor Data (Optional - Buffer of BYTEs) (_VEN) */ + + RsGetVendorData (InitializerOp, VendorData, + CurrentByteOffset + sizeof (AML_RESOURCE_I2C_SERIALBUS)); + break; + + default: /* Ignore any extra nodes */ + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoSpiSerialBusDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "SPI Serial Bus" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoSpiSerialBusDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + char *ResourceSource = NULL; + UINT8 *VendorData = NULL; + UINT16 ResSourceLength; + UINT16 VendorLength; + UINT16 DescriptorSize; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + + /* + * Calculate lengths for fields that have variable length: + * 1) Resource Source string + * 2) Vendor Data buffer + */ + ResSourceLength = RsGetStringDataLength (InitializerOp); + VendorLength = RsGetBufferDataLength (InitializerOp); + + DescriptorSize = ACPI_AML_SIZE_LARGE (AML_RESOURCE_SPI_SERIALBUS) + + ResSourceLength + VendorLength; + + /* Allocate the local resource node and initialize */ + + Rnode = RsAllocateResourceNode (DescriptorSize + sizeof (AML_RESOURCE_LARGE_HEADER)); + + Descriptor = Rnode->Buffer; + Descriptor->SpiSerialBus.ResourceLength = DescriptorSize; + Descriptor->SpiSerialBus.DescriptorType = ACPI_RESOURCE_NAME_SERIAL_BUS; + Descriptor->SpiSerialBus.RevisionId = AML_RESOURCE_SPI_REVISION; + Descriptor->SpiSerialBus.TypeRevisionId = AML_RESOURCE_SPI_TYPE_REVISION; + Descriptor->SpiSerialBus.Type = AML_RESOURCE_SPI_SERIALBUSTYPE; + Descriptor->SpiSerialBus.TypeDataLength = AML_RESOURCE_SPI_MIN_DATA_LEN + VendorLength; + + /* Build pointers to optional areas */ + + VendorData = ACPI_ADD_PTR (UINT8, Descriptor, sizeof (AML_RESOURCE_SPI_SERIALBUS)); + ResourceSource = ACPI_ADD_PTR (char, VendorData, VendorLength); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%16s - Actual: %.2X, Base: %.2X, ResLen: %.2X, VendLen: %.2X, TypLen: %.2X\n", + "SpiSerialBus", Descriptor->SpiSerialBus.ResourceLength, + (UINT16) sizeof (AML_RESOURCE_SPI_SERIALBUS), ResSourceLength, + VendorLength, Descriptor->SpiSerialBus.TypeDataLength); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Device Selection [WORD] (_ADR) */ + + Descriptor->SpiSerialBus.DeviceSelection = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_ADDRESS, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.DeviceSelection)); + break; + + case 1: /* Device Polarity [Flag] (_DPL) */ + + RsSetFlagBits16 (&Descriptor->SpiSerialBus.TypeSpecificFlags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DEVICEPOLARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.TypeSpecificFlags), 1); + break; + + case 2: /* Wire Mode [Flag] (_MOD) */ + + RsSetFlagBits16 (&Descriptor->SpiSerialBus.TypeSpecificFlags, InitializerOp, 0, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.TypeSpecificFlags), 0); + break; + + case 3: /* Device Bit Length [BYTE] (_LEN) */ + + Descriptor->SpiSerialBus.DataBitLength = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.DataBitLength)); + break; + + case 4: /* Slave Mode [Flag] (_SLV) */ + + RsSetFlagBits (&Descriptor->SpiSerialBus.Flags, InitializerOp, 0, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_SLAVEMODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.Flags), 0); + break; + + case 5: /* Connection Speed [DWORD] (_SPE) */ + + Descriptor->SpiSerialBus.ConnectionSpeed = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_SPEED, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.ConnectionSpeed)); + break; + + case 6: /* Clock Polarity [BYTE] (_POL) */ + + Descriptor->SpiSerialBus.ClockPolarity = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_POLARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.ClockPolarity)); + break; + + case 7: /* Clock Phase [BYTE] (_PHA) */ + + Descriptor->SpiSerialBus.ClockPhase = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_PHASE, + CurrentByteOffset + ASL_RESDESC_OFFSET (SpiSerialBus.ClockPhase)); + break; + + case 8: /* ResSource [Optional Field - STRING] */ + + if (ResSourceLength) + { + /* Copy string to the descriptor */ + + strcpy (ResourceSource, + InitializerOp->Asl.Value.String); + } + break; + + case 9: /* Resource Index */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + Descriptor->SpiSerialBus.ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer; + } + break; + + case 10: /* Resource Usage (consumer/producer) */ + + RsSetFlagBits (&Descriptor->SpiSerialBus.Flags, InitializerOp, 1, 1); + break; + + case 11: /* Resource Tag (Descriptor Name) */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 12: /* Vendor Data (Optional - Buffer of BYTEs) (_VEN) */ + + RsGetVendorData (InitializerOp, VendorData, + CurrentByteOffset + sizeof (AML_RESOURCE_SPI_SERIALBUS)); + break; + + default: /* Ignore any extra nodes */ + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoUartSerialBusDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "UART Serial Bus" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoUartSerialBusDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ASL_RESOURCE_NODE *Rnode; + char *ResourceSource = NULL; + UINT8 *VendorData = NULL; + UINT16 ResSourceLength; + UINT16 VendorLength; + UINT16 DescriptorSize; + UINT32 i; + + + InitializerOp = Op->Asl.Child; + + /* + * Calculate lengths for fields that have variable length: + * 1) Resource Source string + * 2) Vendor Data buffer + */ + ResSourceLength = RsGetStringDataLength (InitializerOp); + VendorLength = RsGetBufferDataLength (InitializerOp); + + DescriptorSize = ACPI_AML_SIZE_LARGE (AML_RESOURCE_UART_SERIALBUS) + + ResSourceLength + VendorLength; + + /* Allocate the local resource node and initialize */ + + Rnode = RsAllocateResourceNode (DescriptorSize + sizeof (AML_RESOURCE_LARGE_HEADER)); + + Descriptor = Rnode->Buffer; + Descriptor->UartSerialBus.ResourceLength = DescriptorSize; + Descriptor->UartSerialBus.DescriptorType = ACPI_RESOURCE_NAME_SERIAL_BUS; + Descriptor->UartSerialBus.RevisionId = AML_RESOURCE_UART_REVISION; + Descriptor->UartSerialBus.TypeRevisionId = AML_RESOURCE_UART_TYPE_REVISION; + Descriptor->UartSerialBus.Type = AML_RESOURCE_UART_SERIALBUSTYPE; + Descriptor->UartSerialBus.TypeDataLength = AML_RESOURCE_UART_MIN_DATA_LEN + VendorLength; + + /* Build pointers to optional areas */ + + VendorData = ACPI_ADD_PTR (UINT8, Descriptor, sizeof (AML_RESOURCE_UART_SERIALBUS)); + ResourceSource = ACPI_ADD_PTR (char, VendorData, VendorLength); + + DbgPrint (ASL_DEBUG_OUTPUT, + "%16s - Actual: %.2X, Base: %.2X, ResLen: %.2X, VendLen: %.2X, TypLen: %.2X\n", + "UartSerialBus", Descriptor->UartSerialBus.ResourceLength, + (UINT16) sizeof (AML_RESOURCE_UART_SERIALBUS), ResSourceLength, + VendorLength, Descriptor->UartSerialBus.TypeDataLength); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Connection Speed (Baud Rate) [DWORD] (_SPE) */ + + Descriptor->UartSerialBus.DefaultBaudRate = (UINT32) InitializerOp->Asl.Value.Integer; + RsCreateDwordField (InitializerOp, ACPI_RESTAG_SPEED, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.DefaultBaudRate)); + break; + + case 1: /* Bits Per Byte [Flags] (_LEN) */ + + RsSetFlagBits16 (&Descriptor->UartSerialBus.TypeSpecificFlags, InitializerOp, 4, 3); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.TypeSpecificFlags), 4, 3); + break; + + case 2: /* Stop Bits [Flags] (_STB) */ + + RsSetFlagBits16 (&Descriptor->UartSerialBus.TypeSpecificFlags, InitializerOp, 2, 1); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_STOPBITS, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.TypeSpecificFlags), 2, 2); + break; + + case 3: /* Lines In Use [BYTE] (_LIN) */ + + Descriptor->UartSerialBus.LinesEnabled = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_LINE, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.LinesEnabled)); + break; + + case 4: /* Endianness [Flag] (_END) */ + + RsSetFlagBits16 (&Descriptor->UartSerialBus.TypeSpecificFlags, InitializerOp, 7, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_ENDIANNESS, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.TypeSpecificFlags), 7); + break; + + case 5: /* Parity [BYTE] (_PAR) */ + + Descriptor->UartSerialBus.Parity = (UINT8) InitializerOp->Asl.Value.Integer; + RsCreateByteField (InitializerOp, ACPI_RESTAG_PARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.Parity)); + break; + + case 6: /* Flow Control [Flags] (_FLC) */ + + RsSetFlagBits16 (&Descriptor->UartSerialBus.TypeSpecificFlags, InitializerOp, 0, 0); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_FLOWCONTROL, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.TypeSpecificFlags), 0, 2); + break; + + case 7: /* Rx Buffer Size [WORD] (_RXL) */ + + Descriptor->UartSerialBus.RxFifoSize = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_LENGTH_RX, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.RxFifoSize)); + break; + + case 8: /* Tx Buffer Size [WORD] (_TXL) */ + + Descriptor->UartSerialBus.TxFifoSize = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_LENGTH_TX, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.TxFifoSize)); + break; + + case 9: /* ResSource [Optional Field - STRING] */ + + if (ResSourceLength) + { + /* Copy string to the descriptor */ + + strcpy (ResourceSource, + InitializerOp->Asl.Value.String); + } + break; + + case 10: /* Resource Index */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + Descriptor->UartSerialBus.ResSourceIndex = (UINT8) InitializerOp->Asl.Value.Integer; + } + break; + + case 11: /* Resource Usage (consumer/producer) */ + + RsSetFlagBits (&Descriptor->UartSerialBus.Flags, InitializerOp, 1, 1); + + /* + * Slave Mode [Flag] (_SLV) + * + * Note: There is no SlaveMode argument to the UartSerialBus macro, but + * we add this name anyway to allow the flag to be set by ASL in the + * rare case where there is a slave mode associated with the UART. + */ + RsCreateBitField (InitializerOp, ACPI_RESTAG_SLAVEMODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (UartSerialBus.Flags), 0); + break; + + case 12: /* Resource Tag (Descriptor Name) */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 13: /* Vendor Data (Optional - Buffer of BYTEs) (_VEN) */ + + RsGetVendorData (InitializerOp, VendorData, + CurrentByteOffset + sizeof (AML_RESOURCE_UART_SERIALBUS)); + break; + + default: /* Ignore any extra nodes */ + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + return (Rnode); +} diff --git a/sys/contrib/dev/acpica/compiler/aslrestype2w.c b/sys/contrib/dev/acpica/compiler/aslrestype2w.c new file mode 100644 index 0000000..ad0a9c1 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslrestype2w.c @@ -0,0 +1,702 @@ + +/****************************************************************************** + * + * Module Name: aslrestype2w - Large Word address resource descriptors + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslrestype2w") + +/* + * This module contains the Word (16-bit) address space descriptors: + * + * WordIO + * WordMemory + * WordSpace + */ + +/******************************************************************************* + * + * FUNCTION: RsDoWordIoDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "WordIO" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoWordIoDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS16) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address16.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS16; + Descriptor->Address16.ResourceType = ACPI_ADDRESS_TYPE_IO_RANGE; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS16); + Descriptor->Address16.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS16) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 0, 1); + break; + + case 1: /* MinType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 2); + break; + + case 2: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 3); + break; + + case 3: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 1); + break; + + case 4: /* Range Type */ + + RsSetFlagBits (&Descriptor->Address16.SpecificFlags, InitializerOp, 0, 3); + RsCreateMultiBitField (InitializerOp, ACPI_RESTAG_RANGETYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.SpecificFlags), 0, 2); + break; + + case 5: /* Address Granularity */ + + Descriptor->Address16.Granularity = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Granularity)); + GranOp = InitializerOp; + break; + + case 6: /* Address Min */ + + Descriptor->Address16.Minimum = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Minimum)); + MinOp = InitializerOp; + break; + + case 7: /* Address Max */ + + Descriptor->Address16.Maximum = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Maximum)); + MaxOp = InitializerOp; + break; + + case 8: /* Translation Offset */ + + Descriptor->Address16.TranslationOffset = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.TranslationOffset)); + break; + + case 9: /* Address Length */ + + Descriptor->Address16.AddressLength = (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.AddressLength)); + LengthOp = InitializerOp; + break; + + case 10: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address16.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 11: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address16.ResourceLength = (UINT16) + (Descriptor->Address16.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 12: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + case 13: /* Type */ + + RsSetFlagBits (&Descriptor->Address16.SpecificFlags, InitializerOp, 4, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.SpecificFlags), 4); + break; + + case 14: /* Translation Type */ + + RsSetFlagBits (&Descriptor->Address16.SpecificFlags, InitializerOp, 5, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_TRANSTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.SpecificFlags), 5); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + (UINT64) Descriptor->Address16.Minimum, + (UINT64) Descriptor->Address16.Maximum, + (UINT64) Descriptor->Address16.AddressLength, + (UINT64) Descriptor->Address16.Granularity, + Descriptor->Address16.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS16) + + OptionIndex + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoWordBusNumberDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "WordBusNumber" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoWordBusNumberDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS16) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address16.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS16; + Descriptor->Address16.ResourceType = ACPI_ADDRESS_TYPE_BUS_NUMBER_RANGE; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS16); + Descriptor->Address16.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS16) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 0, 1); + break; + + case 1: /* MinType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 2); + break; + + case 2: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 3); + break; + + case 3: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 1); + break; + + case 4: /* Address Granularity */ + + Descriptor->Address16.Granularity = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Granularity)); + GranOp = InitializerOp; + break; + + case 5: /* Min Address */ + + Descriptor->Address16.Minimum = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Minimum)); + MinOp = InitializerOp; + break; + + case 6: /* Max Address */ + + Descriptor->Address16.Maximum = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Maximum)); + MaxOp = InitializerOp; + break; + + case 7: /* Translation Offset */ + + Descriptor->Address16.TranslationOffset = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.TranslationOffset)); + break; + + case 8: /* Address Length */ + + Descriptor->Address16.AddressLength = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.AddressLength)); + LengthOp = InitializerOp; + break; + + case 9: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address16.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 10: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address16.ResourceLength = (UINT16) + (Descriptor->Address16.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 11: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + (UINT64) Descriptor->Address16.Minimum, + (UINT64) Descriptor->Address16.Maximum, + (UINT64) Descriptor->Address16.AddressLength, + (UINT64) Descriptor->Address16.Granularity, + Descriptor->Address16.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS16) + + OptionIndex + StringLength; + return (Rnode); +} + + +/******************************************************************************* + * + * FUNCTION: RsDoWordSpaceDescriptor + * + * PARAMETERS: Op - Parent resource descriptor parse node + * CurrentByteOffset - Offset into the resource template AML + * buffer (to track references to the desc) + * + * RETURN: Completed resource node + * + * DESCRIPTION: Construct a long "WordSpace" descriptor + * + ******************************************************************************/ + +ASL_RESOURCE_NODE * +RsDoWordSpaceDescriptor ( + ACPI_PARSE_OBJECT *Op, + UINT32 CurrentByteOffset) +{ + AML_RESOURCE *Descriptor; + ACPI_PARSE_OBJECT *InitializerOp; + ACPI_PARSE_OBJECT *MinOp = NULL; + ACPI_PARSE_OBJECT *MaxOp = NULL; + ACPI_PARSE_OBJECT *LengthOp = NULL; + ACPI_PARSE_OBJECT *GranOp = NULL; + ASL_RESOURCE_NODE *Rnode; + UINT8 *OptionalFields; + UINT16 StringLength = 0; + UINT32 OptionIndex = 0; + UINT32 i; + BOOLEAN ResSourceIndex = FALSE; + + + InitializerOp = Op->Asl.Child; + StringLength = RsGetStringDataLength (InitializerOp); + + Rnode = RsAllocateResourceNode ( + sizeof (AML_RESOURCE_ADDRESS16) + 1 + StringLength); + + Descriptor = Rnode->Buffer; + Descriptor->Address16.DescriptorType = ACPI_RESOURCE_NAME_ADDRESS16; + + /* + * Initial descriptor length -- may be enlarged if there are + * optional fields present + */ + OptionalFields = ((UINT8 *) Descriptor) + sizeof (AML_RESOURCE_ADDRESS16); + Descriptor->Address16.ResourceLength = (UINT16) + (sizeof (AML_RESOURCE_ADDRESS16) - + sizeof (AML_RESOURCE_LARGE_HEADER)); + + /* Process all child initialization nodes */ + + for (i = 0; InitializerOp; i++) + { + switch (i) + { + case 0: /* Resource Type */ + + Descriptor->Address16.ResourceType = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 1: /* Resource Usage */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 0, 1); + break; + + case 2: /* DecodeType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 1, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_DECODE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 1); + break; + + case 3: /* MinType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 2, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MINTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 2); + break; + + case 4: /* MaxType */ + + RsSetFlagBits (&Descriptor->Address16.Flags, InitializerOp, 3, 0); + RsCreateBitField (InitializerOp, ACPI_RESTAG_MAXTYPE, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Flags), 3); + break; + + case 5: /* Type-Specific flags */ + + Descriptor->Address16.SpecificFlags = + (UINT8) InitializerOp->Asl.Value.Integer; + break; + + case 6: /* Address Granularity */ + + Descriptor->Address16.Granularity = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_GRANULARITY, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Granularity)); + GranOp = InitializerOp; + break; + + case 7: /* Min Address */ + + Descriptor->Address16.Minimum = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MINADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Minimum)); + MinOp = InitializerOp; + break; + + case 8: /* Max Address */ + + Descriptor->Address16.Maximum = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_MAXADDR, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.Maximum)); + MaxOp = InitializerOp; + break; + + case 9: /* Translation Offset */ + + Descriptor->Address16.TranslationOffset = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_TRANSLATION, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.TranslationOffset)); + break; + + case 10: /* Address Length */ + + Descriptor->Address16.AddressLength = + (UINT16) InitializerOp->Asl.Value.Integer; + RsCreateWordField (InitializerOp, ACPI_RESTAG_LENGTH, + CurrentByteOffset + ASL_RESDESC_OFFSET (Address16.AddressLength)); + LengthOp = InitializerOp; + break; + + case 11: /* ResSourceIndex [Optional Field - BYTE] */ + + if (InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) + { + OptionalFields[0] = (UINT8) InitializerOp->Asl.Value.Integer; + OptionIndex++; + Descriptor->Address16.ResourceLength++; + ResSourceIndex = TRUE; + } + break; + + case 12: /* ResSource [Optional Field - STRING] */ + + if ((InitializerOp->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (InitializerOp->Asl.Value.String)) + { + if (StringLength) + { + Descriptor->Address16.ResourceLength = (UINT16) + (Descriptor->Address16.ResourceLength + StringLength); + + strcpy ((char *) + &OptionalFields[OptionIndex], + InitializerOp->Asl.Value.String); + + /* ResourceSourceIndex must also be valid */ + + if (!ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_INDEX, + InitializerOp, NULL); + } + } + } + +#if 0 + /* + * Not a valid ResourceSource, ResourceSourceIndex must also + * be invalid + */ + else if (ResSourceIndex) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_SOURCE, + InitializerOp, NULL); + } +#endif + break; + + case 13: /* ResourceTag */ + + UtAttachNamepathToOwner (Op, InitializerOp); + break; + + default: + + AslError (ASL_ERROR, ASL_MSG_RESOURCE_LIST, InitializerOp, NULL); + break; + } + + InitializerOp = RsCompleteNodeAndGetNext (InitializerOp); + } + + /* Validate the Min/Max/Len/Gran values */ + + RsLargeAddressCheck ( + (UINT64) Descriptor->Address16.Minimum, + (UINT64) Descriptor->Address16.Maximum, + (UINT64) Descriptor->Address16.AddressLength, + (UINT64) Descriptor->Address16.Granularity, + Descriptor->Address16.Flags, + MinOp, MaxOp, LengthOp, GranOp, Op); + + Rnode->BufferLength = sizeof (AML_RESOURCE_ADDRESS16) + + OptionIndex + StringLength; + return (Rnode); +} diff --git a/sys/contrib/dev/acpica/compiler/aslstartup.c b/sys/contrib/dev/acpica/compiler/aslstartup.c new file mode 100644 index 0000000..9c5ef15 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslstartup.c @@ -0,0 +1,587 @@ + +/****************************************************************************** + * + * Module Name: aslstartup - Compiler startup routines, called from main + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/include/actables.h> +#include <contrib/dev/acpica/include/acapps.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslstartup") + + +#define ASL_MAX_FILES 256 +static char *FileList[ASL_MAX_FILES]; +static BOOLEAN AslToFile = TRUE; + + +/* Local prototypes */ + +static char ** +AsDoWildcard ( + char *DirectoryPathname, + char *FileSpecifier); + +static UINT8 +AslDetectSourceFileType ( + ASL_FILE_INFO *Info); + + +/******************************************************************************* + * + * FUNCTION: AslInitializeGlobals + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Re-initialize globals needed to restart the compiler. This + * allows multiple files to be disassembled and/or compiled. + * + ******************************************************************************/ + +void +AslInitializeGlobals ( + void) +{ + UINT32 i; + + + /* Init compiler globals */ + + Gbl_CurrentColumn = 0; + Gbl_CurrentLineNumber = 1; + Gbl_LogicalLineNumber = 1; + Gbl_CurrentLineOffset = 0; + Gbl_InputFieldCount = 0; + Gbl_InputByteCount = 0; + Gbl_NsLookupCount = 0; + Gbl_LineBufPtr = Gbl_CurrentLineBuffer; + + Gbl_ErrorLog = NULL; + Gbl_NextError = NULL; + Gbl_Signature = NULL; + Gbl_FileType = 0; + + TotalExecutableOpcodes = 0; + TotalNamedObjects = 0; + TotalKeywords = 0; + TotalParseNodes = 0; + TotalMethods = 0; + TotalAllocations = 0; + TotalAllocated = 0; + TotalFolds = 0; + + AslGbl_NextEvent = 0; + for (i = 0; i < ASL_NUM_REPORT_LEVELS; i++) + { + Gbl_ExceptionCount[i] = 0; + } + + for (i = ASL_FILE_INPUT; i <= ASL_MAX_FILE_TYPE; i++) + { + Gbl_Files[i].Handle = NULL; + Gbl_Files[i].Filename = NULL; + } +} + + +/****************************************************************************** + * + * FUNCTION: AsDoWildcard + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Process files via wildcards. This function is for the Windows + * case only. + * + ******************************************************************************/ + +static char ** +AsDoWildcard ( + char *DirectoryPathname, + char *FileSpecifier) +{ +#ifdef WIN32 + void *DirInfo; + char *Filename; + int FileCount; + + + FileCount = 0; + + /* Open parent directory */ + + DirInfo = AcpiOsOpenDirectory (DirectoryPathname, FileSpecifier, REQUEST_FILE_ONLY); + if (!DirInfo) + { + /* Either the directory of file does not exist */ + + Gbl_Files[ASL_FILE_INPUT].Filename = FileSpecifier; + FlFileError (ASL_FILE_INPUT, ASL_MSG_OPEN); + AslAbort (); + } + + /* Process each file that matches the wildcard specification */ + + while ((Filename = AcpiOsGetNextFilename (DirInfo))) + { + /* Add the filename to the file list */ + + FileList[FileCount] = AcpiOsAllocate (strlen (Filename) + 1); + strcpy (FileList[FileCount], Filename); + FileCount++; + + if (FileCount >= ASL_MAX_FILES) + { + printf ("Max files reached\n"); + FileList[0] = NULL; + return (FileList); + } + } + + /* Cleanup */ + + AcpiOsCloseDirectory (DirInfo); + FileList[FileCount] = NULL; + return (FileList); + +#else + /* + * Linux/Unix cases - Wildcards are expanded by the shell automatically. + * Just return the filename in a null terminated list + */ + FileList[0] = AcpiOsAllocate (strlen (FileSpecifier) + 1); + strcpy (FileList[0], FileSpecifier); + FileList[1] = NULL; + + return (FileList); +#endif +} + + +/******************************************************************************* + * + * FUNCTION: AslDetectSourceFileType + * + * PARAMETERS: Info - Name/Handle for the file (must be open) + * + * RETURN: File Type + * + * DESCRIPTION: Determine the type of the input file. Either binary (contains + * non-ASCII characters), ASL file, or an ACPI Data Table file. + * + ******************************************************************************/ + +static UINT8 +AslDetectSourceFileType ( + ASL_FILE_INFO *Info) +{ + char *FileChar; + UINT8 Type; + ACPI_STATUS Status; + + + /* Check for 100% ASCII source file (comments are ignored) */ + + Status = FlCheckForAscii (Info); + if (ACPI_FAILURE (Status)) + { + printf ("Non-ascii input file - %s\n", Info->Filename); + Type = ASL_INPUT_TYPE_BINARY; + goto Cleanup; + } + + /* + * File is ASCII. Determine if this is an ASL file or an ACPI data + * table file. + */ + while (fgets (Gbl_CurrentLineBuffer, ASL_LINE_BUFFER_SIZE, Info->Handle)) + { + /* Uppercase the buffer for caseless compare */ + + FileChar = Gbl_CurrentLineBuffer; + while (*FileChar) + { + *FileChar = (char) toupper ((int) *FileChar); + FileChar++; + } + + /* Presence of "DefinitionBlock" indicates actual ASL code */ + + if (strstr (Gbl_CurrentLineBuffer, "DEFINITIONBLOCK")) + { + /* Appears to be an ASL file */ + + Type = ASL_INPUT_TYPE_ASCII_ASL; + goto Cleanup; + } + } + + /* Not an ASL source file, default to a data table source file */ + + Type = ASL_INPUT_TYPE_ASCII_DATA; + +Cleanup: + + /* Must seek back to the start of the file */ + + fseek (Info->Handle, 0, SEEK_SET); + return (Type); +} + + +/******************************************************************************* + * + * FUNCTION: AslDoOneFile + * + * PARAMETERS: Filename - Name of the file + * + * RETURN: Status + * + * DESCRIPTION: Process a single file - either disassemble, compile, or both + * + ******************************************************************************/ + +ACPI_STATUS +AslDoOneFile ( + char *Filename) +{ + ACPI_STATUS Status; + + + /* Re-initialize "some" compiler/preprocessor globals */ + + AslInitializeGlobals (); + PrInitializeGlobals (); + + Gbl_Files[ASL_FILE_INPUT].Filename = Filename; + + /* + * AML Disassembly (Optional) + */ + if (Gbl_DisasmFlag || Gbl_GetAllTables) + { + /* ACPICA subsystem initialization */ + + Status = AdInitialize (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Status = AcpiAllocateRootTable (4); + if (ACPI_FAILURE (Status)) + { + AcpiOsPrintf ("Could not initialize ACPI Table Manager, %s\n", + AcpiFormatException (Status)); + return (Status); + } + + /* This is where the disassembly happens */ + + AcpiGbl_DbOpt_disasm = TRUE; + Status = AdAmlDisassemble (AslToFile, + Gbl_Files[ASL_FILE_INPUT].Filename, + Gbl_OutputFilenamePrefix, + &Gbl_Files[ASL_FILE_INPUT].Filename, + Gbl_GetAllTables); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Shutdown compiler and ACPICA subsystem */ + + AeClearErrorLog (); + (void) AcpiTerminate (); + + /* + * Gbl_Files[ASL_FILE_INPUT].Filename was replaced with the + * .DSL disassembly file, which can now be compiled if requested + */ + if (Gbl_DoCompile) + { + AcpiOsPrintf ("\nCompiling \"%s\"\n", + Gbl_Files[ASL_FILE_INPUT].Filename); + } + else + { + Gbl_Files[ASL_FILE_INPUT].Filename = NULL; + return (AE_OK); + } + } + + /* + * Open the input file. Here, this should be an ASCII source file, + * either an ASL file or a Data Table file + */ + Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename); + if (ACPI_FAILURE (Status)) + { + AePrintErrorLog (ASL_FILE_STDERR); + return (AE_ERROR); + } + + /* Determine input file type */ + + Gbl_FileType = AslDetectSourceFileType (&Gbl_Files[ASL_FILE_INPUT]); + if (Gbl_FileType == ASL_INPUT_TYPE_BINARY) + { + return (AE_ERROR); + } + + /* + * If -p not specified, we will use the input filename as the + * output filename prefix + */ + if (Gbl_UseDefaultAmlFilename) + { + Gbl_OutputFilenamePrefix = Gbl_Files[ASL_FILE_INPUT].Filename; + } + + /* Open the optional output files (listings, etc.) */ + + Status = FlOpenMiscOutputFiles (Gbl_OutputFilenamePrefix); + if (ACPI_FAILURE (Status)) + { + AePrintErrorLog (ASL_FILE_STDERR); + return (AE_ERROR); + } + + /* + * Compilation of ASL source versus DataTable source uses different + * compiler subsystems + */ + switch (Gbl_FileType) + { + /* + * Data Table Compilation + */ + case ASL_INPUT_TYPE_ASCII_DATA: + + Status = DtDoCompile (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + if (Gbl_Signature) + { + ACPI_FREE (Gbl_Signature); + Gbl_Signature = NULL; + } + + /* Check if any errors occurred during compile */ + + Status = AslCheckForErrorExit (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Cleanup (for next source file) and exit */ + + AeClearErrorLog (); + PrTerminatePreprocessor (); + return (Status); + + /* + * ASL Compilation + */ + case ASL_INPUT_TYPE_ASCII_ASL: + + /* ACPICA subsystem initialization */ + + Status = AdInitialize (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + (void) CmDoCompile (); + (void) AcpiTerminate (); + + /* Check if any errors occurred during compile */ + + Status = AslCheckForErrorExit (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Cleanup (for next source file) and exit */ + + AeClearErrorLog (); + PrTerminatePreprocessor (); + return (AE_OK); + + case ASL_INPUT_TYPE_BINARY: + + AePrintErrorLog (ASL_FILE_STDERR); + return (AE_ERROR); + + default: + printf ("Unknown file type %X\n", Gbl_FileType); + return (AE_ERROR); + } +} + + +/******************************************************************************* + * + * FUNCTION: AslDoOnePathname + * + * PARAMETERS: Pathname - Full pathname, possibly with wildcards + * + * RETURN: Status + * + * DESCRIPTION: Process one pathname, possible terminated with a wildcard + * specification. If a wildcard, it is expanded and the multiple + * files are processed. + * + ******************************************************************************/ + +ACPI_STATUS +AslDoOnePathname ( + char *Pathname, + ASL_PATHNAME_CALLBACK PathCallback) +{ + ACPI_STATUS Status = AE_OK; + char **WildcardList; + char *Filename; + char *FullPathname; + + + /* Split incoming path into a directory/filename combo */ + + Status = FlSplitInputPathname (Pathname, &Gbl_DirectoryPath, &Filename); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Expand possible wildcard into a file list (Windows/DOS only) */ + + WildcardList = AsDoWildcard (Gbl_DirectoryPath, Filename); + while (*WildcardList) + { + FullPathname = ACPI_ALLOCATE ( + strlen (Gbl_DirectoryPath) + strlen (*WildcardList) + 1); + + /* Construct a full path to the file */ + + strcpy (FullPathname, Gbl_DirectoryPath); + strcat (FullPathname, *WildcardList); + + /* + * If -p not specified, we will use the input filename as the + * output filename prefix + */ + if (Gbl_UseDefaultAmlFilename) + { + Gbl_OutputFilenamePrefix = FullPathname; + } + + /* Save status from all compiles */ + + Status |= (*PathCallback) (FullPathname); + + ACPI_FREE (FullPathname); + ACPI_FREE (*WildcardList); + *WildcardList = NULL; + WildcardList++; + } + + ACPI_FREE (Gbl_DirectoryPath); + ACPI_FREE (Filename); + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: AslCheckForErrorExit + * + * PARAMETERS: None. Examines global exception count array + * + * RETURN: Status + * + * DESCRIPTION: Determine if compiler should abort with error status + * + ******************************************************************************/ + +ACPI_STATUS +AslCheckForErrorExit ( + void) +{ + + /* + * Return non-zero exit code if there have been errors, unless the + * global ignore error flag has been set + */ + if (!Gbl_IgnoreErrors) + { + if (Gbl_ExceptionCount[ASL_ERROR] > 0) + { + return (AE_ERROR); + } + + /* Optionally treat warnings as errors */ + + if (Gbl_WarningsAsErrors) + { + if ((Gbl_ExceptionCount[ASL_WARNING] > 0) || + (Gbl_ExceptionCount[ASL_WARNING2] > 0) || + (Gbl_ExceptionCount[ASL_WARNING3] > 0)) + { + return (AE_ERROR); + } + } + } + + return (AE_OK); +} diff --git a/sys/contrib/dev/acpica/compiler/aslstubs.c b/sys/contrib/dev/acpica/compiler/aslstubs.c new file mode 100644 index 0000000..f953b30 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslstubs.c @@ -0,0 +1,253 @@ + +/****************************************************************************** + * + * Module Name: aslstubs - Stubs used to link to Aml interpreter + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/include/acdispat.h> +#include <contrib/dev/acpica/include/actables.h> +#include <contrib/dev/acpica/include/acevents.h> +#include <contrib/dev/acpica/include/acinterp.h> +#include <contrib/dev/acpica/include/acnamesp.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslstubs") + + +/* + * Stubs to simplify linkage to the ACPI CA core subsystem. + * Things like Events, Global Lock, etc. are not used + * by the compiler, so they are stubbed out here. + */ +ACPI_PHYSICAL_ADDRESS +AeLocalGetRootPointer ( + void) +{ + return 0; +} + +void +AcpiNsExecModuleCodeList ( + void) +{ +} + +ACPI_STATUS +AcpiHwReadPort ( + ACPI_IO_ADDRESS Address, + UINT32 *Value, + UINT32 Width) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiHwWritePort ( + ACPI_IO_ADDRESS Address, + UINT32 Value, + UINT32 Width) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsMethodError ( + ACPI_STATUS Status, + ACPI_WALK_STATE *WalkState) +{ + return (Status); +} + +ACPI_STATUS +AcpiDsMethodDataGetValue ( + UINT8 Type, + UINT32 Index, + ACPI_WALK_STATE *WalkState, + ACPI_OPERAND_OBJECT **DestDesc) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsMethodDataGetNode ( + UINT8 Type, + UINT32 Index, + ACPI_WALK_STATE *WalkState, + ACPI_NAMESPACE_NODE **Node) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiDsStoreObjectToLocal ( + UINT8 Type, + UINT32 Index, + ACPI_OPERAND_OBJECT *SrcDesc, + ACPI_WALK_STATE *WalkState) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEvQueueNotifyRequest ( + ACPI_NAMESPACE_NODE *Node, + UINT32 NotifyValue) +{ + return (AE_OK); +} + +BOOLEAN +AcpiEvIsNotifyObject ( + ACPI_NAMESPACE_NODE *Node) +{ + return (FALSE); +} + +#if (!ACPI_REDUCED_HARDWARE) +ACPI_STATUS +AcpiEvDeleteGpeBlock ( + ACPI_GPE_BLOCK_INFO *GpeBlock) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEvAcquireGlobalLock ( + UINT16 Timeout) +{ + return (AE_OK); +} + +ACPI_STATUS +AcpiEvReleaseGlobalLock ( + void) +{ + return (AE_OK); +} +#endif /* !ACPI_REDUCED_HARDWARE */ + +ACPI_STATUS +AcpiEvInitializeRegion ( + ACPI_OPERAND_OBJECT *RegionObj, + BOOLEAN AcpiNsLocked) +{ + return (AE_OK); +} + +void +AcpiExDoDebugObject ( + ACPI_OPERAND_OBJECT *SourceDesc, + UINT32 Level, + UINT32 Index) +{ + return; +} + +ACPI_STATUS +AcpiExReadDataFromField ( + ACPI_WALK_STATE *WalkState, + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_OPERAND_OBJECT **RetBufferDesc) +{ + return (AE_SUPPORT); +} + +ACPI_STATUS +AcpiExWriteDataToField ( + ACPI_OPERAND_OBJECT *SourceDesc, + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_OPERAND_OBJECT **ResultDesc) +{ + return (AE_SUPPORT); +} + +ACPI_STATUS +AcpiExLoadTableOp ( + ACPI_WALK_STATE *WalkState, + ACPI_OPERAND_OBJECT **ReturnDesc) +{ + return (AE_SUPPORT); +} + +ACPI_STATUS +AcpiExUnloadTable ( + ACPI_OPERAND_OBJECT *DdbHandle) +{ + return (AE_SUPPORT); +} + +ACPI_STATUS +AcpiExLoadOp ( + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_OPERAND_OBJECT *Target, + ACPI_WALK_STATE *WalkState) +{ + return (AE_SUPPORT); +} + +ACPI_STATUS +AcpiTbFindTable ( + char *Signature, + char *OemId, + char *OemTableId, + UINT32 *TableIndex) +{ + return (AE_SUPPORT); +} + +/* OSL interfaces */ + +ACPI_THREAD_ID +AcpiOsGetThreadId ( + void) +{ + return (0xFFFF); +} + +ACPI_STATUS +AcpiOsExecute ( + ACPI_EXECUTE_TYPE Type, + ACPI_OSD_EXEC_CALLBACK Function, + void *Context) +{ + return (AE_SUPPORT); +} diff --git a/sys/contrib/dev/acpica/compiler/aslsupport.l b/sys/contrib/dev/acpica/compiler/aslsupport.l new file mode 100644 index 0000000..65dd19b --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslsupport.l @@ -0,0 +1,782 @@ + +/****************************************************************************** + * + * Module Name: aslsupport.l - Flex/lex scanner C support routines. + * NOTE: Included into aslcompile.l, not compiled by itself. + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +/* Configuration */ + +#define ASL_SPACES_PER_TAB 4 + +#define ASL_NORMAL_CHAR 0 +#define ASL_ESCAPE_SEQUENCE 1 +#define ASL_OCTAL_CONSTANT 2 +#define ASL_HEX_CONSTANT 3 + + +/* File node - used for "Include" operator file stack */ + +typedef struct asl_file_node +{ + FILE *File; + UINT32 CurrentLineNumber; + YY_BUFFER_STATE State; + char *Filename; + struct asl_file_node *Next; + +} ASL_FILE_NODE; + +/* File stack for the "Include" operator (NOT #include operator) */ + +ASL_FILE_NODE *Gbl_IncludeFileStack = NULL; + + +/******************************************************************************* + * + * FUNCTION: AslDoLineDirective + * + * PARAMETERS: None. Uses input() to access current source code line + * + * RETURN: Updates global line number and filename + * + * DESCRIPTION: Handle #line directives emitted by the preprocessor. + * + * The #line directive is emitted by the preprocesser, and is used to + * pass through line numbers from the original source code file to the + * preprocessor output file (.i). This allows any compiler-generated + * error messages to be displayed with the correct line number. + * + ******************************************************************************/ + +static void +AslDoLineDirective ( + void) +{ + char c; + char *Token; + UINT32 LineNumber; + char *Filename; + + + /* Eat the entire line that contains the #line directive */ + + while ((c = (char) input()) != '\n' && c != EOF) + { + AslInsertLineBuffer (c); + } + AslInsertLineBuffer (0); + + /* First argument is the actual line number */ + + Token = strtok (Gbl_CurrentLineBuffer, " "); + if (!Token) + { + goto ResetAndExit; + } + + /* Convert line number. Subtract one to handle _this_ line */ + + LineNumber = (UINT32) UtDoConstant (Token); + FlSetLineNumber (LineNumber - 1); + + /* Second argument is the optional filename (in double quotes) */ + + Token = strtok (NULL, " \""); + if (Token) + { + Filename = ACPI_ALLOCATE_ZEROED (strlen (Token) + 1); + strcpy (Filename, Token); + FlSetFilename (Filename); + } + + /* Third argument is not supported at this time */ + +ResetAndExit: + AslResetCurrentLineBuffer (); +} + + +/******************************************************************************* + * + * FUNCTION: AslPopInputFileStack + * + * PARAMETERS: None + * + * RETURN: 0 if a node was popped, -1 otherwise + * + * DESCRIPTION: Pop the top of the input file stack and point the parser to + * the saved parse buffer contained in the fnode. Also, set the + * global line counters to the saved values. This function is + * called when an include file reaches EOF. + * + ******************************************************************************/ + +int +AslPopInputFileStack ( + void) +{ + ASL_FILE_NODE *Fnode; + + + Fnode = Gbl_IncludeFileStack; + DbgPrint (ASL_PARSE_OUTPUT, "\nPop InputFile Stack, Fnode %p\n\n", Fnode); + + if (!Fnode) + { + return (-1); + } + + /* Close the current include file */ + + fclose (yyin); + + /* Update the top-of-stack */ + + Gbl_IncludeFileStack = Fnode->Next; + + /* Reset global line counter and filename */ + + Gbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename; + Gbl_CurrentLineNumber = Fnode->CurrentLineNumber; + + /* Point the parser to the popped file */ + + yy_delete_buffer (YY_CURRENT_BUFFER); + yy_switch_to_buffer (Fnode->State); + + /* All done with this node */ + + ACPI_FREE (Fnode); + return (0); +} + + +/******************************************************************************* + * + * FUNCTION: AslPushInputFileStack + * + * PARAMETERS: InputFile - Open file pointer + * Filename - Name of the file + * + * RETURN: None + * + * DESCRIPTION: Push the InputFile onto the file stack, and point the parser + * to this file. Called when an include file is successfully + * opened. + * + ******************************************************************************/ + +void +AslPushInputFileStack ( + FILE *InputFile, + char *Filename) +{ + ASL_FILE_NODE *Fnode; + YY_BUFFER_STATE State; + + + /* Save the current state in an Fnode */ + + Fnode = UtLocalCalloc (sizeof (ASL_FILE_NODE)); + + Fnode->File = yyin; + Fnode->Next = Gbl_IncludeFileStack; + Fnode->State = YY_CURRENT_BUFFER; + Fnode->CurrentLineNumber = Gbl_CurrentLineNumber; + Fnode->Filename = Gbl_Files[ASL_FILE_INPUT].Filename; + + /* Push it on the stack */ + + Gbl_IncludeFileStack = Fnode; + + /* Point the parser to this file */ + + State = yy_create_buffer (InputFile, YY_BUF_SIZE); + yy_switch_to_buffer (State); + + DbgPrint (ASL_PARSE_OUTPUT, "\nPush InputFile Stack, returning %p\n\n", InputFile); + + /* Reset the global line count and filename */ + + Gbl_Files[ASL_FILE_INPUT].Filename = Filename; + Gbl_CurrentLineNumber = 1; + yyin = InputFile; +} + + +/******************************************************************************* + * + * FUNCTION: AslResetCurrentLineBuffer + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Reset the Line Buffer to zero, increment global line numbers. + * + ******************************************************************************/ + +void +AslResetCurrentLineBuffer ( + void) +{ + + if (Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle) + { + FlWriteFile (ASL_FILE_SOURCE_OUTPUT, Gbl_CurrentLineBuffer, + Gbl_LineBufPtr - Gbl_CurrentLineBuffer); + } + + Gbl_CurrentLineOffset += Gbl_CurrentColumn; + Gbl_CurrentColumn = 0; + + Gbl_CurrentLineNumber++; + Gbl_LogicalLineNumber++; + Gbl_LineBufPtr = Gbl_CurrentLineBuffer; +} + + +/******************************************************************************* + * + * FUNCTION: AslInsertLineBuffer + * + * PARAMETERS: SourceChar - One char from the input ASL source file + * + * RETURN: None + * + * DESCRIPTION: Put one character of the source file into the temp line buffer + * + ******************************************************************************/ + +void +AslInsertLineBuffer ( + int SourceChar) +{ + UINT32 i; + UINT32 Count = 1; + + + if (SourceChar == EOF) + { + return; + } + + Gbl_InputByteCount++; + + /* Handle tabs. Convert to spaces */ + + if (SourceChar == '\t') + { + SourceChar = ' '; + Count = ASL_SPACES_PER_TAB - + (Gbl_CurrentColumn & (ASL_SPACES_PER_TAB-1)); + } + + for (i = 0; i < Count; i++) + { + Gbl_CurrentColumn++; + + /* Insert the character into the line buffer */ + + *Gbl_LineBufPtr = (UINT8) SourceChar; + Gbl_LineBufPtr++; + + if (Gbl_LineBufPtr > (Gbl_CurrentLineBuffer + (ASL_LINE_BUFFER_SIZE - 1))) + { +#if 0 + /* + * Warning if we have split a long source line. + * <Probably overkill> + */ + sprintf (MsgBuffer, "Max %u", ASL_LINE_BUFFER_SIZE); + AslCommonError (ASL_WARNING, ASL_MSG_LONG_LINE, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, MsgBuffer); +#endif + + AslResetCurrentLineBuffer (); + } + else if (SourceChar == '\n') + { + /* End of line */ + + AslResetCurrentLineBuffer (); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: count + * + * PARAMETERS: yytext - Contains the matched keyword. + * Type - Keyword/Character type: + * 0 = anything except a keyword + * 1 = pseudo-keywords + * 2 = non-executable ASL keywords + * 3 = executable ASL keywords + * + * RETURN: None + * + * DESCRIPTION: Count keywords and put them into the line buffer + * + ******************************************************************************/ + +static void +count ( + int Type) +{ + int i; + + + switch (Type) + { + case 2: + TotalKeywords++; + TotalNamedObjects++; + break; + + case 3: + TotalKeywords++; + TotalExecutableOpcodes++; + break; + } + + for (i = 0; (yytext[i] != 0) && (yytext[i] != EOF); i++) + { + AslInsertLineBuffer (yytext[i]); + *Gbl_LineBufPtr = 0; + } +} + + +/******************************************************************************* + * + * FUNCTION: AslDoComment + * + * PARAMETERS: none + * + * RETURN: none + * + * DESCRIPTION: Process a standard comment. + * + ******************************************************************************/ + +static char +AslDoComment ( + void) +{ + char c; + char c1 = 0; + + + AslInsertLineBuffer ('/'); + AslInsertLineBuffer ('*'); + +loop: + + /* Eat chars until end-of-comment */ + + while ((c = (char) input()) != '*' && c != EOF) + { + AslInsertLineBuffer (c); + c1 = c; + } + + if (c == EOF) + { + goto EarlyEOF; + } + + /* + * Check for nested comment -- can help catch cases where a previous + * comment was accidently left unterminated + */ + if ((c1 == '/') && (c == '*')) + { + AslCommonError (ASL_WARNING, ASL_MSG_NESTED_COMMENT, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_InputByteCount, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + } + + /* Comment is closed only if the NEXT character is a slash */ + + AslInsertLineBuffer (c); + + if ((c1 = (char) input()) != '/' && c1 != EOF) + { + unput(c1); + goto loop; + } + + if (c1 == EOF) + { + goto EarlyEOF; + } + + AslInsertLineBuffer (c1); + return (TRUE); + + +EarlyEOF: + /* + * Premature End-Of-File + */ + AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + return (FALSE); +} + + +/******************************************************************************* + * + * FUNCTION: AslDoCommentType2 + * + * PARAMETERS: none + * + * RETURN: none + * + * DESCRIPTION: Process a new "//" comment. + * + ******************************************************************************/ + +static char +AslDoCommentType2 ( + void) +{ + char c; + + + AslInsertLineBuffer ('/'); + AslInsertLineBuffer ('/'); + + while ((c = (char) input()) != '\n' && c != EOF) + { + AslInsertLineBuffer (c); + } + + if (c == EOF) + { + /* End of file is OK, change to newline. Let parser detect EOF later */ + + c = '\n'; + } + + AslInsertLineBuffer (c); + return (TRUE); +} + + +/******************************************************************************* + * + * FUNCTION: AslDoStringLiteral + * + * PARAMETERS: none + * + * RETURN: none + * + * DESCRIPTION: Process a string literal (surrounded by quotes) + * + ******************************************************************************/ + +static char +AslDoStringLiteral ( + void) +{ + char *StringBuffer = MsgBuffer; + char *EndBuffer = MsgBuffer + ASL_MSG_BUFFER_SIZE; + char *CleanString; + char StringChar; + UINT32 State = ASL_NORMAL_CHAR; + UINT32 i = 0; + UINT8 Digit; + char ConvertBuffer[4]; + + + /* + * Eat chars until end-of-literal. + * NOTE: Put back the original surrounding quotes into the + * source line buffer. + */ + AslInsertLineBuffer ('\"'); + while ((StringChar = (char) input()) != EOF) + { + AslInsertLineBuffer (StringChar); + +DoCharacter: + + switch (State) + { + case ASL_NORMAL_CHAR: + + switch (StringChar) + { + case '\\': + /* + * Special handling for backslash-escape sequence. We will + * toss the backslash and translate the escape char(s). + */ + State = ASL_ESCAPE_SEQUENCE; + continue; + + case '\"': + + /* String terminator */ + + goto CompletedString; + } + break; + + + case ASL_ESCAPE_SEQUENCE: + + State = ASL_NORMAL_CHAR; + switch (StringChar) + { + case 'a': + StringChar = 0x07; /* BELL */ + break; + + case 'b': + StringChar = 0x08; /* BACKSPACE */ + break; + + case 'f': + StringChar = 0x0C; /* FORMFEED */ + break; + + case 'n': + StringChar = 0x0A; /* LINEFEED */ + break; + + case 'r': + StringChar = 0x0D; /* CARRIAGE RETURN*/ + break; + + case 't': + StringChar = 0x09; /* HORIZONTAL TAB */ + break; + + case 'v': + StringChar = 0x0B; /* VERTICAL TAB */ + break; + + case 'x': + State = ASL_HEX_CONSTANT; + i = 0; + continue; + + case '\'': /* Single Quote */ + case '\"': /* Double Quote */ + case '\\': /* Backslash */ + break; + + default: + + /* Check for an octal digit (0-7) */ + + if (ACPI_IS_OCTAL_DIGIT (StringChar)) + { + State = ASL_OCTAL_CONSTANT; + ConvertBuffer[0] = StringChar; + i = 1; + continue; + } + + /* Unknown escape sequence issue warning, but use the character */ + + AslCommonError (ASL_WARNING, ASL_MSG_INVALID_ESCAPE, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + break; + } + break; + + + case ASL_OCTAL_CONSTANT: + + /* Up to three octal digits allowed */ + + if (!ACPI_IS_OCTAL_DIGIT (StringChar) || + (i > 2)) + { + /* + * Reached end of the constant. Convert the assembled ASCII + * string and resume processing of the next character + */ + ConvertBuffer[i] = 0; + Digit = (UINT8) ACPI_STRTOUL (ConvertBuffer, NULL, 8); + + /* Check for NULL or non-ascii character (ignore if so) */ + + if ((Digit == 0) || (Digit > ACPI_ASCII_MAX)) + { + AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + } + else + { + *StringBuffer = (char) Digit; + StringBuffer++; + if (StringBuffer >= EndBuffer) + { + goto BufferOverflow; + } + } + + State = ASL_NORMAL_CHAR; + goto DoCharacter; + break; + } + + /* Append another digit of the constant */ + + ConvertBuffer[i] = StringChar; + i++; + continue; + + + case ASL_HEX_CONSTANT: + + /* Up to two hex digits allowed */ + + if (!ACPI_IS_XDIGIT (StringChar) || + (i > 1)) + { + /* + * Reached end of the constant. Convert the assembled ASCII + * string and resume processing of the next character + */ + ConvertBuffer[i] = 0; + Digit = (UINT8) ACPI_STRTOUL (ConvertBuffer, NULL, 16); + + /* Check for NULL or non-ascii character (ignore if so) */ + + if ((Digit == 0) || (Digit > ACPI_ASCII_MAX)) + { + AslCommonError (ASL_WARNING, ASL_MSG_INVALID_STRING, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + } + else + { + *StringBuffer = (char) Digit; + StringBuffer++; + if (StringBuffer >= EndBuffer) + { + goto BufferOverflow; + } + } + + State = ASL_NORMAL_CHAR; + goto DoCharacter; + break; + } + + /* Append another digit of the constant */ + + ConvertBuffer[i] = StringChar; + i++; + continue; + } + + /* Save the finished character */ + + *StringBuffer = StringChar; + StringBuffer++; + if (StringBuffer >= EndBuffer) + { + goto BufferOverflow; + } + } + + /* + * Premature End-Of-File + */ + AslCommonError (ASL_ERROR, ASL_MSG_EARLY_EOF, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + return (FALSE); + + +CompletedString: + /* + * Null terminate the input string and copy string to a new buffer + */ + *StringBuffer = 0; + + CleanString = UtGetStringBuffer (strlen (MsgBuffer) + 1); + if (!CleanString) + { + AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + return (FALSE); + } + + ACPI_STRCPY (CleanString, MsgBuffer); + AslCompilerlval.s = CleanString; + return (TRUE); + + +BufferOverflow: + + /* Literal was too long */ + + AslCommonError (ASL_ERROR, ASL_MSG_STRING_LENGTH, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_CurrentLineOffset, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, "Max length 4096"); + return (FALSE); +} diff --git a/sys/contrib/dev/acpica/compiler/asltransform.c b/sys/contrib/dev/acpica/compiler/asltransform.c new file mode 100644 index 0000000..a3c73b0 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asltransform.c @@ -0,0 +1,782 @@ + +/****************************************************************************** + * + * Module Name: asltransform - Parse tree transforms + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("asltransform") + +/* Local prototypes */ + +static void +TrTransformSubtree ( + ACPI_PARSE_OBJECT *Op); + +static char * +TrAmlGetNextTempName ( + ACPI_PARSE_OBJECT *Op, + UINT8 *TempCount); + +static void +TrAmlInitLineNumbers ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *Neighbor); + +static void +TrAmlInitNode ( + ACPI_PARSE_OBJECT *Op, + UINT16 ParseOpcode); + +static void +TrAmlSetSubtreeParent ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *Parent); + +static void +TrAmlInsertPeer ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *NewPeer); + +static void +TrDoDefinitionBlock ( + ACPI_PARSE_OBJECT *Op); + +static void +TrDoSwitch ( + ACPI_PARSE_OBJECT *StartNode); + + +/******************************************************************************* + * + * FUNCTION: TrAmlGetNextTempName + * + * PARAMETERS: Op - Current parse op + * TempCount - Current temporary counter. Was originally + * per-module; Currently per method, could be + * expanded to per-scope. + * + * RETURN: A pointer to name (allocated here). + * + * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are + * reserved for use by the ASL compiler. (_T_0 through _T_Z) + * + ******************************************************************************/ + +static char * +TrAmlGetNextTempName ( + ACPI_PARSE_OBJECT *Op, + UINT8 *TempCount) +{ + char *TempName; + + + if (*TempCount >= (10+26)) /* 0-35 valid: 0-9 and A-Z for TempName[3] */ + { + /* Too many temps */ + + AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL); + return (NULL); + } + + TempName = UtLocalCalloc (5); + + if (*TempCount < 10) /* 0-9 */ + { + TempName[3] = (char) (*TempCount + '0'); + } + else /* 10-35: A-Z */ + { + TempName[3] = (char) (*TempCount + ('A' - 10)); + } + (*TempCount)++; + + /* First three characters are always "_T_" */ + + TempName[0] = '_'; + TempName[1] = 'T'; + TempName[2] = '_'; + + return (TempName); +} + + +/******************************************************************************* + * + * FUNCTION: TrAmlInitLineNumbers + * + * PARAMETERS: Op - Op to be initialized + * Neighbor - Op used for initialization values + * + * RETURN: None + * + * DESCRIPTION: Initialized the various line numbers for a parse node. + * + ******************************************************************************/ + +static void +TrAmlInitLineNumbers ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *Neighbor) +{ + + Op->Asl.EndLine = Neighbor->Asl.EndLine; + Op->Asl.EndLogicalLine = Neighbor->Asl.EndLogicalLine; + Op->Asl.LineNumber = Neighbor->Asl.LineNumber; + Op->Asl.LogicalByteOffset = Neighbor->Asl.LogicalByteOffset; + Op->Asl.LogicalLineNumber = Neighbor->Asl.LogicalLineNumber; +} + + +/******************************************************************************* + * + * FUNCTION: TrAmlInitNode + * + * PARAMETERS: Op - Op to be initialized + * ParseOpcode - Opcode for this node + * + * RETURN: None + * + * DESCRIPTION: Initialize a node with the parse opcode and opcode name. + * + ******************************************************************************/ + +static void +TrAmlInitNode ( + ACPI_PARSE_OBJECT *Op, + UINT16 ParseOpcode) +{ + + Op->Asl.ParseOpcode = ParseOpcode; + UtSetParseOpName (Op); +} + + +/******************************************************************************* + * + * FUNCTION: TrAmlSetSubtreeParent + * + * PARAMETERS: Op - First node in a list of peer nodes + * Parent - Parent of the subtree + * + * RETURN: None + * + * DESCRIPTION: Set the parent for all peer nodes in a subtree + * + ******************************************************************************/ + +static void +TrAmlSetSubtreeParent ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *Parent) +{ + ACPI_PARSE_OBJECT *Next; + + + Next = Op; + while (Next) + { + Next->Asl.Parent = Parent; + Next = Next->Asl.Next; + } +} + + +/******************************************************************************* + * + * FUNCTION: TrAmlInsertPeer + * + * PARAMETERS: Op - First node in a list of peer nodes + * NewPeer - Peer node to insert + * + * RETURN: None + * + * DESCRIPTION: Insert a new peer node into a list of peers. + * + ******************************************************************************/ + +static void +TrAmlInsertPeer ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *NewPeer) +{ + + NewPeer->Asl.Next = Op->Asl.Next; + Op->Asl.Next = NewPeer; +} + + +/******************************************************************************* + * + * FUNCTION: TrAmlTransformWalk + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: None + * + * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML + * operands. + * + ******************************************************************************/ + +ACPI_STATUS +TrAmlTransformWalk ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + + TrTransformSubtree (Op); + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: TrTransformSubtree + * + * PARAMETERS: Op - The parent parse node + * + * RETURN: None + * + * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more + * complex AML opcodes require processing of the child nodes + * (arguments/operands). + * + ******************************************************************************/ + +static void +TrTransformSubtree ( + ACPI_PARSE_OBJECT *Op) +{ + + if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE) + { + return; + } + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_DEFINITIONBLOCK: + TrDoDefinitionBlock (Op); + break; + + case PARSEOP_SWITCH: + TrDoSwitch (Op); + break; + + case PARSEOP_METHOD: + + /* + * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global, + * however + */ + Gbl_TempCount = 0; + break; + + default: + /* Nothing to do here for other opcodes */ + break; + } +} + + +/******************************************************************************* + * + * FUNCTION: TrDoDefinitionBlock + * + * PARAMETERS: Op - Parse node + * + * RETURN: None + * + * DESCRIPTION: Find the end of the definition block and set a global to this + * node. It is used by the compiler to insert compiler-generated + * names at the root level of the namespace. + * + ******************************************************************************/ + +static void +TrDoDefinitionBlock ( + ACPI_PARSE_OBJECT *Op) +{ + ACPI_PARSE_OBJECT *Next; + UINT32 i; + + + Next = Op->Asl.Child; + for (i = 0; i < 5; i++) + { + Next = Next->Asl.Next; + if (i == 0) + { + /* + * This is the table signature. Only the DSDT can be assumed + * to be at the root of the namespace; Therefore, namepath + * optimization can only be performed on the DSDT. + */ + if (!ACPI_COMPARE_NAME (Next->Asl.Value.String, ACPI_SIG_DSDT)) + { + Gbl_ReferenceOptimizationFlag = FALSE; + } + } + } + + Gbl_FirstLevelInsertionNode = Next; +} + + +/******************************************************************************* + * + * FUNCTION: TrDoSwitch + * + * PARAMETERS: StartNode - Parse node for SWITCH + * + * RETURN: None + * + * + * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is + * no actual AML opcode for SWITCH -- it must be simulated. + * + ******************************************************************************/ + +static void +TrDoSwitch ( + ACPI_PARSE_OBJECT *StartNode) +{ + ACPI_PARSE_OBJECT *Next; + ACPI_PARSE_OBJECT *CaseOp = NULL; + ACPI_PARSE_OBJECT *CaseBlock = NULL; + ACPI_PARSE_OBJECT *DefaultOp = NULL; + ACPI_PARSE_OBJECT *CurrentParentNode; + ACPI_PARSE_OBJECT *Conditional = NULL; + ACPI_PARSE_OBJECT *Predicate; + ACPI_PARSE_OBJECT *Peer; + ACPI_PARSE_OBJECT *NewOp; + ACPI_PARSE_OBJECT *NewOp2; + ACPI_PARSE_OBJECT *MethodOp; + ACPI_PARSE_OBJECT *StoreOp; + ACPI_PARSE_OBJECT *BreakOp; + ACPI_PARSE_OBJECT *BufferOp; + char *PredicateValueName; + UINT16 Index; + UINT32 Btype; + + + /* Start node is the Switch() node */ + + CurrentParentNode = StartNode; + + /* Create a new temp name of the form _T_x */ + + PredicateValueName = TrAmlGetNextTempName (StartNode, &Gbl_TempCount); + if (!PredicateValueName) + { + return; + } + + /* First child is the Switch() predicate */ + + Next = StartNode->Asl.Child; + + /* + * Examine the return type of the Switch Value - + * must be Integer/Buffer/String + */ + Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE); + Btype = AslKeywordMapping[Index].AcpiBtype; + if ((Btype != ACPI_BTYPE_INTEGER) && + (Btype != ACPI_BTYPE_STRING) && + (Btype != ACPI_BTYPE_BUFFER)) + { + AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL); + Btype = ACPI_BTYPE_INTEGER; + } + + /* CASE statements start at next child */ + + Peer = Next->Asl.Next; + while (Peer) + { + Next = Peer; + Peer = Next->Asl.Next; + + if (Next->Asl.ParseOpcode == PARSEOP_CASE) + { + if (CaseOp) + { + /* Add an ELSE to complete the previous CASE */ + + if (!Conditional) + { + return; + } + NewOp = TrCreateLeafNode (PARSEOP_ELSE); + NewOp->Asl.Parent = Conditional->Asl.Parent; + TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent); + + /* Link ELSE node as a peer to the previous IF */ + + TrAmlInsertPeer (Conditional, NewOp); + CurrentParentNode = NewOp; + } + + CaseOp = Next; + Conditional = CaseOp; + CaseBlock = CaseOp->Asl.Child->Asl.Next; + Conditional->Asl.Child->Asl.Next = NULL; + Predicate = CaseOp->Asl.Child; + + if ((Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE) || + (Predicate->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)) + { + /* + * Convert the package declaration to this form: + * + * If (LNotEqual (Match (Package(<size>){<data>}, + * MEQ, _T_x, MTR, Zero, Zero), Ones)) + */ + NewOp2 = TrCreateLeafNode (PARSEOP_MATCHTYPE_MEQ); + Predicate->Asl.Next = NewOp2; + TrAmlInitLineNumbers (NewOp2, Conditional); + + NewOp = NewOp2; + NewOp2 = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, + (UINT64) ACPI_TO_INTEGER (PredicateValueName)); + NewOp->Asl.Next = NewOp2; + TrAmlInitLineNumbers (NewOp2, Predicate); + + NewOp = NewOp2; + NewOp2 = TrCreateLeafNode (PARSEOP_MATCHTYPE_MTR); + NewOp->Asl.Next = NewOp2; + TrAmlInitLineNumbers (NewOp2, Predicate); + + NewOp = NewOp2; + NewOp2 = TrCreateLeafNode (PARSEOP_ZERO); + NewOp->Asl.Next = NewOp2; + TrAmlInitLineNumbers (NewOp2, Predicate); + + NewOp = NewOp2; + NewOp2 = TrCreateLeafNode (PARSEOP_ZERO); + NewOp->Asl.Next = NewOp2; + TrAmlInitLineNumbers (NewOp2, Predicate); + + NewOp2 = TrCreateLeafNode (PARSEOP_MATCH); + NewOp2->Asl.Child = Predicate; /* PARSEOP_PACKAGE */ + TrAmlInitLineNumbers (NewOp2, Conditional); + TrAmlSetSubtreeParent (Predicate, NewOp2); + + NewOp = NewOp2; + NewOp2 = TrCreateLeafNode (PARSEOP_ONES); + NewOp->Asl.Next = NewOp2; + TrAmlInitLineNumbers (NewOp2, Conditional); + + NewOp2 = TrCreateLeafNode (PARSEOP_LEQUAL); + NewOp2->Asl.Child = NewOp; + NewOp->Asl.Parent = NewOp2; + TrAmlInitLineNumbers (NewOp2, Conditional); + TrAmlSetSubtreeParent (NewOp, NewOp2); + + NewOp = NewOp2; + NewOp2 = TrCreateLeafNode (PARSEOP_LNOT); + NewOp2->Asl.Child = NewOp; + NewOp2->Asl.Parent = Conditional; + NewOp->Asl.Parent = NewOp2; + TrAmlInitLineNumbers (NewOp2, Conditional); + + Conditional->Asl.Child = NewOp2; + NewOp2->Asl.Next = CaseBlock; + } + else + { + /* + * Integer and Buffer case. + * + * Change CaseOp() to: If (LEqual (SwitchValue, CaseValue)) {...} + * Note: SwitchValue is first to allow the CaseValue to be implicitly + * converted to the type of SwitchValue if necessary. + * + * CaseOp->Child is the case value + * CaseOp->Child->Peer is the beginning of the case block + */ + NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESTRING, + (UINT64) ACPI_TO_INTEGER (PredicateValueName)); + NewOp->Asl.Next = Predicate; + TrAmlInitLineNumbers (NewOp, Predicate); + + NewOp2 = TrCreateLeafNode (PARSEOP_LEQUAL); + NewOp2->Asl.Parent = Conditional; + NewOp2->Asl.Child = NewOp; + TrAmlInitLineNumbers (NewOp2, Conditional); + + TrAmlSetSubtreeParent (NewOp, NewOp2); + + Predicate = NewOp2; + Predicate->Asl.Next = CaseBlock; + + TrAmlSetSubtreeParent (Predicate, Conditional); + Conditional->Asl.Child = Predicate; + } + + /* Reinitialize the CASE node to an IF node */ + + TrAmlInitNode (Conditional, PARSEOP_IF); + + /* + * The first CASE(IF) is not nested under an ELSE. + * All other CASEs are children of a parent ELSE. + */ + if (CurrentParentNode == StartNode) + { + Conditional->Asl.Next = NULL; + } + else + { + /* + * The IF is a child of previous IF/ELSE. It + * is therefore without peer. + */ + CurrentParentNode->Asl.Child = Conditional; + Conditional->Asl.Parent = CurrentParentNode; + Conditional->Asl.Next = NULL; + } + } + else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT) + { + if (DefaultOp) + { + /* + * More than one Default + * (Parser does not catch this, must check here) + */ + AslError (ASL_ERROR, ASL_MSG_MULTIPLE_DEFAULT, Next, NULL); + } + else + { + /* Save the DEFAULT node for later, after CASEs */ + + DefaultOp = Next; + } + } + else + { + /* Unknown peer opcode */ + + AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n", + Next->Asl.ParseOpName, Next->Asl.ParseOpcode); + } + } + + /* Add the default case at the end of the if/else construct */ + + if (DefaultOp) + { + /* If no CASE statements, this is an error - see below */ + + if (CaseOp) + { + /* Convert the DEFAULT node to an ELSE */ + + if (!Conditional) + { + return; + } + + TrAmlInitNode (DefaultOp, PARSEOP_ELSE); + DefaultOp->Asl.Parent = Conditional->Asl.Parent; + + /* Link ELSE node as a peer to the previous IF */ + + TrAmlInsertPeer (Conditional, DefaultOp); + } + } + + if (!CaseOp) + { + AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL); + } + + + /* + * Create a Name(_T_x, ...) statement. This statement must appear at the + * method level, in case a loop surrounds the switch statement and could + * cause the name to be created twice (error). + */ + + /* Create the Name node */ + + Predicate = StartNode->Asl.Child; + NewOp = TrCreateLeafNode (PARSEOP_NAME); + TrAmlInitLineNumbers (NewOp, StartNode); + + /* Find the parent method */ + + Next = StartNode; + while ((Next->Asl.ParseOpcode != PARSEOP_METHOD) && + (Next->Asl.ParseOpcode != PARSEOP_DEFINITIONBLOCK)) + { + Next = Next->Asl.Parent; + } + MethodOp = Next; + + NewOp->Asl.CompileFlags |= NODE_COMPILER_EMITTED; + NewOp->Asl.Parent = Next; + + /* Insert name after the method name and arguments */ + + Next = Next->Asl.Child; /* Name */ + Next = Next->Asl.Next; /* NumArgs */ + Next = Next->Asl.Next; /* SerializeRule */ + + /* + * If method is not Serialized, we must make is so, because of the way + * that Switch() must be implemented -- we cannot allow multiple threads + * to execute this method concurrently since we need to create local + * temporary name(s). + */ + if (Next->Asl.ParseOpcode != PARSEOP_SERIALIZERULE_SERIAL) + { + AslError (ASL_REMARK, ASL_MSG_SERIALIZED, MethodOp, "Due to use of Switch operator"); + Next->Asl.ParseOpcode = PARSEOP_SERIALIZERULE_SERIAL; + } + + Next = Next->Asl.Next; /* SyncLevel */ + Next = Next->Asl.Next; /* ReturnType */ + Next = Next->Asl.Next; /* ParameterTypes */ + + TrAmlInsertPeer (Next, NewOp); + TrAmlInitLineNumbers (NewOp, Next); + + /* Create the NameSeg child for the Name node */ + + NewOp2 = TrCreateValuedLeafNode (PARSEOP_NAMESEG, + (UINT64) ACPI_TO_INTEGER (PredicateValueName)); + TrAmlInitLineNumbers (NewOp2, NewOp); + NewOp2->Asl.CompileFlags |= NODE_IS_NAME_DECLARATION; + NewOp->Asl.Child = NewOp2; + + /* Create the initial value for the Name. Btype was already validated above */ + + switch (Btype) + { + case ACPI_BTYPE_INTEGER: + NewOp2->Asl.Next = TrCreateValuedLeafNode (PARSEOP_ZERO, + (UINT64) 0); + TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp); + break; + + case ACPI_BTYPE_STRING: + NewOp2->Asl.Next = TrCreateValuedLeafNode (PARSEOP_STRING_LITERAL, + (UINT64) ACPI_TO_INTEGER ("")); + TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp); + break; + + case ACPI_BTYPE_BUFFER: + (void) TrLinkPeerNode (NewOp2, TrCreateValuedLeafNode (PARSEOP_BUFFER, + (UINT64) 0)); + Next = NewOp2->Asl.Next; + TrAmlInitLineNumbers (Next, NewOp2); + (void) TrLinkChildren (Next, 1, TrCreateValuedLeafNode (PARSEOP_ZERO, + (UINT64) 1)); + TrAmlInitLineNumbers (Next->Asl.Child, Next); + + BufferOp = TrCreateValuedLeafNode (PARSEOP_DEFAULT_ARG, (UINT64) 0); + TrAmlInitLineNumbers (BufferOp, Next->Asl.Child); + (void) TrLinkPeerNode (Next->Asl.Child, BufferOp); + + TrAmlSetSubtreeParent (Next->Asl.Child, Next); + break; + + default: + break; + } + + TrAmlSetSubtreeParent (NewOp2, NewOp); + + /* + * Transform the Switch() into a While(One)-Break node. + * And create a Store() node which will be used to save the + * Switch() value. The store is of the form: Store (Value, _T_x) + * where _T_x is the temp variable. + */ + TrAmlInitNode (StartNode, PARSEOP_WHILE); + NewOp = TrCreateLeafNode (PARSEOP_ONE); + TrAmlInitLineNumbers (NewOp, StartNode); + NewOp->Asl.Next = Predicate->Asl.Next; + NewOp->Asl.Parent = StartNode; + StartNode->Asl.Child = NewOp; + + /* Create a Store() node */ + + StoreOp = TrCreateLeafNode (PARSEOP_STORE); + TrAmlInitLineNumbers (StoreOp, NewOp); + StoreOp->Asl.Parent = StartNode; + TrAmlInsertPeer (NewOp, StoreOp); + + /* Complete the Store subtree */ + + StoreOp->Asl.Child = Predicate; + Predicate->Asl.Parent = StoreOp; + + NewOp = TrCreateValuedLeafNode (PARSEOP_NAMESEG, + (UINT64) ACPI_TO_INTEGER (PredicateValueName)); + TrAmlInitLineNumbers (NewOp, StoreOp); + NewOp->Asl.Parent = StoreOp; + Predicate->Asl.Next = NewOp; + + /* Create a Break() node and insert it into the end of While() */ + + Conditional = StartNode->Asl.Child; + while (Conditional->Asl.Next) + { + Conditional = Conditional->Asl.Next; + } + + BreakOp = TrCreateLeafNode (PARSEOP_BREAK); + TrAmlInitLineNumbers (BreakOp, NewOp); + BreakOp->Asl.Parent = StartNode; + TrAmlInsertPeer (Conditional, BreakOp); +} + + diff --git a/sys/contrib/dev/acpica/compiler/asltree.c b/sys/contrib/dev/acpica/compiler/asltree.c new file mode 100644 index 0000000..8e3e970 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asltree.c @@ -0,0 +1,1202 @@ + +/****************************************************************************** + * + * Module Name: asltree - parse tree management + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/acapps.h> +#include <time.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("asltree") + +/* Local prototypes */ + +static ACPI_PARSE_OBJECT * +TrGetNextNode ( + void); + +static char * +TrGetNodeFlagName ( + UINT32 Flags); + + +/******************************************************************************* + * + * FUNCTION: TrGetNextNode + * + * PARAMETERS: None + * + * RETURN: New parse node. Aborts on allocation failure + * + * DESCRIPTION: Allocate a new parse node for the parse tree. Bypass the local + * dynamic memory manager for performance reasons (This has a + * major impact on the speed of the compiler.) + * + ******************************************************************************/ + +static ACPI_PARSE_OBJECT * +TrGetNextNode ( + void) +{ + + if (Gbl_NodeCacheNext >= Gbl_NodeCacheLast) + { + Gbl_NodeCacheNext = UtLocalCalloc (sizeof (ACPI_PARSE_OBJECT) * + ASL_NODE_CACHE_SIZE); + Gbl_NodeCacheLast = Gbl_NodeCacheNext + ASL_NODE_CACHE_SIZE; + } + + return (Gbl_NodeCacheNext++); +} + + +/******************************************************************************* + * + * FUNCTION: TrAllocateNode + * + * PARAMETERS: ParseOpcode - Opcode to be assigned to the node + * + * RETURN: New parse node. Aborts on allocation failure + * + * DESCRIPTION: Allocate and initialize a new parse node for the parse tree + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrAllocateNode ( + UINT32 ParseOpcode) +{ + ACPI_PARSE_OBJECT *Op; + + + Op = TrGetNextNode (); + + Op->Asl.ParseOpcode = (UINT16) ParseOpcode; + Op->Asl.Filename = Gbl_Files[ASL_FILE_INPUT].Filename; + Op->Asl.LineNumber = Gbl_CurrentLineNumber; + Op->Asl.LogicalLineNumber = Gbl_LogicalLineNumber; + Op->Asl.LogicalByteOffset = Gbl_CurrentLineOffset; + Op->Asl.Column = Gbl_CurrentColumn; + + UtSetParseOpName (Op); + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: TrReleaseNode + * + * PARAMETERS: Op - Op to be released + * + * RETURN: None + * + * DESCRIPTION: "release" a node. In truth, nothing is done since the node + * is part of a larger buffer + * + ******************************************************************************/ + +void +TrReleaseNode ( + ACPI_PARSE_OBJECT *Op) +{ + + return; +} + + +/******************************************************************************* + * + * FUNCTION: TrUpdateNode + * + * PARAMETERS: ParseOpcode - New opcode to be assigned to the node + * Op - An existing parse node + * + * RETURN: The updated node + * + * DESCRIPTION: Change the parse opcode assigned to a node. Usually used to + * change an opcode to DEFAULT_ARG so that the node is ignored + * during the code generation. Also used to set generic integers + * to a specific size (8, 16, 32, or 64 bits) + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrUpdateNode ( + UINT32 ParseOpcode, + ACPI_PARSE_OBJECT *Op) +{ + + if (!Op) + { + return NULL; + } + + DbgPrint (ASL_PARSE_OUTPUT, + "\nUpdateNode: Old - %s, New - %s\n\n", + UtGetOpName (Op->Asl.ParseOpcode), + UtGetOpName (ParseOpcode)); + + /* Assign new opcode and name */ + + if (Op->Asl.ParseOpcode == PARSEOP_ONES) + { + switch (ParseOpcode) + { + case PARSEOP_BYTECONST: + Op->Asl.Value.Integer = 0xFF; + break; + + case PARSEOP_WORDCONST: + Op->Asl.Value.Integer = 0xFFFF; + break; + + case PARSEOP_DWORDCONST: + Op->Asl.Value.Integer = 0xFFFFFFFF; + break; + + default: + /* Don't care about others, don't need to check QWORD */ + break; + } + } + + Op->Asl.ParseOpcode = (UINT16) ParseOpcode; + UtSetParseOpName (Op); + + /* + * For the BYTE, WORD, and DWORD constants, make sure that the integer + * that was passed in will actually fit into the data type + */ + switch (ParseOpcode) + { + case PARSEOP_BYTECONST: + Op = UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX); + break; + + case PARSEOP_WORDCONST: + Op = UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX); + break; + + case PARSEOP_DWORDCONST: + Op = UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX); + break; + + default: + /* Don't care about others, don't need to check QWORD */ + break; + } + + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: TrGetNodeFlagName + * + * PARAMETERS: Flags - Flags word to be decoded + * + * RETURN: Name string. Always returns a valid string pointer. + * + * DESCRIPTION: Decode a flags word + * + ******************************************************************************/ + +static char * +TrGetNodeFlagName ( + UINT32 Flags) +{ + + switch (Flags) + { + case NODE_VISITED: + return ("NODE_VISITED"); + + case NODE_AML_PACKAGE: + return ("NODE_AML_PACKAGE"); + + case NODE_IS_TARGET: + return ("NODE_IS_TARGET"); + + case NODE_IS_RESOURCE_DESC: + return ("NODE_IS_RESOURCE_DESC"); + + case NODE_IS_RESOURCE_FIELD: + return ("NODE_IS_RESOURCE_FIELD"); + + case NODE_HAS_NO_EXIT: + return ("NODE_HAS_NO_EXIT"); + + case NODE_IF_HAS_NO_EXIT: + return ("NODE_IF_HAS_NO_EXIT"); + + case NODE_NAME_INTERNALIZED: + return ("NODE_NAME_INTERNALIZED"); + + case NODE_METHOD_NO_RETVAL: + return ("NODE_METHOD_NO_RETVAL"); + + case NODE_METHOD_SOME_NO_RETVAL: + return ("NODE_METHOD_SOME_NO_RETVAL"); + + case NODE_RESULT_NOT_USED: + return ("NODE_RESULT_NOT_USED"); + + case NODE_METHOD_TYPED: + return ("NODE_METHOD_TYPED"); + + case NODE_COMPILE_TIME_CONST: + return ("NODE_COMPILE_TIME_CONST"); + + case NODE_IS_TERM_ARG: + return ("NODE_IS_TERM_ARG"); + + case NODE_WAS_ONES_OP: + return ("NODE_WAS_ONES_OP"); + + case NODE_IS_NAME_DECLARATION: + return ("NODE_IS_NAME_DECLARATION"); + + default: + return ("Multiple Flags (or unknown flag) set"); + } +} + + +/******************************************************************************* + * + * FUNCTION: TrSetNodeFlags + * + * PARAMETERS: Op - An existing parse node + * Flags - New flags word + * + * RETURN: The updated parser op + * + * DESCRIPTION: Set bits in the node flags word. Will not clear bits, only set + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrSetNodeFlags ( + ACPI_PARSE_OBJECT *Op, + UINT32 Flags) +{ + + DbgPrint (ASL_PARSE_OUTPUT, + "\nSetNodeFlags: Op %p, %8.8X %s\n\n", Op, Flags, + TrGetNodeFlagName (Flags)); + + if (!Op) + { + return NULL; + } + + Op->Asl.CompileFlags |= Flags; + + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: TrSetEndLineNumber + * + * PARAMETERS: Op - An existing parse node + * + * RETURN: None. + * + * DESCRIPTION: Set the ending line numbers (file line and logical line) of a + * parse node to the current line numbers. + * + ******************************************************************************/ + +void +TrSetEndLineNumber ( + ACPI_PARSE_OBJECT *Op) +{ + + /* If the end line # is already set, just return */ + + if (Op->Asl.EndLine) + { + return; + } + + Op->Asl.EndLine = Gbl_CurrentLineNumber; + Op->Asl.EndLogicalLine = Gbl_LogicalLineNumber; +} + + +/******************************************************************************* + * + * FUNCTION: TrCreateLeafNode + * + * PARAMETERS: ParseOpcode - New opcode to be assigned to the node + * + * RETURN: Pointer to the new node. Aborts on allocation failure + * + * DESCRIPTION: Create a simple leaf node (no children or peers, and no value + * assigned to the node) + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrCreateLeafNode ( + UINT32 ParseOpcode) +{ + ACPI_PARSE_OBJECT *Op; + + + Op = TrAllocateNode (ParseOpcode); + + DbgPrint (ASL_PARSE_OUTPUT, + "\nCreateLeafNode Ln/Col %u/%u NewNode %p Op %s\n\n", + Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode)); + + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: TrCreateConstantLeafNode + * + * PARAMETERS: ParseOpcode - The constant opcode + * + * RETURN: Pointer to the new node. Aborts on allocation failure + * + * DESCRIPTION: Create a leaf node (no children or peers) for one of the + * special constants - __LINE__, __FILE__, and __DATE__. + * + * Note: An implemenation of __FUNC__ cannot happen here because we don't + * have a full parse tree at this time and cannot find the parent control + * method. If it is ever needed, __FUNC__ must be implemented later, after + * the parse tree has been fully constructed. + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrCreateConstantLeafNode ( + UINT32 ParseOpcode) +{ + ACPI_PARSE_OBJECT *Op = NULL; + time_t CurrentTime; + char *StaticTimeString; + char *TimeString; + char *Path; + char *Filename; + + + switch (ParseOpcode) + { + case PARSEOP___LINE__: + Op = TrAllocateNode (PARSEOP_INTEGER); + Op->Asl.Value.Integer = Op->Asl.LineNumber; + break; + + case PARSEOP___PATH__: + Op = TrAllocateNode (PARSEOP_STRING_LITERAL); + + /* Op.Asl.Filename contains the full pathname to the file */ + + Op->Asl.Value.String = Op->Asl.Filename; + break; + + case PARSEOP___FILE__: + Op = TrAllocateNode (PARSEOP_STRING_LITERAL); + + /* Get the simple filename from the full path */ + + FlSplitInputPathname (Op->Asl.Filename, &Path, &Filename); + ACPI_FREE (Path); + Op->Asl.Value.String = Filename; + break; + + case PARSEOP___DATE__: + Op = TrAllocateNode (PARSEOP_STRING_LITERAL); + + /* Get a copy of the current time */ + + CurrentTime = time (NULL); + StaticTimeString = ctime (&CurrentTime); + TimeString = UtLocalCalloc (strlen (StaticTimeString) + 1); + strcpy (TimeString, StaticTimeString); + + TimeString[strlen(TimeString) -1] = 0; /* Remove trailing newline */ + Op->Asl.Value.String = TimeString; + break; + + default: /* This would be an internal error */ + return (NULL); + } + + DbgPrint (ASL_PARSE_OUTPUT, + "\nCreateConstantLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ", + Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName (ParseOpcode), + ACPI_FORMAT_UINT64 (Op->Asl.Value.Integer)); + return (Op); +} + + +/******************************************************************************* + * + * FUNCTION: TrCreateValuedLeafNode + * + * PARAMETERS: ParseOpcode - New opcode to be assigned to the node + * Value - Value to be assigned to the node + * + * RETURN: Pointer to the new node. Aborts on allocation failure + * + * DESCRIPTION: Create a leaf node (no children or peers) with a value + * assigned to it + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrCreateValuedLeafNode ( + UINT32 ParseOpcode, + UINT64 Value) +{ + ACPI_PARSE_OBJECT *Op; + + + Op = TrAllocateNode (ParseOpcode); + + DbgPrint (ASL_PARSE_OUTPUT, + "\nCreateValuedLeafNode Ln/Col %u/%u NewNode %p Op %s Value %8.8X%8.8X ", + Op->Asl.LineNumber, Op->Asl.Column, Op, UtGetOpName(ParseOpcode), + ACPI_FORMAT_UINT64 (Value)); + Op->Asl.Value.Integer = Value; + + switch (ParseOpcode) + { + case PARSEOP_STRING_LITERAL: + DbgPrint (ASL_PARSE_OUTPUT, "STRING->%s", Value); + break; + + case PARSEOP_NAMESEG: + DbgPrint (ASL_PARSE_OUTPUT, "NAMESEG->%s", Value); + break; + + case PARSEOP_NAMESTRING: + DbgPrint (ASL_PARSE_OUTPUT, "NAMESTRING->%s", Value); + break; + + case PARSEOP_EISAID: + DbgPrint (ASL_PARSE_OUTPUT, "EISAID->%s", Value); + break; + + case PARSEOP_METHOD: + DbgPrint (ASL_PARSE_OUTPUT, "METHOD"); + break; + + case PARSEOP_INTEGER: + DbgPrint (ASL_PARSE_OUTPUT, "INTEGER"); + break; + + default: + break; + } + + DbgPrint (ASL_PARSE_OUTPUT, "\n\n"); + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: TrCreateNode + * + * PARAMETERS: ParseOpcode - Opcode to be assigned to the node + * NumChildren - Number of children to follow + * ... - A list of child nodes to link to the new + * node. NumChildren long. + * + * RETURN: Pointer to the new node. Aborts on allocation failure + * + * DESCRIPTION: Create a new parse node and link together a list of child + * nodes underneath the new node. + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrCreateNode ( + UINT32 ParseOpcode, + UINT32 NumChildren, + ...) +{ + ACPI_PARSE_OBJECT *Op; + ACPI_PARSE_OBJECT *Child; + ACPI_PARSE_OBJECT *PrevChild; + va_list ap; + UINT32 i; + BOOLEAN FirstChild; + + + va_start (ap, NumChildren); + + /* Allocate one new node */ + + Op = TrAllocateNode (ParseOpcode); + + DbgPrint (ASL_PARSE_OUTPUT, + "\nCreateNode Ln/Col %u/%u NewParent %p Child %u Op %s ", + Op->Asl.LineNumber, Op->Asl.Column, Op, NumChildren, UtGetOpName(ParseOpcode)); + + /* Some extra debug output based on the parse opcode */ + + switch (ParseOpcode) + { + case PARSEOP_DEFINITIONBLOCK: + RootNode = Op; + DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->"); + break; + + case PARSEOP_OPERATIONREGION: + DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->"); + break; + + case PARSEOP_OR: + DbgPrint (ASL_PARSE_OUTPUT, "OR->"); + break; + + default: + /* Nothing to do for other opcodes */ + break; + } + + /* Link the new node to its children */ + + PrevChild = NULL; + FirstChild = TRUE; + for (i = 0; i < NumChildren; i++) + { + /* Get the next child */ + + Child = va_arg (ap, ACPI_PARSE_OBJECT *); + DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child); + + /* + * If child is NULL, this means that an optional argument + * was omitted. We must create a placeholder with a special + * opcode (DEFAULT_ARG) so that the code generator will know + * that it must emit the correct default for this argument + */ + if (!Child) + { + Child = TrAllocateNode (PARSEOP_DEFAULT_ARG); + } + + /* Link first child to parent */ + + if (FirstChild) + { + FirstChild = FALSE; + Op->Asl.Child = Child; + } + + /* Point all children to parent */ + + Child->Asl.Parent = Op; + + /* Link children in a peer list */ + + if (PrevChild) + { + PrevChild->Asl.Next = Child; + }; + + /* + * This child might be a list, point all nodes in the list + * to the same parent + */ + while (Child->Asl.Next) + { + Child = Child->Asl.Next; + Child->Asl.Parent = Op; + } + + PrevChild = Child; + } + va_end(ap); + + DbgPrint (ASL_PARSE_OUTPUT, "\n\n"); + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: TrLinkChildren + * + * PARAMETERS: Op - An existing parse node + * NumChildren - Number of children to follow + * ... - A list of child nodes to link to the new + * node. NumChildren long. + * + * RETURN: The updated (linked) node + * + * DESCRIPTION: Link a group of nodes to an existing parse node + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrLinkChildren ( + ACPI_PARSE_OBJECT *Op, + UINT32 NumChildren, + ...) +{ + ACPI_PARSE_OBJECT *Child; + ACPI_PARSE_OBJECT *PrevChild; + va_list ap; + UINT32 i; + BOOLEAN FirstChild; + + + va_start (ap, NumChildren); + + + TrSetEndLineNumber (Op); + + DbgPrint (ASL_PARSE_OUTPUT, + "\nLinkChildren Line [%u to %u] NewParent %p Child %u Op %s ", + Op->Asl.LineNumber, Op->Asl.EndLine, + Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode)); + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_DEFINITIONBLOCK: + RootNode = Op; + DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->"); + break; + + case PARSEOP_OPERATIONREGION: + DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->"); + break; + + case PARSEOP_OR: + DbgPrint (ASL_PARSE_OUTPUT, "OR->"); + break; + + default: + /* Nothing to do for other opcodes */ + break; + } + + /* Link the new node to it's children */ + + PrevChild = NULL; + FirstChild = TRUE; + for (i = 0; i < NumChildren; i++) + { + Child = va_arg (ap, ACPI_PARSE_OBJECT *); + + if ((Child == PrevChild) && (Child != NULL)) + { + AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child, + "Child node list invalid"); + return Op; + } + + DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child); + + /* + * If child is NULL, this means that an optional argument + * was omitted. We must create a placeholder with a special + * opcode (DEFAULT_ARG) so that the code generator will know + * that it must emit the correct default for this argument + */ + if (!Child) + { + Child = TrAllocateNode (PARSEOP_DEFAULT_ARG); + } + + /* Link first child to parent */ + + if (FirstChild) + { + FirstChild = FALSE; + Op->Asl.Child = Child; + } + + /* Point all children to parent */ + + Child->Asl.Parent = Op; + + /* Link children in a peer list */ + + if (PrevChild) + { + PrevChild->Asl.Next = Child; + }; + + /* + * This child might be a list, point all nodes in the list + * to the same parent + */ + while (Child->Asl.Next) + { + Child = Child->Asl.Next; + Child->Asl.Parent = Op; + } + PrevChild = Child; + } + va_end(ap); + + DbgPrint (ASL_PARSE_OUTPUT, "\n\n"); + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: TrLinkPeerNode + * + * PARAMETERS: Op1 - First peer + * Op2 - Second peer + * + * RETURN: Op1 or the non-null node. + * + * DESCRIPTION: Link two nodes as peers. Handles cases where one peer is null. + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrLinkPeerNode ( + ACPI_PARSE_OBJECT *Op1, + ACPI_PARSE_OBJECT *Op2) +{ + ACPI_PARSE_OBJECT *Next; + + + DbgPrint (ASL_PARSE_OUTPUT, + "\nLinkPeerNode: 1=%p (%s), 2=%p (%s)\n\n", + Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL, + Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL); + + + if ((!Op1) && (!Op2)) + { + DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null nodes!\n"); + return Op1; + } + + /* If one of the nodes is null, just return the non-null node */ + + if (!Op2) + { + return Op1; + } + + if (!Op1) + { + return Op2; + } + + if (Op1 == Op2) + { + DbgPrint (ASL_DEBUG_OUTPUT, + "\n\n************* Internal error, linking node to itself %p\n\n\n", + Op1); + AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1, + "Linking node to itself"); + return Op1; + } + + Op1->Asl.Parent = Op2->Asl.Parent; + + /* + * Op 1 may already have a peer list (such as an IF/ELSE pair), + * so we must walk to the end of the list and attach the new + * peer at the end + */ + Next = Op1; + while (Next->Asl.Next) + { + Next = Next->Asl.Next; + } + + Next->Asl.Next = Op2; + return Op1; +} + + +/******************************************************************************* + * + * FUNCTION: TrLinkPeerNodes + * + * PARAMETERS: NumPeers - The number of nodes in the list to follow + * ... - A list of nodes to link together as peers + * + * RETURN: The first node in the list (head of the peer list) + * + * DESCRIPTION: Link together an arbitrary number of peer nodes. + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrLinkPeerNodes ( + UINT32 NumPeers, + ...) +{ + ACPI_PARSE_OBJECT *This; + ACPI_PARSE_OBJECT *Next; + va_list ap; + UINT32 i; + ACPI_PARSE_OBJECT *Start; + + + DbgPrint (ASL_PARSE_OUTPUT, + "\nLinkPeerNodes: (%u) ", NumPeers); + + va_start (ap, NumPeers); + This = va_arg (ap, ACPI_PARSE_OBJECT *); + Start = This; + + /* + * Link all peers + */ + for (i = 0; i < (NumPeers -1); i++) + { + DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This); + + while (This->Asl.Next) + { + This = This->Asl.Next; + } + + /* Get another peer node */ + + Next = va_arg (ap, ACPI_PARSE_OBJECT *); + if (!Next) + { + Next = TrAllocateNode (PARSEOP_DEFAULT_ARG); + } + + /* link new node to the current node */ + + This->Asl.Next = Next; + This = Next; + } + va_end (ap); + + DbgPrint (ASL_PARSE_OUTPUT,"\n\n"); + return (Start); +} + + +/******************************************************************************* + * + * FUNCTION: TrLinkChildNode + * + * PARAMETERS: Op1 - Parent node + * Op2 - Op to become a child + * + * RETURN: The parent node + * + * DESCRIPTION: Link two nodes together as a parent and child + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +TrLinkChildNode ( + ACPI_PARSE_OBJECT *Op1, + ACPI_PARSE_OBJECT *Op2) +{ + ACPI_PARSE_OBJECT *Next; + + + DbgPrint (ASL_PARSE_OUTPUT, + "\nLinkChildNode: Parent=%p (%s), Child=%p (%s)\n\n", + Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL, + Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL); + + if (!Op1 || !Op2) + { + return Op1; + } + + Op1->Asl.Child = Op2; + + /* Set the child and all peers of the child to point to the parent */ + + Next = Op2; + while (Next) + { + Next->Asl.Parent = Op1; + Next = Next->Asl.Next; + } + + return Op1; +} + + +/******************************************************************************* + * + * FUNCTION: TrWalkParseTree + * + * PARAMETERS: Visitation - Type of walk + * DescendingCallback - Called during tree descent + * AscendingCallback - Called during tree ascent + * Context - To be passed to the callbacks + * + * RETURN: Status from callback(s) + * + * DESCRIPTION: Walk the entire parse tree. + * + ******************************************************************************/ + +ACPI_STATUS +TrWalkParseTree ( + ACPI_PARSE_OBJECT *Op, + UINT32 Visitation, + ASL_WALK_CALLBACK DescendingCallback, + ASL_WALK_CALLBACK AscendingCallback, + void *Context) +{ + UINT32 Level; + BOOLEAN NodePreviouslyVisited; + ACPI_PARSE_OBJECT *StartOp = Op; + ACPI_STATUS Status; + + + if (!RootNode) + { + return (AE_OK); + } + + Level = 0; + NodePreviouslyVisited = FALSE; + + switch (Visitation) + { + case ASL_WALK_VISIT_DOWNWARD: + + while (Op) + { + if (!NodePreviouslyVisited) + { + /* Let the callback process the node. */ + + Status = DescendingCallback (Op, Level, Context); + if (ACPI_SUCCESS (Status)) + { + /* Visit children first, once */ + + if (Op->Asl.Child) + { + Level++; + Op = Op->Asl.Child; + continue; + } + } + else if (Status != AE_CTRL_DEPTH) + { + /* Exit immediately on any error */ + + return (Status); + } + } + + /* Terminate walk at start op */ + + if (Op == StartOp) + { + break; + } + + /* No more children, visit peers */ + + if (Op->Asl.Next) + { + Op = Op->Asl.Next; + NodePreviouslyVisited = FALSE; + } + else + { + /* No children or peers, re-visit parent */ + + if (Level != 0 ) + { + Level--; + } + Op = Op->Asl.Parent; + NodePreviouslyVisited = TRUE; + } + } + break; + + + case ASL_WALK_VISIT_UPWARD: + + while (Op) + { + /* Visit leaf node (no children) or parent node on return trip */ + + if ((!Op->Asl.Child) || + (NodePreviouslyVisited)) + { + /* Let the callback process the node. */ + + Status = AscendingCallback (Op, Level, Context); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + } + else + { + /* Visit children first, once */ + + Level++; + Op = Op->Asl.Child; + continue; + } + + /* Terminate walk at start op */ + + if (Op == StartOp) + { + break; + } + + /* No more children, visit peers */ + + if (Op->Asl.Next) + { + Op = Op->Asl.Next; + NodePreviouslyVisited = FALSE; + } + else + { + /* No children or peers, re-visit parent */ + + if (Level != 0 ) + { + Level--; + } + Op = Op->Asl.Parent; + NodePreviouslyVisited = TRUE; + } + } + break; + + + case ASL_WALK_VISIT_TWICE: + + while (Op) + { + if (NodePreviouslyVisited) + { + Status = AscendingCallback (Op, Level, Context); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + } + else + { + /* Let the callback process the node. */ + + Status = DescendingCallback (Op, Level, Context); + if (ACPI_SUCCESS (Status)) + { + /* Visit children first, once */ + + if (Op->Asl.Child) + { + Level++; + Op = Op->Asl.Child; + continue; + } + } + else if (Status != AE_CTRL_DEPTH) + { + /* Exit immediately on any error */ + + return (Status); + } + } + + /* Terminate walk at start op */ + + if (Op == StartOp) + { + break; + } + + /* No more children, visit peers */ + + if (Op->Asl.Next) + { + Op = Op->Asl.Next; + NodePreviouslyVisited = FALSE; + } + else + { + /* No children or peers, re-visit parent */ + + if (Level != 0 ) + { + Level--; + } + Op = Op->Asl.Parent; + NodePreviouslyVisited = TRUE; + } + } + break; + + default: + /* No other types supported */ + break; + } + + /* If we get here, the walk completed with no errors */ + + return (AE_OK); +} + + diff --git a/sys/contrib/dev/acpica/compiler/asltypes.h b/sys/contrib/dev/acpica/compiler/asltypes.h new file mode 100644 index 0000000..7e3bd0a --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asltypes.h @@ -0,0 +1,238 @@ + +/****************************************************************************** + * + * Module Name: asltypes.h - compiler data types and struct definitions + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#ifndef __ASLTYPES_H +#define __ASLTYPES_H + + +/******************************************************************************* + * + * Structure definitions + * + ******************************************************************************/ + + +/* Op flags for the ACPI_PARSE_OBJECT */ + +#define NODE_VISITED 0x00000001 +#define NODE_AML_PACKAGE 0x00000002 +#define NODE_IS_TARGET 0x00000004 +#define NODE_IS_RESOURCE_DESC 0x00000008 +#define NODE_IS_RESOURCE_FIELD 0x00000010 +#define NODE_HAS_NO_EXIT 0x00000020 +#define NODE_IF_HAS_NO_EXIT 0x00000040 +#define NODE_NAME_INTERNALIZED 0x00000080 +#define NODE_METHOD_NO_RETVAL 0x00000100 +#define NODE_METHOD_SOME_NO_RETVAL 0x00000200 +#define NODE_RESULT_NOT_USED 0x00000400 +#define NODE_METHOD_TYPED 0x00000800 +#define NODE_UNUSED_FLAG 0x00001000 +#define NODE_COMPILE_TIME_CONST 0x00002000 +#define NODE_IS_TERM_ARG 0x00004000 +#define NODE_WAS_ONES_OP 0x00008000 +#define NODE_IS_NAME_DECLARATION 0x00010000 +#define NODE_COMPILER_EMITTED 0x00020000 +#define NODE_IS_DUPLICATE 0x00040000 +#define NODE_IS_RESOURCE_DATA 0x00080000 +#define NODE_IS_NULL_RETURN 0x00100000 + +/* Keeps information about individual control methods */ + +typedef struct asl_method_info +{ + UINT8 NumArguments; + UINT8 LocalInitialized[ACPI_METHOD_NUM_LOCALS]; + UINT8 ArgInitialized[ACPI_METHOD_NUM_ARGS]; + UINT32 ValidArgTypes[ACPI_METHOD_NUM_ARGS]; + UINT32 ValidReturnTypes; + UINT32 NumReturnNoValue; + UINT32 NumReturnWithValue; + ACPI_PARSE_OBJECT *Op; + struct asl_method_info *Next; + UINT8 HasBeenTyped; + +} ASL_METHOD_INFO; + + +/* Parse tree walk info for control method analysis */ + +typedef struct asl_analysis_walk_info +{ + ASL_METHOD_INFO *MethodStack; + +} ASL_ANALYSIS_WALK_INFO; + + +/* An entry in the ParseOpcode to AmlOpcode mapping table */ + +typedef struct asl_mapping_entry +{ + UINT32 Value; + UINT32 AcpiBtype; /* Object type or return type */ + UINT16 AmlOpcode; + UINT8 Flags; + +} ASL_MAPPING_ENTRY; + + +/* Parse tree walk info structure */ + +typedef struct asl_walk_info +{ + ACPI_PARSE_OBJECT **NodePtr; + UINT32 *LevelPtr; + +} ASL_WALK_INFO; + + +/* File info */ + +typedef struct asl_file_info +{ + FILE *Handle; + char *Filename; + +} ASL_FILE_INFO; + +typedef struct asl_file_status +{ + UINT32 Line; + UINT32 Offset; + +} ASL_FILE_STATUS; + + +/* + * File types. Note: Any changes to this table must also be reflected + * in the AslFileTypeNames array. + */ +typedef enum +{ + ASL_FILE_STDOUT = 0, + ASL_FILE_STDERR, + ASL_FILE_INPUT, /* Don't move these first 3 file types */ + ASL_FILE_AML_OUTPUT, + ASL_FILE_SOURCE_OUTPUT, + ASL_FILE_PREPROCESSOR, + ASL_FILE_LISTING_OUTPUT, + ASL_FILE_HEX_OUTPUT, + ASL_FILE_NAMESPACE_OUTPUT, + ASL_FILE_DEBUG_OUTPUT, + ASL_FILE_ASM_SOURCE_OUTPUT, + ASL_FILE_C_SOURCE_OUTPUT, + ASL_FILE_ASM_INCLUDE_OUTPUT, + ASL_FILE_C_INCLUDE_OUTPUT + +} ASL_FILE_TYPES; + + +#define ASL_MAX_FILE_TYPE 13 +#define ASL_NUM_FILES (ASL_MAX_FILE_TYPE + 1) + + +typedef struct asl_include_dir +{ + char *Dir; + struct asl_include_dir *Next; + +} ASL_INCLUDE_DIR; + + +/* An entry in the exception list, one for each error/warning */ + +typedef struct asl_error_msg +{ + UINT32 LineNumber; + UINT32 LogicalLineNumber; + UINT32 LogicalByteOffset; + UINT32 Column; + char *Message; + struct asl_error_msg *Next; + char *Filename; + char *SourceLine; + UINT32 FilenameLength; + UINT8 MessageId; + UINT8 Level; + +} ASL_ERROR_MSG; + + +/* An entry in the listing file stack (for include files) */ + +typedef struct asl_listing_node +{ + char *Filename; + UINT32 LineNumber; + struct asl_listing_node *Next; + +} ASL_LISTING_NODE; + + +/* Callback interface for a parse tree walk */ + +/* + * TBD - another copy of this is in adisasm.h, fix + */ +#ifndef ASL_WALK_CALLBACK_DEFINED +typedef +ACPI_STATUS (*ASL_WALK_CALLBACK) ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context); +#define ASL_WALK_CALLBACK_DEFINED +#endif + + +typedef struct asl_event_info +{ + UINT64 StartTime; + UINT64 EndTime; + char *EventName; + BOOLEAN Valid; + +} ASL_EVENT_INFO; + + +#endif /* __ASLTYPES_H */ diff --git a/sys/contrib/dev/acpica/compiler/aslutils.c b/sys/contrib/dev/acpica/compiler/aslutils.c new file mode 100644 index 0000000..0fabba1 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslutils.c @@ -0,0 +1,1076 @@ + +/****************************************************************************** + * + * Module Name: aslutils -- compiler utilities + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/acdisasm.h> +#include <contrib/dev/acpica/include/acnamesp.h> +#include <contrib/dev/acpica/include/amlcode.h> +#include <contrib/dev/acpica/include/acapps.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslutils") + + +char AslHexLookup[] = +{ + '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' +}; + +/* Table below must match ASL_FILE_TYPES in asltypes.h */ + +static const char *AslFileTypeNames [ASL_NUM_FILES] = +{ + "stdout: ", + "stderr: ", + "Table Input: ", + "Binary Output:", + "Source Output:", + "Preprocessor: ", + "Listing File: ", + "Hex Dump: ", + "Namespace: ", + "Debug File: ", + "ASM Source: ", + "C Source: ", + "ASM Include: ", + "C Include: " +}; + + +/* Local prototypes */ + +static void +UtPadNameWithUnderscores ( + char *NameSeg, + char *PaddedNameSeg); + +static void +UtAttachNameseg ( + ACPI_PARSE_OBJECT *Op, + char *Name); + + +/******************************************************************************* + * + * FUNCTION: UtDisplaySupportedTables + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Print all supported ACPI table names. + * + ******************************************************************************/ + +void +UtDisplaySupportedTables ( + void) +{ + ACPI_DMTABLE_DATA *TableData; + UINT32 i = 6; + + + printf ("\nACPI tables supported by iASL subsystems in " + "version %8.8X:\n" + " ASL and Data Table compilers\n" + " AML and Data Table disassemblers\n" + " ACPI table template generator\n\n", ACPI_CA_VERSION); + + /* Special tables */ + + printf ("%8u) %s %s\n", 1, ACPI_SIG_DSDT, "Differentiated System Description Table"); + printf ("%8u) %s %s\n", 2, ACPI_SIG_SSDT, "Secondary System Description Table"); + printf ("%8u) %s %s\n", 3, ACPI_SIG_FADT, "Fixed ACPI Description Table (FADT)"); + printf ("%8u) %s %s\n", 4, ACPI_SIG_FACS, "Firmware ACPI Control Structure"); + printf ("%8u) %s %s\n", 5, ACPI_RSDP_NAME, "Root System Description Pointer"); + + /* All data tables with common table header */ + + for (TableData = AcpiDmTableData; TableData->Signature; TableData++) + { + printf ("%8u) %s %s\n", i, TableData->Signature, TableData->Name); + i++; + } +} + + +/******************************************************************************* + * + * FUNCTION: AcpiPsDisplayConstantOpcodes + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Print AML opcodes that can be used in constant expressions. + * + ******************************************************************************/ + +void +UtDisplayConstantOpcodes ( + void) +{ + UINT32 i; + + + printf ("Constant expression opcode information\n\n"); + + for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++) + { + if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT) + { + printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name); + } + } +} + + +/******************************************************************************* + * + * FUNCTION: UtLocalCalloc + * + * PARAMETERS: Size - Bytes to be allocated + * + * RETURN: Pointer to the allocated memory. Guaranteed to be valid. + * + * DESCRIPTION: Allocate zero-initialized memory. Aborts the compile on an + * allocation failure, on the assumption that nothing more can be + * accomplished. + * + ******************************************************************************/ + +void * +UtLocalCalloc ( + UINT32 Size) +{ + void *Allocated; + + + Allocated = ACPI_ALLOCATE_ZEROED (Size); + if (!Allocated) + { + AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION, + Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, + Gbl_InputByteCount, Gbl_CurrentColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, NULL); + + CmCleanupAndExit (); + exit (1); + } + + TotalAllocations++; + TotalAllocated += Size; + return (Allocated); +} + + +/******************************************************************************* + * + * FUNCTION: UtBeginEvent + * + * PARAMETERS: Name - Ascii name of this event + * + * RETURN: Event - Event number (integer index) + * + * DESCRIPTION: Saves the current time with this event + * + ******************************************************************************/ + +UINT8 +UtBeginEvent ( + char *Name) +{ + + if (AslGbl_NextEvent >= ASL_NUM_EVENTS) + { + AcpiOsPrintf ("Ran out of compiler event structs!\n"); + return (AslGbl_NextEvent); + } + + /* Init event with current (start) time */ + + AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer (); + AslGbl_Events[AslGbl_NextEvent].EventName = Name; + AslGbl_Events[AslGbl_NextEvent].Valid = TRUE; + + return (AslGbl_NextEvent++); +} + + +/******************************************************************************* + * + * FUNCTION: UtEndEvent + * + * PARAMETERS: Event - Event number (integer index) + * + * RETURN: None + * + * DESCRIPTION: Saves the current time (end time) with this event + * + ******************************************************************************/ + +void +UtEndEvent ( + UINT8 Event) +{ + + if (Event >= ASL_NUM_EVENTS) + { + return; + } + + /* Insert end time for event */ + + AslGbl_Events[Event].EndTime = AcpiOsGetTimer (); +} + + +/******************************************************************************* + * + * FUNCTION: UtHexCharToValue + * + * PARAMETERS: HexChar - Hex character in Ascii + * + * RETURN: The binary value of the hex character + * + * DESCRIPTION: Perform ascii-to-hex translation + * + ******************************************************************************/ + +UINT8 +UtHexCharToValue ( + int HexChar) +{ + + if (HexChar <= 0x39) + { + return ((UINT8) (HexChar - 0x30)); + } + + if (HexChar <= 0x46) + { + return ((UINT8) (HexChar - 0x37)); + } + + return ((UINT8) (HexChar - 0x57)); +} + + +/******************************************************************************* + * + * FUNCTION: UtConvertByteToHex + * + * PARAMETERS: RawByte - Binary data + * Buffer - Pointer to where the hex bytes will be stored + * + * RETURN: Ascii hex byte is stored in Buffer. + * + * DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed + * with "0x" + * + ******************************************************************************/ + +void +UtConvertByteToHex ( + UINT8 RawByte, + UINT8 *Buffer) +{ + + Buffer[0] = '0'; + Buffer[1] = 'x'; + + Buffer[2] = (UINT8) AslHexLookup[(RawByte >> 4) & 0xF]; + Buffer[3] = (UINT8) AslHexLookup[RawByte & 0xF]; +} + + +/******************************************************************************* + * + * FUNCTION: UtConvertByteToAsmHex + * + * PARAMETERS: RawByte - Binary data + * Buffer - Pointer to where the hex bytes will be stored + * + * RETURN: Ascii hex byte is stored in Buffer. + * + * DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed + * with "0x" + * + ******************************************************************************/ + +void +UtConvertByteToAsmHex ( + UINT8 RawByte, + UINT8 *Buffer) +{ + + Buffer[0] = '0'; + Buffer[1] = (UINT8) AslHexLookup[(RawByte >> 4) & 0xF]; + Buffer[2] = (UINT8) AslHexLookup[RawByte & 0xF]; + Buffer[3] = 'h'; +} + + +/******************************************************************************* + * + * FUNCTION: DbgPrint + * + * PARAMETERS: Type - Type of output + * Fmt - Printf format string + * ... - variable printf list + * + * RETURN: None + * + * DESCRIPTION: Conditional print statement. Prints to stderr only if the + * debug flag is set. + * + ******************************************************************************/ + +void +DbgPrint ( + UINT32 Type, + char *Fmt, + ...) +{ + va_list Args; + + + va_start (Args, Fmt); + + if (!Gbl_DebugFlag) + { + return; + } + + if ((Type == ASL_PARSE_OUTPUT) && + (!(AslCompilerdebug))) + { + return; + } + + (void) vfprintf (stderr, Fmt, Args); + va_end (Args); + return; +} + + +/******************************************************************************* + * + * FUNCTION: UtPrintFormattedName + * + * PARAMETERS: ParseOpcode - Parser keyword ID + * Level - Indentation level + * + * RETURN: None + * + * DESCRIPTION: Print the ascii name of the parse opcode. + * + ******************************************************************************/ + +#define TEXT_OFFSET 10 + +void +UtPrintFormattedName ( + UINT16 ParseOpcode, + UINT32 Level) +{ + + if (Level) + { + DbgPrint (ASL_TREE_OUTPUT, + "%*s", (3 * Level), " "); + } + DbgPrint (ASL_TREE_OUTPUT, + " %-20.20s", UtGetOpName (ParseOpcode)); + + if (Level < TEXT_OFFSET) + { + DbgPrint (ASL_TREE_OUTPUT, + "%*s", (TEXT_OFFSET - Level) * 3, " "); + } +} + + +/******************************************************************************* + * + * FUNCTION: UtSetParseOpName + * + * PARAMETERS: Op + * + * RETURN: None + * + * DESCRIPTION: Insert the ascii name of the parse opcode + * + ******************************************************************************/ + +void +UtSetParseOpName ( + ACPI_PARSE_OBJECT *Op) +{ + + strncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode), + ACPI_MAX_PARSEOP_NAME); +} + + +/******************************************************************************* + * + * FUNCTION: UtDisplaySummary + * + * PARAMETERS: FileID - ID of outpout file + * + * RETURN: None + * + * DESCRIPTION: Display compilation statistics + * + ******************************************************************************/ + +void +UtDisplaySummary ( + UINT32 FileId) +{ + UINT32 i; + + + if (FileId != ASL_FILE_STDOUT) + { + /* Compiler name and version number */ + + FlPrintFile (FileId, "%s version %X%s\n\n", + ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, ACPI_WIDTH); + } + + /* Summary of main input and output files */ + + if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) + { + FlPrintFile (FileId, + "%-14s %s - %u lines, %u bytes, %u fields\n", + "Table Input:", + Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, + Gbl_InputByteCount, Gbl_InputFieldCount); + + if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) + { + FlPrintFile (FileId, + "%-14s %s - %u bytes\n", + "Binary Output:", + Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength); + } + } + else + { + FlPrintFile (FileId, + "%-14s %s - %u lines, %u bytes, %u keywords\n", + "ASL Input:", + Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, + Gbl_InputByteCount, TotalKeywords); + + /* AML summary */ + + if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) + { + FlPrintFile (FileId, + "%-14s %s - %u bytes, %u named objects, %u executable opcodes\n", + "AML Output:", + Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength, + TotalNamedObjects, TotalExecutableOpcodes); + } + } + + /* Display summary of any optional files */ + + for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++) + { + if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle) + { + continue; + } + + /* .SRC is a temp file unless specifically requested */ + + if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag)) + { + continue; + } + + /* .I is a temp file unless specifically requested */ + + if ((i == ASL_FILE_PREPROCESSOR) && (!Gbl_PreprocessorOutputFlag)) + { + continue; + } + + FlPrintFile (FileId, "%14s %s - %u bytes\n", + AslFileTypeNames [i], + Gbl_Files[i].Filename, FlGetFileSize (i)); + } + + /* Error summary */ + + FlPrintFile (FileId, + "\nCompilation complete. %u Errors, %u Warnings, %u Remarks", + Gbl_ExceptionCount[ASL_ERROR], + Gbl_ExceptionCount[ASL_WARNING] + + Gbl_ExceptionCount[ASL_WARNING2] + + Gbl_ExceptionCount[ASL_WARNING3], + Gbl_ExceptionCount[ASL_REMARK]); + + if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA) + { + FlPrintFile (FileId, + ", %u Optimizations", Gbl_ExceptionCount[ASL_OPTIMIZATION]); + } + + FlPrintFile (FileId, "\n"); +} + + +/******************************************************************************* + * + * FUNCTION: UtDisplaySummary + * + * PARAMETERS: Op - Integer parse node + * LowValue - Smallest allowed value + * HighValue - Largest allowed value + * + * RETURN: Op if OK, otherwise NULL + * + * DESCRIPTION: Check integer for an allowable range + * + ******************************************************************************/ + +ACPI_PARSE_OBJECT * +UtCheckIntegerRange ( + ACPI_PARSE_OBJECT *Op, + UINT32 LowValue, + UINT32 HighValue) +{ + char *ParseError = NULL; + char Buffer[64]; + + + if (!Op) + { + return NULL; + } + + if (Op->Asl.Value.Integer < LowValue) + { + ParseError = "Value below valid range"; + Op->Asl.Value.Integer = LowValue; + } + + if (Op->Asl.Value.Integer > HighValue) + { + ParseError = "Value above valid range"; + Op->Asl.Value.Integer = HighValue; + } + + if (ParseError) + { + sprintf (Buffer, "%s 0x%X-0x%X", ParseError, LowValue, HighValue); + AslCompilererror (Buffer); + + return NULL; + } + + return Op; +} + + +/******************************************************************************* + * + * FUNCTION: UtGetStringBuffer + * + * PARAMETERS: Length - Size of buffer requested + * + * RETURN: Pointer to the buffer. Aborts on allocation failure + * + * DESCRIPTION: Allocate a string buffer. Bypass the local + * dynamic memory manager for performance reasons (This has a + * major impact on the speed of the compiler.) + * + ******************************************************************************/ + +char * +UtGetStringBuffer ( + UINT32 Length) +{ + char *Buffer; + + + if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast) + { + Gbl_StringCacheNext = UtLocalCalloc (ASL_STRING_CACHE_SIZE + Length); + Gbl_StringCacheLast = Gbl_StringCacheNext + ASL_STRING_CACHE_SIZE + + Length; + } + + Buffer = Gbl_StringCacheNext; + Gbl_StringCacheNext += Length; + + return (Buffer); +} + + +/******************************************************************************* + * + * FUNCTION: UtInternalizeName + * + * PARAMETERS: ExternalName - Name to convert + * ConvertedName - Where the converted name is returned + * + * RETURN: Status + * + * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name + * + ******************************************************************************/ + +ACPI_STATUS +UtInternalizeName ( + char *ExternalName, + char **ConvertedName) +{ + ACPI_NAMESTRING_INFO Info; + ACPI_STATUS Status; + + + if (!ExternalName) + { + return (AE_OK); + } + + /* Get the length of the new internal name */ + + Info.ExternalName = ExternalName; + AcpiNsGetInternalNameLength (&Info); + + /* We need a segment to store the internal name */ + + Info.InternalName = UtGetStringBuffer (Info.Length); + if (!Info.InternalName) + { + return (AE_NO_MEMORY); + } + + /* Build the name */ + + Status = AcpiNsBuildInternalName (&Info); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + *ConvertedName = Info.InternalName; + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: UtPadNameWithUnderscores + * + * PARAMETERS: NameSeg - Input nameseg + * PaddedNameSeg - Output padded nameseg + * + * RETURN: Padded nameseg. + * + * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full + * ACPI_NAME. + * + ******************************************************************************/ + +static void +UtPadNameWithUnderscores ( + char *NameSeg, + char *PaddedNameSeg) +{ + UINT32 i; + + + for (i = 0; (i < ACPI_NAME_SIZE); i++) + { + if (*NameSeg) + { + *PaddedNameSeg = *NameSeg; + NameSeg++; + } + else + { + *PaddedNameSeg = '_'; + } + PaddedNameSeg++; + } +} + + +/******************************************************************************* + * + * FUNCTION: UtAttachNameseg + * + * PARAMETERS: Op - Parent parse node + * Name - Full ExternalName + * + * RETURN: None; Sets the NameSeg field in parent node + * + * DESCRIPTION: Extract the last nameseg of the ExternalName and store it + * in the NameSeg field of the Op. + * + ******************************************************************************/ + +static void +UtAttachNameseg ( + ACPI_PARSE_OBJECT *Op, + char *Name) +{ + char *NameSeg; + char PaddedNameSeg[4]; + + + if (!Name) + { + return; + } + + /* Look for the last dot in the namepath */ + + NameSeg = strrchr (Name, '.'); + if (NameSeg) + { + /* Found last dot, we have also found the final nameseg */ + + NameSeg++; + UtPadNameWithUnderscores (NameSeg, PaddedNameSeg); + } + else + { + /* No dots in the namepath, there is only a single nameseg. */ + /* Handle prefixes */ + + while ((*Name == '\\') || (*Name == '^')) + { + Name++; + } + + /* Remaing string should be one single nameseg */ + + UtPadNameWithUnderscores (Name, PaddedNameSeg); + } + + strncpy (Op->Asl.NameSeg, PaddedNameSeg, 4); +} + + +/******************************************************************************* + * + * FUNCTION: UtAttachNamepathToOwner + * + * PARAMETERS: Op - Parent parse node + * NameOp - Node that contains the name + * + * RETURN: Sets the ExternalName and Namepath in the parent node + * + * DESCRIPTION: Store the name in two forms in the parent node: The original + * (external) name, and the internalized name that is used within + * the ACPI namespace manager. + * + ******************************************************************************/ + +void +UtAttachNamepathToOwner ( + ACPI_PARSE_OBJECT *Op, + ACPI_PARSE_OBJECT *NameOp) +{ + ACPI_STATUS Status; + + + /* Full external path */ + + Op->Asl.ExternalName = NameOp->Asl.Value.String; + + /* Save the NameOp for possible error reporting later */ + + Op->Asl.ParentMethod = (void *) NameOp; + + /* Last nameseg of the path */ + + UtAttachNameseg (Op, Op->Asl.ExternalName); + + /* Create internalized path */ + + Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath); + if (ACPI_FAILURE (Status)) + { + /* TBD: abort on no memory */ + } +} + + +/******************************************************************************* + * + * FUNCTION: UtDoConstant + * + * PARAMETERS: String - Hex, Octal, or Decimal string + * + * RETURN: Converted Integer + * + * DESCRIPTION: Convert a string to an integer. With error checking. + * + ******************************************************************************/ + +UINT64 +UtDoConstant ( + char *String) +{ + ACPI_STATUS Status; + UINT64 Converted; + char ErrBuf[64]; + + + Status = UtStrtoul64 (String, 0, &Converted); + if (ACPI_FAILURE (Status)) + { + sprintf (ErrBuf, "%s %s\n", "Conversion error:", + AcpiFormatException (Status)); + AslCompilererror (ErrBuf); + } + + return (Converted); +} + + +/* TBD: use version in ACPI CA main code base? */ + +/******************************************************************************* + * + * FUNCTION: UtStrtoul64 + * + * PARAMETERS: String - Null terminated string + * Terminater - Where a pointer to the terminating byte is + * returned + * Base - Radix of the string + * + * RETURN: Converted value + * + * DESCRIPTION: Convert a string into an unsigned value. + * + ******************************************************************************/ + +ACPI_STATUS +UtStrtoul64 ( + char *String, + UINT32 Base, + UINT64 *RetInteger) +{ + UINT32 Index; + UINT32 Sign; + UINT64 ReturnValue = 0; + ACPI_STATUS Status = AE_OK; + + + *RetInteger = 0; + + switch (Base) + { + case 0: + case 8: + case 10: + case 16: + break; + + default: + /* + * The specified Base parameter is not in the domain of + * this function: + */ + return (AE_BAD_PARAMETER); + } + + /* Skip over any white space in the buffer: */ + + while (isspace ((int) *String) || *String == '\t') + { + ++String; + } + + /* + * The buffer may contain an optional plus or minus sign. + * If it does, then skip over it but remember what is was: + */ + if (*String == '-') + { + Sign = NEGATIVE; + ++String; + } + else if (*String == '+') + { + ++String; + Sign = POSITIVE; + } + else + { + Sign = POSITIVE; + } + + /* + * If the input parameter Base is zero, then we need to + * determine if it is octal, decimal, or hexadecimal: + */ + if (Base == 0) + { + if (*String == '0') + { + if (tolower ((int) *(++String)) == 'x') + { + Base = 16; + ++String; + } + else + { + Base = 8; + } + } + else + { + Base = 10; + } + } + + /* + * For octal and hexadecimal bases, skip over the leading + * 0 or 0x, if they are present. + */ + if (Base == 8 && *String == '0') + { + String++; + } + + if (Base == 16 && + *String == '0' && + tolower ((int) *(++String)) == 'x') + { + String++; + } + + /* Main loop: convert the string to an unsigned long */ + + while (*String) + { + if (isdigit ((int) *String)) + { + Index = ((UINT8) *String) - '0'; + } + else + { + Index = (UINT8) toupper ((int) *String); + if (isupper ((int) Index)) + { + Index = Index - 'A' + 10; + } + else + { + goto ErrorExit; + } + } + + if (Index >= Base) + { + goto ErrorExit; + } + + /* Check to see if value is out of range: */ + + if (ReturnValue > ((ACPI_UINT64_MAX - (UINT64) Index) / + (UINT64) Base)) + { + goto ErrorExit; + } + else + { + ReturnValue *= Base; + ReturnValue += Index; + } + + ++String; + } + + + /* If a minus sign was present, then "the conversion is negated": */ + + if (Sign == NEGATIVE) + { + ReturnValue = (ACPI_UINT32_MAX - ReturnValue) + 1; + } + + *RetInteger = ReturnValue; + return (Status); + + +ErrorExit: + switch (Base) + { + case 8: + Status = AE_BAD_OCTAL_CONSTANT; + break; + + case 10: + Status = AE_BAD_DECIMAL_CONSTANT; + break; + + case 16: + Status = AE_BAD_HEX_CONSTANT; + break; + + default: + /* Base validated above */ + break; + } + + return (Status); +} + + diff --git a/sys/contrib/dev/acpica/compiler/asluuid.c b/sys/contrib/dev/acpica/compiler/asluuid.c new file mode 100644 index 0000000..485db6b --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/asluuid.c @@ -0,0 +1,216 @@ +/****************************************************************************** + * + * Module Name: asluuid-- compiler UUID support + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("asluuid") + + +/* + * UUID support functions. + * + * This table is used to convert an input UUID ascii string to a 16 byte + * buffer and the reverse. The table maps a UUID buffer index 0-15 to + * the index within the 36-byte UUID string where the associated 2-byte + * hex value can be found. + * + * 36-byte UUID strings are of the form: + * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp + * Where aa-pp are one byte hex numbers, made up of two hex digits + * + * Note: This table is basically the inverse of the string-to-offset table + * found in the ACPI spec in the description of the ToUUID macro. + */ +static UINT8 Gbl_MapToUuidOffset[16] = +{ + 6,4,2,0,11,9,16,14,19,21,24,26,28,30,32,34 +}; + +#define UUID_BUFFER_LENGTH 16 +#define UUID_STRING_LENGTH 36 + +/* Positions for required hyphens (dashes) in UUID strings */ + +#define UUID_HYPHEN1_OFFSET 8 +#define UUID_HYPHEN2_OFFSET 13 +#define UUID_HYPHEN3_OFFSET 18 +#define UUID_HYPHEN4_OFFSET 23 + + +/******************************************************************************* + * + * FUNCTION: AuValiduateUuid + * + * PARAMETERS: InString - 36-byte formatted UUID string + * + * RETURN: Status + * + * DESCRIPTION: Check all 36 characters for correct format + * + ******************************************************************************/ + +ACPI_STATUS +AuValidateUuid ( + char *InString) +{ + UINT32 i; + + + if (!InString || (ACPI_STRLEN (InString) != UUID_STRING_LENGTH)) + { + return (AE_BAD_PARAMETER); + } + + /* Check all 36 characters for correct format */ + + for (i = 0; i < UUID_STRING_LENGTH; i++) + { + /* Must have 4 hyphens (dashes) in these positions: */ + + if ((i == UUID_HYPHEN1_OFFSET) || + (i == UUID_HYPHEN2_OFFSET) || + (i == UUID_HYPHEN3_OFFSET) || + (i == UUID_HYPHEN4_OFFSET)) + { + if (InString[i] != '-') + { + return (AE_BAD_PARAMETER); + } + } + + /* All other positions must contain hex digits */ + + else + { + if (!isxdigit ((int) InString[i])) + { + return (AE_BAD_PARAMETER); + } + } + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: AuConvertStringToUuid + * + * PARAMETERS: InString - 36-byte formatted UUID string + * UuidBuffer - 16-byte UUID buffer + * + * RETURN: Status + * + * DESCRIPTION: Convert 36-byte formatted UUID string to 16-byte UUID buffer + * + ******************************************************************************/ + +ACPI_STATUS +AuConvertStringToUuid ( + char *InString, + char *UuidBuffer) +{ + UINT32 i; + + + if (!InString || !UuidBuffer) + { + return (AE_BAD_PARAMETER); + } + + for (i = 0; i < UUID_BUFFER_LENGTH; i++) + { + UuidBuffer[i] = (char) (UtHexCharToValue (InString[Gbl_MapToUuidOffset[i]]) << 4); + UuidBuffer[i] |= (char) UtHexCharToValue (InString[Gbl_MapToUuidOffset[i] + 1]); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: AuConvertUuidToString + * + * PARAMETERS: UuidBuffer - 16-byte UUID buffer + * OutString - 36-byte formatted UUID string + * + * RETURN: Status + * + * DESCRIPTION: Convert 16-byte UUID buffer to 36-byte formatted UUID string + * OutString must be 37 bytes to include null terminator. + * + ******************************************************************************/ + +ACPI_STATUS +AuConvertUuidToString ( + char *UuidBuffer, + char *OutString) +{ + UINT32 i; + + + if (!UuidBuffer || !OutString) + { + return (AE_BAD_PARAMETER); + } + + for (i = 0; i < UUID_BUFFER_LENGTH; i++) + { + OutString[Gbl_MapToUuidOffset[i]] = (UINT8) AslHexLookup[(UuidBuffer[i] >> 4) & 0xF]; + OutString[Gbl_MapToUuidOffset[i] + 1] = (UINT8) AslHexLookup[UuidBuffer[i] & 0xF]; + } + + /* Insert required hyphens (dashes) */ + + OutString[UUID_HYPHEN1_OFFSET] = + OutString[UUID_HYPHEN2_OFFSET] = + OutString[UUID_HYPHEN3_OFFSET] = + OutString[UUID_HYPHEN4_OFFSET] = '-'; + + OutString[UUID_STRING_LENGTH] = 0; /* Null terminate */ + return (AE_OK); +} diff --git a/sys/contrib/dev/acpica/compiler/aslwalks.c b/sys/contrib/dev/acpica/compiler/aslwalks.c new file mode 100644 index 0000000..7c14ef0 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/aslwalks.c @@ -0,0 +1,1237 @@ +/****************************************************************************** + * + * Module Name: aslwalks.c - major analytical parse tree walks + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "aslcompiler.y.h" +#include <contrib/dev/acpica/include/acparser.h> +#include <contrib/dev/acpica/include/amlcode.h> + + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("aslwalks") + + +/******************************************************************************* + * + * FUNCTION: AnMethodAnalysisWalkBegin + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Descending callback for the analysis walk. Check methods for: + * 1) Initialized local variables + * 2) Valid arguments + * 3) Return types + * + ******************************************************************************/ + +ACPI_STATUS +AnMethodAnalysisWalkBegin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context; + ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack; + ACPI_PARSE_OBJECT *Next; + UINT32 RegisterNumber; + UINT32 i; + char LocalName[] = "Local0"; + char ArgName[] = "Arg0"; + ACPI_PARSE_OBJECT *ArgNode; + ACPI_PARSE_OBJECT *NextType; + ACPI_PARSE_OBJECT *NextParamType; + UINT8 ActualArgs = 0; + + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_METHOD: + + TotalMethods++; + + /* Create and init method info */ + + MethodInfo = UtLocalCalloc (sizeof (ASL_METHOD_INFO)); + MethodInfo->Next = WalkInfo->MethodStack; + MethodInfo->Op = Op; + + WalkInfo->MethodStack = MethodInfo; + + /* Get the name node, ignored here */ + + Next = Op->Asl.Child; + + /* Get the NumArguments node */ + + Next = Next->Asl.Next; + MethodInfo->NumArguments = (UINT8) + (((UINT8) Next->Asl.Value.Integer) & 0x07); + + /* Get the SerializeRule and SyncLevel nodes, ignored here */ + + Next = Next->Asl.Next; + Next = Next->Asl.Next; + ArgNode = Next; + + /* Get the ReturnType node */ + + Next = Next->Asl.Next; + + NextType = Next->Asl.Child; + while (NextType) + { + /* Get and map each of the ReturnTypes */ + + MethodInfo->ValidReturnTypes |= AnMapObjTypeToBtype (NextType); + NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + NextType = NextType->Asl.Next; + } + + /* Get the ParameterType node */ + + Next = Next->Asl.Next; + + NextType = Next->Asl.Child; + while (NextType) + { + if (NextType->Asl.ParseOpcode == PARSEOP_DEFAULT_ARG) + { + NextParamType = NextType->Asl.Child; + while (NextParamType) + { + MethodInfo->ValidArgTypes[ActualArgs] |= AnMapObjTypeToBtype (NextParamType); + NextParamType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + NextParamType = NextParamType->Asl.Next; + } + } + else + { + MethodInfo->ValidArgTypes[ActualArgs] = + AnMapObjTypeToBtype (NextType); + NextType->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + ActualArgs++; + } + + NextType = NextType->Asl.Next; + } + + if ((MethodInfo->NumArguments) && + (MethodInfo->NumArguments != ActualArgs)) + { + /* error: Param list did not match number of args */ + } + + /* Allow numarguments == 0 for Function() */ + + if ((!MethodInfo->NumArguments) && (ActualArgs)) + { + MethodInfo->NumArguments = ActualArgs; + ArgNode->Asl.Value.Integer |= ActualArgs; + } + + /* + * Actual arguments are initialized at method entry. + * All other ArgX "registers" can be used as locals, so we + * track their initialization. + */ + for (i = 0; i < MethodInfo->NumArguments; i++) + { + MethodInfo->ArgInitialized[i] = TRUE; + } + break; + + + case PARSEOP_METHODCALL: + + if (MethodInfo && + (Op->Asl.Node == MethodInfo->Op->Asl.Node)) + { + AslError (ASL_REMARK, ASL_MSG_RECURSION, Op, Op->Asl.ExternalName); + } + break; + + + case PARSEOP_LOCAL0: + case PARSEOP_LOCAL1: + case PARSEOP_LOCAL2: + case PARSEOP_LOCAL3: + case PARSEOP_LOCAL4: + case PARSEOP_LOCAL5: + case PARSEOP_LOCAL6: + case PARSEOP_LOCAL7: + + if (!MethodInfo) + { + /* + * Local was used outside a control method, or there was an error + * in the method declaration. + */ + AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName); + return (AE_ERROR); + } + + RegisterNumber = (Op->Asl.AmlOpcode & 0x000F); + + /* + * If the local is being used as a target, mark the local + * initialized + */ + if (Op->Asl.CompileFlags & NODE_IS_TARGET) + { + MethodInfo->LocalInitialized[RegisterNumber] = TRUE; + } + + /* + * Otherwise, this is a reference, check if the local + * has been previously initialized. + * + * The only operator that accepts an uninitialized value is ObjectType() + */ + else if ((!MethodInfo->LocalInitialized[RegisterNumber]) && + (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) + { + LocalName[strlen (LocalName) -1] = (char) (RegisterNumber + 0x30); + AslError (ASL_ERROR, ASL_MSG_LOCAL_INIT, Op, LocalName); + } + break; + + + case PARSEOP_ARG0: + case PARSEOP_ARG1: + case PARSEOP_ARG2: + case PARSEOP_ARG3: + case PARSEOP_ARG4: + case PARSEOP_ARG5: + case PARSEOP_ARG6: + + if (!MethodInfo) + { + /* + * Arg was used outside a control method, or there was an error + * in the method declaration. + */ + AslError (ASL_REMARK, ASL_MSG_LOCAL_OUTSIDE_METHOD, Op, Op->Asl.ExternalName); + return (AE_ERROR); + } + + RegisterNumber = (Op->Asl.AmlOpcode & 0x000F) - 8; + ArgName[strlen (ArgName) -1] = (char) (RegisterNumber + 0x30); + + /* + * If the Arg is being used as a target, mark the local + * initialized + */ + if (Op->Asl.CompileFlags & NODE_IS_TARGET) + { + MethodInfo->ArgInitialized[RegisterNumber] = TRUE; + } + + /* + * Otherwise, this is a reference, check if the Arg + * has been previously initialized. + * + * The only operator that accepts an uninitialized value is ObjectType() + */ + else if ((!MethodInfo->ArgInitialized[RegisterNumber]) && + (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_OBJECTTYPE)) + { + AslError (ASL_ERROR, ASL_MSG_ARG_INIT, Op, ArgName); + } + + /* Flag this arg if it is not a "real" argument to the method */ + + if (RegisterNumber >= MethodInfo->NumArguments) + { + AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Op, ArgName); + } + break; + + + case PARSEOP_RETURN: + + if (!MethodInfo) + { + /* + * Probably was an error in the method declaration, + * no additional error here + */ + ACPI_WARNING ((AE_INFO, "%p, No parent method", Op)); + return (AE_ERROR); + } + + /* + * A child indicates a possible return value. A simple Return or + * Return() is marked with NODE_IS_NULL_RETURN by the parser so + * that it is not counted as a "real" return-with-value, although + * the AML code that is actually emitted is Return(0). The AML + * definition of Return has a required parameter, so we are + * forced to convert a null return to Return(0). + */ + if ((Op->Asl.Child) && + (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG) && + (!(Op->Asl.Child->Asl.CompileFlags & NODE_IS_NULL_RETURN))) + { + MethodInfo->NumReturnWithValue++; + } + else + { + MethodInfo->NumReturnNoValue++; + } + break; + + + case PARSEOP_BREAK: + case PARSEOP_CONTINUE: + + Next = Op->Asl.Parent; + while (Next) + { + if (Next->Asl.ParseOpcode == PARSEOP_WHILE) + { + break; + } + Next = Next->Asl.Parent; + } + + if (!Next) + { + AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Op, NULL); + } + break; + + + case PARSEOP_STALL: + + /* We can range check if the argument is an integer */ + + if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_INTEGER) && + (Op->Asl.Child->Asl.Value.Integer > ACPI_UINT8_MAX)) + { + AslError (ASL_ERROR, ASL_MSG_INVALID_TIME, Op, NULL); + } + break; + + + case PARSEOP_DEVICE: + case PARSEOP_EVENT: + case PARSEOP_MUTEX: + case PARSEOP_OPERATIONREGION: + case PARSEOP_POWERRESOURCE: + case PARSEOP_PROCESSOR: + case PARSEOP_THERMALZONE: + + /* + * The first operand is a name to be created in the namespace. + * Check against the reserved list. + */ + i = ApCheckForPredefinedName (Op, Op->Asl.NameSeg); + if (i < ACPI_VALID_RESERVED_NAME_MAX) + { + AslError (ASL_ERROR, ASL_MSG_RESERVED_USE, Op, Op->Asl.ExternalName); + } + break; + + + case PARSEOP_NAME: + + /* Typecheck any predefined names statically defined with Name() */ + + ApCheckForPredefinedObject (Op, Op->Asl.NameSeg); + + /* Special typechecking for _HID */ + + if (!ACPI_STRCMP (METHOD_NAME__HID, Op->Asl.NameSeg)) + { + Next = Op->Asl.Child->Asl.Next; + AnCheckId (Next, ASL_TYPE_HID); + } + + /* Special typechecking for _CID */ + + else if (!ACPI_STRCMP (METHOD_NAME__CID, Op->Asl.NameSeg)) + { + Next = Op->Asl.Child->Asl.Next; + + if ((Next->Asl.ParseOpcode == PARSEOP_PACKAGE) || + (Next->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)) + { + Next = Next->Asl.Child; + while (Next) + { + AnCheckId (Next, ASL_TYPE_CID); + Next = Next->Asl.Next; + } + } + else + { + AnCheckId (Next, ASL_TYPE_CID); + } + } + break; + + + default: + break; + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: AnMethodAnalysisWalkEnd + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Ascending callback for analysis walk. Complete method + * return analysis. + * + ******************************************************************************/ + +ACPI_STATUS +AnMethodAnalysisWalkEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ASL_ANALYSIS_WALK_INFO *WalkInfo = (ASL_ANALYSIS_WALK_INFO *) Context; + ASL_METHOD_INFO *MethodInfo = WalkInfo->MethodStack; + + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_METHOD: + case PARSEOP_RETURN: + if (!MethodInfo) + { + printf ("No method info for method! [%s]\n", Op->Asl.Namepath); + AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, Op, + "No method info for this method"); + + CmCleanupAndExit (); + return (AE_AML_INTERNAL); + } + break; + + default: + break; + } + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_METHOD: + + WalkInfo->MethodStack = MethodInfo->Next; + + /* + * Check if there is no return statement at the end of the + * method AND we can actually get there -- i.e., the execution + * of the method can possibly terminate without a return statement. + */ + if ((!AnLastStatementIsReturn (Op)) && + (!(Op->Asl.CompileFlags & NODE_HAS_NO_EXIT))) + { + /* + * No return statement, and execution can possibly exit + * via this path. This is equivalent to Return () + */ + MethodInfo->NumReturnNoValue++; + } + + /* + * Check for case where some return statements have a return value + * and some do not. Exit without a return statement is a return with + * no value + */ + if (MethodInfo->NumReturnNoValue && + MethodInfo->NumReturnWithValue) + { + AslError (ASL_WARNING, ASL_MSG_RETURN_TYPES, Op, + Op->Asl.ExternalName); + } + + /* + * If there are any RETURN() statements with no value, or there is a + * control path that allows the method to exit without a return value, + * we mark the method as a method that does not return a value. This + * knowledge can be used to check method invocations that expect a + * returned value. + */ + if (MethodInfo->NumReturnNoValue) + { + if (MethodInfo->NumReturnWithValue) + { + Op->Asl.CompileFlags |= NODE_METHOD_SOME_NO_RETVAL; + } + else + { + Op->Asl.CompileFlags |= NODE_METHOD_NO_RETVAL; + } + } + + /* + * Check predefined method names for correct return behavior + * and correct number of arguments. Also, some special checks + * For GPE and _REG methods. + */ + if (ApCheckForPredefinedMethod (Op, MethodInfo)) + { + /* Special check for two names like _L01 and _E01 in same scope */ + + ApCheckForGpeNameConflict (Op); + + /* + * Special check for _REG: Must have an operation region definition + * within the same scope! + */ + ApCheckRegMethod (Op); + } + + ACPI_FREE (MethodInfo); + break; + + + case PARSEOP_NAME: + + /* Special check for two names like _L01 and _E01 in same scope */ + + ApCheckForGpeNameConflict (Op); + break; + + + case PARSEOP_RETURN: + + /* + * If the parent is a predefined method name, attempt to typecheck + * the return value. Only static types can be validated. + */ + ApCheckPredefinedReturnValue (Op, MethodInfo); + + /* + * The parent block does not "exit" and continue execution -- the + * method is terminated here with the Return() statement. + */ + Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT; + + /* Used in the "typing" pass later */ + + Op->Asl.ParentMethod = MethodInfo->Op; + + /* + * If there is a peer node after the return statement, then this + * node is unreachable code -- i.e., it won't be executed because of + * the preceeding Return() statement. + */ + if (Op->Asl.Next) + { + AslError (ASL_WARNING, ASL_MSG_UNREACHABLE_CODE, Op->Asl.Next, NULL); + } + break; + + + case PARSEOP_IF: + + if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) && + (Op->Asl.Next) && + (Op->Asl.Next->Asl.ParseOpcode == PARSEOP_ELSE)) + { + /* + * This IF has a corresponding ELSE. The IF block has no exit, + * (it contains an unconditional Return) + * mark the ELSE block to remember this fact. + */ + Op->Asl.Next->Asl.CompileFlags |= NODE_IF_HAS_NO_EXIT; + } + break; + + + case PARSEOP_ELSE: + + if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) && + (Op->Asl.CompileFlags & NODE_IF_HAS_NO_EXIT)) + { + /* + * This ELSE block has no exit and the corresponding IF block + * has no exit either. Therefore, the parent node has no exit. + */ + Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT; + } + break; + + + default: + + if ((Op->Asl.CompileFlags & NODE_HAS_NO_EXIT) && + (Op->Asl.Parent)) + { + /* If this node has no exit, then the parent has no exit either */ + + Op->Asl.Parent->Asl.CompileFlags |= NODE_HAS_NO_EXIT; + } + break; + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: AnMethodTypingWalkEnd + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Ascending callback for typing walk. Complete the method + * return analysis. Check methods for: + * 1) Initialized local variables + * 2) Valid arguments + * 3) Return types + * + ******************************************************************************/ + +ACPI_STATUS +AnMethodTypingWalkEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + UINT32 ThisNodeBtype; + + + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_METHOD: + + Op->Asl.CompileFlags |= NODE_METHOD_TYPED; + break; + + case PARSEOP_RETURN: + + if ((Op->Asl.Child) && + (Op->Asl.Child->Asl.ParseOpcode != PARSEOP_DEFAULT_ARG)) + { + ThisNodeBtype = AnGetBtype (Op->Asl.Child); + + if ((Op->Asl.Child->Asl.ParseOpcode == PARSEOP_METHODCALL) && + (ThisNodeBtype == (ACPI_UINT32_MAX -1))) + { + /* + * The called method is untyped at this time (typically a + * forward reference). + * + * Check for a recursive method call first. + */ + if (Op->Asl.ParentMethod != Op->Asl.Child->Asl.Node->Op) + { + /* We must type the method here */ + + TrWalkParseTree (Op->Asl.Child->Asl.Node->Op, + ASL_WALK_VISIT_UPWARD, NULL, + AnMethodTypingWalkEnd, NULL); + + ThisNodeBtype = AnGetBtype (Op->Asl.Child); + } + } + + /* Returns a value, save the value type */ + + if (Op->Asl.ParentMethod) + { + Op->Asl.ParentMethod->Asl.AcpiBtype |= ThisNodeBtype; + } + } + break; + + default: + break; + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: AnOperandTypecheckWalkEnd + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Ascending callback for analysis walk. Complete method + * return analysis. + * + ******************************************************************************/ + +ACPI_STATUS +AnOperandTypecheckWalkEnd ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + const ACPI_OPCODE_INFO *OpInfo; + UINT32 RuntimeArgTypes; + UINT32 RuntimeArgTypes2; + UINT32 RequiredBtypes; + UINT32 ThisNodeBtype; + UINT32 CommonBtypes; + UINT32 OpcodeClass; + ACPI_PARSE_OBJECT *ArgOp; + UINT32 ArgType; + + + switch (Op->Asl.AmlOpcode) + { + case AML_RAW_DATA_BYTE: + case AML_RAW_DATA_WORD: + case AML_RAW_DATA_DWORD: + case AML_RAW_DATA_QWORD: + case AML_RAW_DATA_BUFFER: + case AML_RAW_DATA_CHAIN: + case AML_PACKAGE_LENGTH: + case AML_UNASSIGNED_OPCODE: + case AML_DEFAULT_ARG_OP: + + /* Ignore the internal (compiler-only) AML opcodes */ + + return (AE_OK); + + default: + break; + } + + OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); + if (!OpInfo) + { + return (AE_OK); + } + + ArgOp = Op->Asl.Child; + RuntimeArgTypes = OpInfo->RuntimeArgs; + OpcodeClass = OpInfo->Class; + +#ifdef ASL_ERROR_NAMED_OBJECT_IN_WHILE + /* + * Update 11/2008: In practice, we can't perform this check. A simple + * analysis is not sufficient. Also, it can cause errors when compiling + * disassembled code because of the way Switch operators are implemented + * (a While(One) loop with a named temp variable created within.) + */ + + /* + * If we are creating a named object, check if we are within a while loop + * by checking if the parent is a WHILE op. This is a simple analysis, but + * probably sufficient for many cases. + * + * Allow Scope(), Buffer(), and Package(). + */ + if (((OpcodeClass == AML_CLASS_NAMED_OBJECT) && (Op->Asl.AmlOpcode != AML_SCOPE_OP)) || + ((OpcodeClass == AML_CLASS_CREATE) && (OpInfo->Flags & AML_NSNODE))) + { + if (Op->Asl.Parent->Asl.AmlOpcode == AML_WHILE_OP) + { + AslError (ASL_ERROR, ASL_MSG_NAMED_OBJECT_IN_WHILE, Op, NULL); + } + } +#endif + + /* + * Special case for control opcodes IF/RETURN/WHILE since they + * have no runtime arg list (at this time) + */ + switch (Op->Asl.AmlOpcode) + { + case AML_IF_OP: + case AML_WHILE_OP: + case AML_RETURN_OP: + + if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) + { + /* Check for an internal method */ + + if (AnIsInternalMethod (ArgOp)) + { + return (AE_OK); + } + + /* The lone arg is a method call, check it */ + + RequiredBtypes = AnMapArgTypeToBtype (ARGI_INTEGER); + if (Op->Asl.AmlOpcode == AML_RETURN_OP) + { + RequiredBtypes = 0xFFFFFFFF; + } + + ThisNodeBtype = AnGetBtype (ArgOp); + if (ThisNodeBtype == ACPI_UINT32_MAX) + { + return (AE_OK); + } + AnCheckMethodReturnValue (Op, OpInfo, ArgOp, + RequiredBtypes, ThisNodeBtype); + } + return (AE_OK); + + default: + break; + } + + /* Ignore the non-executable opcodes */ + + if (RuntimeArgTypes == ARGI_INVALID_OPCODE) + { + return (AE_OK); + } + + switch (OpcodeClass) + { + case AML_CLASS_EXECUTE: + case AML_CLASS_CREATE: + case AML_CLASS_CONTROL: + case AML_CLASS_RETURN_VALUE: + + /* TBD: Change class or fix typechecking for these */ + + if ((Op->Asl.AmlOpcode == AML_BUFFER_OP) || + (Op->Asl.AmlOpcode == AML_PACKAGE_OP) || + (Op->Asl.AmlOpcode == AML_VAR_PACKAGE_OP)) + { + break; + } + + /* Reverse the runtime argument list */ + + RuntimeArgTypes2 = 0; + while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes))) + { + RuntimeArgTypes2 <<= ARG_TYPE_WIDTH; + RuntimeArgTypes2 |= ArgType; + INCREMENT_ARG_LIST (RuntimeArgTypes); + } + + while ((ArgType = GET_CURRENT_ARG_TYPE (RuntimeArgTypes2))) + { + RequiredBtypes = AnMapArgTypeToBtype (ArgType); + + ThisNodeBtype = AnGetBtype (ArgOp); + if (ThisNodeBtype == ACPI_UINT32_MAX) + { + goto NextArgument; + } + + /* Examine the arg based on the required type of the arg */ + + switch (ArgType) + { + case ARGI_TARGETREF: + + if (ArgOp->Asl.ParseOpcode == PARSEOP_ZERO) + { + /* ZERO is the placeholder for "don't store result" */ + + ThisNodeBtype = RequiredBtypes; + break; + } + + if (ArgOp->Asl.ParseOpcode == PARSEOP_INTEGER) + { + /* + * This is the case where an original reference to a resource + * descriptor field has been replaced by an (Integer) offset. + * These named fields are supported at compile-time only; + * the names are not passed to the interpreter (via the AML). + */ + if ((ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) || + (ArgOp->Asl.Node->Type == ACPI_TYPE_LOCAL_RESOURCE)) + { + AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgOp, NULL); + } + else + { + AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, NULL); + } + break; + } + + if ((ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) || + (ArgOp->Asl.ParseOpcode == PARSEOP_DEREFOF)) + { + break; + } + + ThisNodeBtype = RequiredBtypes; + break; + + + case ARGI_REFERENCE: /* References */ + case ARGI_INTEGER_REF: + case ARGI_OBJECT_REF: + case ARGI_DEVICE_REF: + + switch (ArgOp->Asl.ParseOpcode) + { + case PARSEOP_LOCAL0: + case PARSEOP_LOCAL1: + case PARSEOP_LOCAL2: + case PARSEOP_LOCAL3: + case PARSEOP_LOCAL4: + case PARSEOP_LOCAL5: + case PARSEOP_LOCAL6: + case PARSEOP_LOCAL7: + + /* TBD: implement analysis of current value (type) of the local */ + /* For now, just treat any local as a typematch */ + + /*ThisNodeBtype = RequiredBtypes;*/ + break; + + case PARSEOP_ARG0: + case PARSEOP_ARG1: + case PARSEOP_ARG2: + case PARSEOP_ARG3: + case PARSEOP_ARG4: + case PARSEOP_ARG5: + case PARSEOP_ARG6: + + /* Hard to analyze argument types, sow we won't */ + /* For now, just treat any arg as a typematch */ + + /* ThisNodeBtype = RequiredBtypes; */ + break; + + case PARSEOP_DEBUG: + break; + + case PARSEOP_REFOF: + case PARSEOP_INDEX: + default: + break; + + } + break; + + case ARGI_INTEGER: + default: + break; + } + + + CommonBtypes = ThisNodeBtype & RequiredBtypes; + + if (ArgOp->Asl.ParseOpcode == PARSEOP_METHODCALL) + { + if (AnIsInternalMethod (ArgOp)) + { + return (AE_OK); + } + + /* Check a method call for a valid return value */ + + AnCheckMethodReturnValue (Op, OpInfo, ArgOp, + RequiredBtypes, ThisNodeBtype); + } + + /* + * Now check if the actual type(s) match at least one + * bit to the required type + */ + else if (!CommonBtypes) + { + /* No match -- this is a type mismatch error */ + + AnFormatBtype (StringBuffer, ThisNodeBtype); + AnFormatBtype (StringBuffer2, RequiredBtypes); + + sprintf (MsgBuffer, "[%s] found, %s operator requires [%s]", + StringBuffer, OpInfo->Name, StringBuffer2); + + AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgOp, MsgBuffer); + } + + NextArgument: + ArgOp = ArgOp->Asl.Next; + INCREMENT_ARG_LIST (RuntimeArgTypes2); + } + break; + + default: + break; + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: AnOtherSemanticAnalysisWalkBegin + * + * PARAMETERS: ASL_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Descending callback for the analysis walk. Checks for + * miscellaneous issues in the code. + * + ******************************************************************************/ + +ACPI_STATUS +AnOtherSemanticAnalysisWalkBegin ( + ACPI_PARSE_OBJECT *Op, + UINT32 Level, + void *Context) +{ + ACPI_PARSE_OBJECT *ArgNode; + ACPI_PARSE_OBJECT *PrevArgNode = NULL; + const ACPI_OPCODE_INFO *OpInfo; + ACPI_NAMESPACE_NODE *Node; + + + OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode); + + /* + * Determine if an execution class operator actually does something by + * checking if it has a target and/or the function return value is used. + * (Target is optional, so a standalone statement can actually do nothing.) + */ + if ((OpInfo->Class == AML_CLASS_EXECUTE) && + (OpInfo->Flags & AML_HAS_RETVAL) && + (!AnIsResultUsed (Op))) + { + if (OpInfo->Flags & AML_HAS_TARGET) + { + /* + * Find the target node, it is always the last child. If the traget + * is not specified in the ASL, a default node of type Zero was + * created by the parser. + */ + ArgNode = Op->Asl.Child; + while (ArgNode->Asl.Next) + { + PrevArgNode = ArgNode; + ArgNode = ArgNode->Asl.Next; + } + + /* Divide() is the only weird case, it has two targets */ + + if (Op->Asl.AmlOpcode == AML_DIVIDE_OP) + { + if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) && + (PrevArgNode) && + (PrevArgNode->Asl.ParseOpcode == PARSEOP_ZERO)) + { + AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, + Op, Op->Asl.ExternalName); + } + } + else if (ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) + { + AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, + Op, Op->Asl.ExternalName); + } + } + else + { + /* + * Has no target and the result is not used. Only a couple opcodes + * can have this combination. + */ + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_ACQUIRE: + case PARSEOP_WAIT: + case PARSEOP_LOADTABLE: + break; + + default: + AslError (ASL_WARNING, ASL_MSG_RESULT_NOT_USED, + Op, Op->Asl.ExternalName); + break; + } + } + } + + + /* + * Semantic checks for individual ASL operators + */ + switch (Op->Asl.ParseOpcode) + { + case PARSEOP_ACQUIRE: + case PARSEOP_WAIT: + /* + * Emit a warning if the timeout parameter for these operators is not + * ACPI_WAIT_FOREVER, and the result value from the operator is not + * checked, meaning that a timeout could happen, but the code + * would not know about it. + */ + + /* First child is the namepath, 2nd child is timeout */ + + ArgNode = Op->Asl.Child; + ArgNode = ArgNode->Asl.Next; + + /* + * Check for the WAIT_FOREVER case - defined by the ACPI spec to be + * 0xFFFF or greater + */ + if (((ArgNode->Asl.ParseOpcode == PARSEOP_WORDCONST) || + (ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER)) && + (ArgNode->Asl.Value.Integer >= (UINT64) ACPI_WAIT_FOREVER)) + { + break; + } + + /* + * The operation could timeout. If the return value is not used + * (indicates timeout occurred), issue a warning + */ + if (!AnIsResultUsed (Op)) + { + AslError (ASL_WARNING, ASL_MSG_TIMEOUT, ArgNode, + Op->Asl.ExternalName); + } + break; + + case PARSEOP_CREATEFIELD: + /* + * Check for a zero Length (NumBits) operand. NumBits is the 3rd operand + */ + ArgNode = Op->Asl.Child; + ArgNode = ArgNode->Asl.Next; + ArgNode = ArgNode->Asl.Next; + + if ((ArgNode->Asl.ParseOpcode == PARSEOP_ZERO) || + ((ArgNode->Asl.ParseOpcode == PARSEOP_INTEGER) && + (ArgNode->Asl.Value.Integer == 0))) + { + AslError (ASL_ERROR, ASL_MSG_NON_ZERO, ArgNode, NULL); + } + break; + + case PARSEOP_CONNECTION: + /* + * Ensure that the referenced operation region has the correct SPACE_ID. + * From the grammar/parser, we know the parent is a FIELD definition. + */ + ArgNode = Op->Asl.Parent; /* Field definition */ + ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */ + Node = ArgNode->Asl.Node; /* OpRegion namespace node */ + + ArgNode = Node->Op; /* OpRegion definition */ + ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */ + ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */ + + /* + * The Connection() operator is only valid for the following operation + * region SpaceIds: GeneralPurposeIo and GenericSerialBus. + */ + if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) && + (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS)) + { + AslError (ASL_ERROR, ASL_MSG_CONNECTION_INVALID, Op, NULL); + } + break; + + case PARSEOP_FIELD: + /* + * Ensure that fields for GeneralPurposeIo and GenericSerialBus + * contain at least one Connection() operator + */ + ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */ + Node = ArgNode->Asl.Node; /* OpRegion namespace node */ + if (!Node) + { + break; + } + + ArgNode = Node->Op; /* OpRegion definition */ + ArgNode = ArgNode->Asl.Child; /* First child is the OpRegion Name */ + ArgNode = ArgNode->Asl.Next; /* Next peer is the SPACE_ID (what we want) */ + + /* We are only interested in GeneralPurposeIo and GenericSerialBus */ + + if ((ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GPIO) && + (ArgNode->Asl.Value.Integer != ACPI_ADR_SPACE_GSBUS)) + { + break; + } + + ArgNode = Op->Asl.Child; /* 1st child is the OpRegion Name */ + ArgNode = ArgNode->Asl.Next; /* AccessType */ + ArgNode = ArgNode->Asl.Next; /* LockRule */ + ArgNode = ArgNode->Asl.Next; /* UpdateRule */ + ArgNode = ArgNode->Asl.Next; /* Start of FieldUnitList */ + + /* Walk the FieldUnitList */ + + while (ArgNode) + { + if (ArgNode->Asl.ParseOpcode == PARSEOP_CONNECTION) + { + break; + } + else if (ArgNode->Asl.ParseOpcode == PARSEOP_NAMESEG) + { + AslError (ASL_ERROR, ASL_MSG_CONNECTION_MISSING, ArgNode, NULL); + break; + } + + ArgNode = ArgNode->Asl.Next; + } + break; + + default: + break; + } + + return (AE_OK); +} diff --git a/sys/contrib/dev/acpica/compiler/dtcompile.c b/sys/contrib/dev/acpica/compiler/dtcompile.c new file mode 100644 index 0000000..a36eb95 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtcompile.c @@ -0,0 +1,600 @@ +/****************************************************************************** + * + * Module Name: dtcompile.c - Front-end for data table compiler + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTCOMPILE_C__ +#define _DECLARE_DT_GLOBALS + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtcompile") + +static char VersionString[9]; + + +/* Local prototypes */ + +static ACPI_STATUS +DtInitialize ( + void); + +static ACPI_STATUS +DtCompileDataTable ( + DT_FIELD **Field); + +static void +DtInsertCompilerIds ( + DT_FIELD *FieldList); + + +/****************************************************************************** + * + * FUNCTION: DtDoCompile + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Main entry point for the data table compiler. + * + * Note: Assumes Gbl_Files[ASL_FILE_INPUT] is initialized and the file is + * open at seek offset zero. + * + *****************************************************************************/ + +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); + LsDoHexOutput (); + DtWriteTableToListing (); + +CleanupAndExit: + + CmCleanupAndExit (); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtInitialize + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Initialize data table compiler globals. Enables multiple + * compiles per invocation. + * + *****************************************************************************/ + +static ACPI_STATUS +DtInitialize ( + void) +{ + ACPI_STATUS Status; + + + Status = AcpiOsInitialize (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Status = AcpiUtInitGlobals (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Gbl_FieldList = NULL; + Gbl_RootTable = NULL; + Gbl_SubtableStack = NULL; + + sprintf (VersionString, "%X", (UINT32) ACPI_CA_VERSION); + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtInsertCompilerIds + * + * PARAMETERS: FieldList - Current field list pointer + * + * RETURN: None + * + * DESCRIPTION: Insert the IDs (Name, Version) of the current compiler into + * the original ACPI table header. + * + *****************************************************************************/ + +static void +DtInsertCompilerIds ( + DT_FIELD *FieldList) +{ + DT_FIELD *Next; + UINT32 i; + + + /* + * Don't insert current compiler ID if requested. Used for compiler + * debug/validation only. + */ + if (Gbl_UseOriginalCompilerId) + { + return; + } + + /* Walk to the Compiler fields at the end of the header */ + + Next = FieldList; + for (i = 0; i < 7; i++) + { + Next = Next->Next; + } + + Next->Value = ASL_CREATOR_ID; + Next->Flags = DT_FIELD_NOT_ALLOCATED; + + Next = Next->Next; + Next->Value = VersionString; + Next->Flags = DT_FIELD_NOT_ALLOCATED; +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileDataTable + * + * PARAMETERS: FieldList - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Entry point to compile one data table + * + *****************************************************************************/ + +static ACPI_STATUS +DtCompileDataTable ( + DT_FIELD **FieldList) +{ + ACPI_DMTABLE_DATA *TableData; + DT_SUBTABLE *Subtable; + char *Signature; + ACPI_TABLE_HEADER *AcpiTableHeader; + ACPI_STATUS Status; + + + /* Verify that we at least have a table signature and save it */ + + Signature = DtGetFieldValue (*FieldList); + if (!Signature) + { + sprintf (MsgBuffer, "Expected \"%s\"", "Signature"); + DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME, + *FieldList, MsgBuffer); + return (AE_ERROR); + } + + Gbl_Signature = UtLocalCalloc (ACPI_STRLEN (Signature) + 1); + strcpy (Gbl_Signature, Signature); + + /* + * Handle tables that don't use the common ACPI table header structure. + * Currently, these are the FACS and RSDP. Also check for an OEMx table, + * these tables have user-defined contents. + */ + if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) + { + Status = DtCompileFacs (FieldList); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtSetTableLength (); + return (Status); + } + else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_RSDP)) + { + Status = DtCompileRsdp (FieldList); + return (Status); + } + else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_S3PT)) + { + Status = DtCompileS3pt (FieldList); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtSetTableLength (); + return (Status); + } + + /* + * All other tables must use the common ACPI table header. Insert the + * current iASL IDs (name, version), and compile the header now. + */ + DtInsertCompilerIds (*FieldList); + + Status = DtCompileTable (FieldList, AcpiDmTableInfoHeader, + &Gbl_RootTable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtPushSubtable (Gbl_RootTable); + + /* Validate the signature via the ACPI table list */ + + TableData = AcpiDmGetTableData (Signature); + if (!TableData || Gbl_CompileGeneric) + { + DtCompileGeneric ((void **) FieldList); + goto Out; + } + + /* Dispatch to per-table compile */ + + if (TableData->CmTableHandler) + { + /* Complex table, has a handler */ + + Status = TableData->CmTableHandler ((void **) FieldList); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + } + else if (TableData->TableInfo) + { + /* Simple table, just walk the info table */ + + Subtable = NULL; + Status = DtCompileTable (FieldList, TableData->TableInfo, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (Gbl_RootTable, Subtable); + DtPopSubtable (); + } + else + { + DtFatal (ASL_MSG_COMPILER_INTERNAL, *FieldList, + "Missing table dispatch info"); + return (AE_ERROR); + } + +Out: + /* Set the final table length and then the checksum */ + + DtSetTableLength (); + AcpiTableHeader = ACPI_CAST_PTR ( + ACPI_TABLE_HEADER, Gbl_RootTable->Buffer); + DtSetTableChecksum (&AcpiTableHeader->Checksum); + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileTable + * + * PARAMETERS: Field - Current field list pointer + * Info - Info table for this ACPI table + * RetSubtable - Compile result of table + * Required - If this subtable must exist + * + * RETURN: Status + * + * DESCRIPTION: Compile a subtable + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileTable ( + DT_FIELD **Field, + ACPI_DMTABLE_INFO *Info, + DT_SUBTABLE **RetSubtable, + BOOLEAN Required) +{ + DT_FIELD *LocalField; + UINT32 Length; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *InlineSubtable; + UINT32 FieldLength = 0; + UINT8 FieldType; + UINT8 *Buffer; + UINT8 *FlagBuffer = NULL; + UINT32 CurrentFlagByteOffset = 0; + ACPI_STATUS Status; + + + if (!Field || !*Field) + { + return (AE_BAD_PARAMETER); + } + + Length = DtGetSubtableLength (*Field, Info); + if (Length == ASL_EOF) + { + return (AE_ERROR); + } + + Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE)); + + if (Length > 0) + { + Subtable->Buffer = UtLocalCalloc (Length); + } + Subtable->Length = Length; + Subtable->TotalLength = Length; + Buffer = Subtable->Buffer; + + LocalField = *Field; + + /* + * Main loop walks the info table for this ACPI table or subtable + */ + for (; Info->Name; Info++) + { + if (Info->Opcode == ACPI_DMT_EXTRA_TEXT) + { + continue; + } + + if (!LocalField) + { + sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed", + Info->Name); + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); + Status = AE_BAD_DATA; + goto Error; + } + + /* Maintain table offsets */ + + LocalField->TableOffset = Gbl_CurrentTableOffset; + FieldLength = DtGetFieldLength (LocalField, Info); + Gbl_CurrentTableOffset += FieldLength; + + FieldType = DtGetFieldType (Info); + Gbl_InputFieldCount++; + + switch (FieldType) + { + case DT_FIELD_TYPE_FLAGS_INTEGER: + /* + * Start of the definition of a flags field. + * This master flags integer starts at value zero, in preparation + * to compile and insert the flag fields from the individual bits + */ + LocalField = LocalField->Next; + *Field = LocalField; + + FlagBuffer = Buffer; + CurrentFlagByteOffset = Info->Offset; + break; + + case DT_FIELD_TYPE_FLAG: + + /* Individual Flag field, can be multiple bits */ + + if (FlagBuffer) + { + /* + * We must increment the FlagBuffer when we have crossed + * into the next flags byte within the flags field + * of type DT_FIELD_TYPE_FLAGS_INTEGER. + */ + FlagBuffer += (Info->Offset - CurrentFlagByteOffset); + CurrentFlagByteOffset = Info->Offset; + + DtCompileFlag (FlagBuffer, LocalField, Info); + } + else + { + /* TBD - this is an internal error */ + } + + LocalField = LocalField->Next; + *Field = LocalField; + break; + + case DT_FIELD_TYPE_INLINE_SUBTABLE: + /* + * Recursion (one level max): compile GAS (Generic Address) + * or Notify in-line subtable + */ + *Field = LocalField; + + if (Info->Opcode == ACPI_DMT_GAS) + { + Status = DtCompileTable (Field, AcpiDmTableInfoGas, + &InlineSubtable, TRUE); + } + else + { + Status = DtCompileTable (Field, AcpiDmTableInfoHestNotify, + &InlineSubtable, TRUE); + } + + if (ACPI_FAILURE (Status)) + { + goto Error; + } + + DtSetSubtableLength (InlineSubtable); + + ACPI_MEMCPY (Buffer, InlineSubtable->Buffer, FieldLength); + ACPI_FREE (InlineSubtable->Buffer); + ACPI_FREE (InlineSubtable); + LocalField = *Field; + break; + + case DT_FIELD_TYPE_LABEL: + + DtWriteFieldToListing (Buffer, LocalField, 0); + LocalField = LocalField->Next; + break; + + default: + + /* Normal case for most field types (Integer, String, etc.) */ + + DtCompileOneField (Buffer, LocalField, + FieldLength, FieldType, Info->Flags); + + DtWriteFieldToListing (Buffer, LocalField, FieldLength); + LocalField = LocalField->Next; + + if (Info->Flags & DT_LENGTH) + { + /* Field is an Integer that will contain a subtable length */ + + Subtable->LengthField = Buffer; + Subtable->SizeOfLengthField = FieldLength; + } + + break; + } + + Buffer += FieldLength; + } + + *Field = LocalField; + *RetSubtable = Subtable; + return (AE_OK); + +Error: + ACPI_FREE (Subtable->Buffer); + ACPI_FREE (Subtable); + return (Status); +} diff --git a/sys/contrib/dev/acpica/compiler/dtcompiler.h b/sys/contrib/dev/acpica/compiler/dtcompiler.h new file mode 100644 index 0000000..22d1805 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtcompiler.h @@ -0,0 +1,517 @@ +/****************************************************************************** + * + * Module Name: dtcompiler.h - header for data table compiler + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTCOMPILER_H__ + +#ifndef _DTCOMPILER +#define _DTCOMPILER + +#include <stdio.h> +#include <contrib/dev/acpica/include/acdisasm.h> + + +#undef DT_EXTERN + +#ifdef _DECLARE_DT_GLOBALS +#define DT_EXTERN +#define DT_INIT_GLOBAL(a,b) (a)=(b) +#else +#define DT_EXTERN extern +#define DT_INIT_GLOBAL(a,b) (a) +#endif + + +/* Types for individual fields (one per input line) */ + +#define DT_FIELD_TYPE_STRING 0 +#define DT_FIELD_TYPE_INTEGER 1 +#define DT_FIELD_TYPE_BUFFER 2 +#define DT_FIELD_TYPE_PCI_PATH 3 +#define DT_FIELD_TYPE_FLAG 4 +#define DT_FIELD_TYPE_FLAGS_INTEGER 5 +#define DT_FIELD_TYPE_INLINE_SUBTABLE 6 +#define DT_FIELD_TYPE_UUID 7 +#define DT_FIELD_TYPE_UNICODE 8 +#define DT_FIELD_TYPE_DEVICE_PATH 9 +#define DT_FIELD_TYPE_LABEL 10 + + +/* + * Structure used for each individual field within an ACPI table + */ +typedef struct dt_field +{ + char *Name; /* Field name (from name : value) */ + char *Value; /* Field value (from name : value) */ + struct dt_field *Next; /* Next field */ + struct dt_field *NextLabel; /* If field is a label, next label */ + UINT32 Line; /* Line number for this field */ + UINT32 ByteOffset; /* Offset in source file for field */ + UINT32 NameColumn; /* Start column for field name */ + UINT32 Column; /* Start column for field value */ + UINT32 TableOffset;/* Binary offset within ACPI table */ + UINT8 Flags; + +} DT_FIELD; + +/* Flags for above */ + +#define DT_FIELD_NOT_ALLOCATED 1 + + +/* + * Structure used for individual subtables within an ACPI table + */ +typedef struct dt_subtable +{ + struct dt_subtable *Parent; + struct dt_subtable *Child; + struct dt_subtable *Peer; + struct dt_subtable *StackTop; + UINT8 *Buffer; + UINT8 *LengthField; + UINT32 Length; + UINT32 TotalLength; + UINT32 SizeOfLengthField; + UINT8 Flags; + +} DT_SUBTABLE; + + +/* + * Globals + */ + +/* List of all field names and values from the input source */ + +DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_FieldList, NULL); + +/* List of all compiled tables and subtables */ + +DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_RootTable, NULL); + +/* Stack for subtables */ + +DT_EXTERN DT_SUBTABLE DT_INIT_GLOBAL (*Gbl_SubtableStack, NULL); + +/* List for defined labels */ + +DT_EXTERN DT_FIELD DT_INIT_GLOBAL (*Gbl_LabelList, NULL); + +/* Current offset within the binary output table */ + +DT_EXTERN UINT32 DT_INIT_GLOBAL (Gbl_CurrentTableOffset, 0); + + +/* dtcompiler - main module */ + +ACPI_STATUS +DtCompileTable ( + DT_FIELD **Field, + ACPI_DMTABLE_INFO *Info, + DT_SUBTABLE **RetSubtable, + BOOLEAN Required); + + +/* dtio - binary and text input/output */ + +UINT32 +DtGetNextLine ( + FILE *Handle); + +DT_FIELD * +DtScanFile ( + FILE *Handle); + +void +DtOutputBinary ( + DT_SUBTABLE *RootTable); + +void +DtWriteFieldToListing ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 Length); + +void +DtWriteTableToListing ( + void); + + +/* dtsubtable - compile subtables */ + +void +DtCreateSubtable ( + UINT8 *Buffer, + UINT32 Length, + DT_SUBTABLE **RetSubtable); + +UINT32 +DtGetSubtableLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info); + +void +DtSetSubtableLength ( + DT_SUBTABLE *Subtable); + +void +DtPushSubtable ( + DT_SUBTABLE *Subtable); + +void +DtPopSubtable ( + void); + +DT_SUBTABLE * +DtPeekSubtable ( + void); + +void +DtInsertSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *Subtable); + +DT_SUBTABLE * +DtGetNextSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *ChildTable); + +DT_SUBTABLE * +DtGetParentSubtable ( + DT_SUBTABLE *Subtable); + + +/* dtexpress - Integer expressions and labels */ + +ACPI_STATUS +DtResolveIntegerExpression ( + DT_FIELD *Field, + UINT64 *ReturnValue); + +UINT64 +DtDoOperator ( + UINT64 LeftValue, + UINT32 Operator, + UINT64 RightValue); + +UINT64 +DtResolveLabel ( + char *LabelString); + +void +DtDetectAllLabels ( + DT_FIELD *FieldList); + + +/* dtfield - Compile individual fields within a table */ + +void +DtCompileOneField ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength, + UINT8 Type, + UINT8 Flags); + +void +DtCompileInteger ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength, + UINT8 Flags); + +UINT32 +DtCompileBuffer ( + UINT8 *Buffer, + char *Value, + DT_FIELD *Field, + UINT32 ByteLength); + +void +DtCompileFlag ( + UINT8 *Buffer, + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info); + + +/* dtparser - lex/yacc files */ + +UINT64 +DtEvaluateExpression ( + char *ExprString); + +int +DtInitLexer ( + char *String); + +void +DtTerminateLexer ( + void); + +char * +DtGetOpName ( + UINT32 ParseOpcode); + + +/* dtutils - Miscellaneous utilities */ + +typedef +void (*DT_WALK_CALLBACK) ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue); + +void +DtWalkTableTree ( + DT_SUBTABLE *StartTable, + DT_WALK_CALLBACK UserFunction, + void *Context, + void *ReturnValue); + +void +DtError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage); + +void +DtNameError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage); + +void +DtFatal ( + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage); + +ACPI_STATUS +DtStrtoul64 ( + char *String, + UINT64 *ReturnInteger); + +UINT32 +DtGetFileSize ( + FILE *Handle); + +char* +DtGetFieldValue ( + DT_FIELD *Field); + +UINT8 +DtGetFieldType ( + ACPI_DMTABLE_INFO *Info); + +UINT32 +DtGetBufferLength ( + char *Buffer); + +UINT32 +DtGetFieldLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info); + +void +DtSetTableChecksum ( + UINT8 *ChecksumPointer); + +void +DtSetTableLength( + void); + +void +DtFreeFieldList ( + void); + + +/* dttable - individual table compilation */ + +ACPI_STATUS +DtCompileFacs ( + DT_FIELD **PFieldList); + +ACPI_STATUS +DtCompileRsdp ( + DT_FIELD **PFieldList); + +ACPI_STATUS +DtCompileAsf ( + void **PFieldList); + +ACPI_STATUS +DtCompileCpep ( + void **PFieldList); + +ACPI_STATUS +DtCompileDmar ( + void **PFieldList); + +ACPI_STATUS +DtCompileEinj ( + void **PFieldList); + +ACPI_STATUS +DtCompileErst ( + void **PFieldList); + +ACPI_STATUS +DtCompileFadt ( + void **PFieldList); + +ACPI_STATUS +DtCompileFpdt ( + void **PFieldList); + +ACPI_STATUS +DtCompileHest ( + void **PFieldList); + +ACPI_STATUS +DtCompileIvrs ( + void **PFieldList); + +ACPI_STATUS +DtCompileMadt ( + void **PFieldList); + +ACPI_STATUS +DtCompileMcfg ( + void **PFieldList); + +ACPI_STATUS +DtCompileMpst ( + void **PFieldList); + +ACPI_STATUS +DtCompileMsct ( + void **PFieldList); + +ACPI_STATUS +DtCompilePmtt ( + void **PFieldList); + +ACPI_STATUS +DtCompileRsdt ( + void **PFieldList); + +ACPI_STATUS +DtCompileS3pt ( + DT_FIELD **PFieldList); + +ACPI_STATUS +DtCompileSlic ( + void **PFieldList); + +ACPI_STATUS +DtCompileSlit ( + void **PFieldList); + +ACPI_STATUS +DtCompileSrat ( + void **PFieldList); + +ACPI_STATUS +DtCompileUefi ( + void **PFieldList); + +ACPI_STATUS +DtCompileWdat ( + void **PFieldList); + +ACPI_STATUS +DtCompileXsdt ( + void **PFieldList); + +ACPI_STATUS +DtCompileGeneric ( + void **PFieldList); + +ACPI_DMTABLE_INFO * +DtGetGenericTableInfo ( + char *Name); + +/* ACPI Table templates */ + +extern const unsigned char TemplateAsf[]; +extern const unsigned char TemplateBoot[]; +extern const unsigned char TemplateBert[]; +extern const unsigned char TemplateBgrt[]; +extern const unsigned char TemplateCpep[]; +extern const unsigned char TemplateDbgp[]; +extern const unsigned char TemplateDmar[]; +extern const unsigned char TemplateEcdt[]; +extern const unsigned char TemplateEinj[]; +extern const unsigned char TemplateErst[]; +extern const unsigned char TemplateFadt[]; +extern const unsigned char TemplateFpdt[]; +extern const unsigned char TemplateGtdt[]; +extern const unsigned char TemplateHest[]; +extern const unsigned char TemplateHpet[]; +extern const unsigned char TemplateIvrs[]; +extern const unsigned char TemplateMadt[]; +extern const unsigned char TemplateMcfg[]; +extern const unsigned char TemplateMchi[]; +extern const unsigned char TemplateMpst[]; +extern const unsigned char TemplateMsct[]; +extern const unsigned char TemplatePmtt[]; +extern const unsigned char TemplateRsdt[]; +extern const unsigned char TemplateS3pt[]; +extern const unsigned char TemplateSbst[]; +extern const unsigned char TemplateSlic[]; +extern const unsigned char TemplateSlit[]; +extern const unsigned char TemplateSpcr[]; +extern const unsigned char TemplateSpmi[]; +extern const unsigned char TemplateSrat[]; +extern const unsigned char TemplateTcpa[]; +extern const unsigned char TemplateUefi[]; +extern const unsigned char TemplateWaet[]; +extern const unsigned char TemplateWdat[]; +extern const unsigned char TemplateWddt[]; +extern const unsigned char TemplateWdrt[]; +extern const unsigned char TemplateXsdt[]; + +#endif diff --git a/sys/contrib/dev/acpica/compiler/dtexpress.c b/sys/contrib/dev/acpica/compiler/dtexpress.c new file mode 100644 index 0000000..f0a1c8e --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtexpress.c @@ -0,0 +1,407 @@ +/****************************************************************************** + * + * Module Name: dtexpress.c - Support for integer expressions and labels + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTEXPRESS_C__ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> +#include "dtparser.y.h" + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtexpress") + + +/* Local prototypes */ + +static void +DtInsertLabelField ( + DT_FIELD *Field); + +static DT_FIELD * +DtLookupLabel ( + char *Name); + +/* Global used for errors during parse and related functions */ + +DT_FIELD *Gbl_CurrentField; + + +/****************************************************************************** + * + * FUNCTION: DtResolveIntegerExpression + * + * PARAMETERS: Field - Field object with Integer expression + * ReturnValue - Where the integer is returned + * + * RETURN: Status, and the resolved 64-bit integer value + * + * DESCRIPTION: Resolve an integer expression to a single value. Supports + * both integer constants and labels. + * + *****************************************************************************/ + +ACPI_STATUS +DtResolveIntegerExpression ( + DT_FIELD *Field, + UINT64 *ReturnValue) +{ + UINT64 Result; + + + DbgPrint (ASL_DEBUG_OUTPUT, "Full Integer expression: %s\n", + Field->Value); + + Gbl_CurrentField = Field; + + Result = DtEvaluateExpression (Field->Value); + *ReturnValue = Result; + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtDoOperator + * + * PARAMETERS: LeftValue - First 64-bit operand + * Operator - Parse token for the operator (EXPOP_*) + * RightValue - Second 64-bit operand + * + * RETURN: 64-bit result of the requested operation + * + * DESCRIPTION: Perform the various 64-bit integer math functions + * + *****************************************************************************/ + +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); +} + + +/****************************************************************************** + * + * FUNCTION: DtResolveLabel + * + * PARAMETERS: LabelString - Contains the label + * + * RETURN: Table offset associated with the label + * + * DESCRIPTION: Lookup a lable and return its value. + * + *****************************************************************************/ + +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); +} + + +/****************************************************************************** + * + * FUNCTION: DtDetectAllLabels + * + * PARAMETERS: FieldList - Field object at start of generic list + * + * RETURN: None + * + * DESCRIPTION: Detect all labels in a list of "generic" opcodes (such as + * a UEFI table.) and insert them into the global label list. + * + *****************************************************************************/ + +void +DtDetectAllLabels ( + DT_FIELD *FieldList) +{ + ACPI_DMTABLE_INFO *Info; + DT_FIELD *GenericField; + UINT32 TableOffset; + + + TableOffset = Gbl_CurrentTableOffset; + GenericField = FieldList; + + /* + * Process all "Label:" fields within the parse tree. We need + * to know the offsets for all labels before we can compile + * the parse tree in order to handle forward references. Traverse + * tree and get/set all field lengths of all operators in order to + * determine the label offsets. + */ + while (GenericField) + { + Info = DtGetGenericTableInfo (GenericField->Name); + if (Info) + { + /* Maintain table offsets */ + + GenericField->TableOffset = TableOffset; + TableOffset += DtGetFieldLength (GenericField, Info); + + /* Insert all labels in the global label list */ + + if (Info->Opcode == ACPI_DMT_LABEL) + { + DtInsertLabelField (GenericField); + } + } + + GenericField = GenericField->Next; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtInsertLabelField + * + * PARAMETERS: Field - Field object with Label to be inserted + * + * RETURN: None + * + * DESCRIPTION: Insert a label field into the global label list + * + *****************************************************************************/ + +static void +DtInsertLabelField ( + DT_FIELD *Field) +{ + + DbgPrint (ASL_DEBUG_OUTPUT, + "DtInsertLabelField: Found Label : %s at output table offset %X\n", + Field->Value, Field->TableOffset); + + Field->NextLabel = Gbl_LabelList; + Gbl_LabelList = Field; +} + + +/****************************************************************************** + * + * FUNCTION: DtLookupLabel + * + * PARAMETERS: Name - Label to be resolved + * + * RETURN: Field object associated with the label + * + * DESCRIPTION: Lookup a label in the global label list. Used during the + * resolution of integer expressions. + * + *****************************************************************************/ + +static DT_FIELD * +DtLookupLabel ( + char *Name) +{ + DT_FIELD *LabelField; + + + /* Skip a leading $ */ + + if (*Name == '$') + { + Name++; + } + + /* Search global list */ + + LabelField = Gbl_LabelList; + while (LabelField) + { + if (!ACPI_STRCMP (Name, LabelField->Value)) + { + return (LabelField); + } + LabelField = LabelField->NextLabel; + } + + return (NULL); +} diff --git a/sys/contrib/dev/acpica/compiler/dtfield.c b/sys/contrib/dev/acpica/compiler/dtfield.c new file mode 100644 index 0000000..6bfa649 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtfield.c @@ -0,0 +1,561 @@ +/****************************************************************************** + * + * Module Name: dtfield.c - Code generation for individual source fields + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTFIELD_C__ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtfield") + + +/* Local prototypes */ + +static void +DtCompileString ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength); + +static void +DtCompileUnicode ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength); + +static ACPI_STATUS +DtCompileUuid ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength); + +static char * +DtNormalizeBuffer ( + char *Buffer, + UINT32 *Count); + + +/****************************************************************************** + * + * FUNCTION: DtCompileOneField + * + * PARAMETERS: Buffer - Output buffer + * Field - Field to be compiled + * ByteLength - Byte length of the field + * Type - Field type + * + * RETURN: None + * + * DESCRIPTION: Compile a field value to binary + * + *****************************************************************************/ + +void +DtCompileOneField ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength, + UINT8 Type, + UINT8 Flags) +{ + ACPI_STATUS Status; + + switch (Type) + { + case DT_FIELD_TYPE_INTEGER: + DtCompileInteger (Buffer, Field, ByteLength, Flags); + break; + + case DT_FIELD_TYPE_STRING: + DtCompileString (Buffer, Field, ByteLength); + break; + + case DT_FIELD_TYPE_UUID: + Status = DtCompileUuid (Buffer, Field, ByteLength); + if (ACPI_SUCCESS (Status)) + { + break; + } + + /* Fall through. */ + + case DT_FIELD_TYPE_BUFFER: + DtCompileBuffer (Buffer, Field->Value, Field, ByteLength); + break; + + case DT_FIELD_TYPE_UNICODE: + DtCompileUnicode (Buffer, Field, ByteLength); + break; + + case DT_FIELD_TYPE_DEVICE_PATH: + break; + + default: + DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid field type"); + break; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileString + * + * PARAMETERS: Buffer - Output buffer + * Field - String to be copied to buffer + * ByteLength - Maximum length of string + * + * RETURN: None + * + * DESCRIPTION: Copy string to the buffer + * + *****************************************************************************/ + +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); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileUnicode + * + * PARAMETERS: Buffer - Output buffer + * Field - String to be copied to buffer + * ByteLength - Maximum length of string + * + * RETURN: None + * + * DESCRIPTION: Convert ASCII string to Unicode string + * + * Note: The Unicode string is 16 bits per character, no leading signature, + * with a 16-bit terminating NULL. + * + *****************************************************************************/ + +static void +DtCompileUnicode ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength) +{ + UINT32 Count; + UINT32 i; + char *AsciiString; + UINT16 *UnicodeString; + + + AsciiString = Field->Value; + UnicodeString = (UINT16 *) Buffer; + Count = ACPI_STRLEN (AsciiString) + 1; + + /* Convert to Unicode string (including null terminator) */ + + for (i = 0; i < Count; i++) + { + UnicodeString[i] = (UINT16) AsciiString[i]; + } +} + + +/******************************************************************************* + * + * FUNCTION: DtCompileUuid + * + * PARAMETERS: Buffer - Output buffer + * Field - String to be copied to buffer + * ByteLength - Maximum length of string + * + * RETURN: None + * + * DESCRIPTION: Convert UUID string to 16-byte buffer + * + ******************************************************************************/ + +static ACPI_STATUS +DtCompileUuid ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 ByteLength) +{ + char *InString; + ACPI_STATUS Status; + + + InString = Field->Value; + + Status = AuValidateUuid (InString); + if (ACPI_FAILURE (Status)) + { + sprintf (MsgBuffer, "%s", Field->Value); + DtNameError (ASL_ERROR, ASL_MSG_INVALID_UUID, Field, MsgBuffer); + } + else + { + Status = AuConvertStringToUuid (InString, (char *) Buffer); + } + + return (Status); +} + + +/****************************************************************************** + * + * 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. + * + *****************************************************************************/ + +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) + { + sprintf (MsgBuffer, "%8.8X%8.8X", ACPI_FORMAT_UINT64 (Value)); + DtError (ASL_ERROR, ASL_MSG_INTEGER_SIZE, Field, MsgBuffer); + } + + ACPI_MEMCPY (Buffer, &Value, ByteLength); + return; +} + + +/****************************************************************************** + * + * FUNCTION: DtNormalizeBuffer + * + * PARAMETERS: Buffer - Input buffer + * Count - Output the count of hex number in + * the Buffer + * + * RETURN: The normalized buffer, freed by caller + * + * DESCRIPTION: [1A,2B,3C,4D] or 1A, 2B, 3C, 4D will be normalized + * to 1A 2B 3C 4D + * + *****************************************************************************/ + +static char * +DtNormalizeBuffer ( + char *Buffer, + UINT32 *Count) +{ + char *NewBuffer; + char *TmpBuffer; + UINT32 BufferCount = 0; + BOOLEAN Separator = TRUE; + char c; + + + NewBuffer = UtLocalCalloc (ACPI_STRLEN (Buffer) + 1); + TmpBuffer = NewBuffer; + + while ((c = *Buffer++)) + { + switch (c) + { + /* Valid separators */ + + case '[': + case ']': + case ' ': + case ',': + Separator = TRUE; + break; + + default: + if (Separator) + { + /* Insert blank as the standard separator */ + + if (NewBuffer[0]) + { + *TmpBuffer++ = ' '; + BufferCount++; + } + + Separator = FALSE; + } + + *TmpBuffer++ = c; + break; + } + } + + *Count = BufferCount + 1; + return (NewBuffer); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileBuffer + * + * PARAMETERS: Buffer - Output buffer + * StringValue - Integer list to be compiled + * Field - Current field object + * ByteLength - Byte length of the integer list + * + * RETURN: Count of remaining data in the input list + * + * DESCRIPTION: Compile and pack an integer list, for example + * "AA 1F 20 3B" ==> Buffer[] = {0xAA,0x1F,0x20,0x3B} + * + *****************************************************************************/ + +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); + return (ByteLength - Count); + } + + Buffer[i] = (UINT8) Value; + } + + ACPI_FREE (StringValue); + return (ByteLength - Count); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileFlag + * + * PARAMETERS: Buffer - Output buffer + * Field - Field to be compiled + * Info - Flag info + * + * RETURN: + * + * DESCRIPTION: Compile a flag + * + *****************************************************************************/ + +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); +} diff --git a/sys/contrib/dev/acpica/compiler/dtio.c b/sys/contrib/dev/acpica/compiler/dtio.c new file mode 100644 index 0000000..633ed2d --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtio.c @@ -0,0 +1,997 @@ +/****************************************************************************** + * + * Module Name: dtio.c - File I/O support for data table compiler + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTIO_C__ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtio") + + +/* Local prototypes */ + +static char * +DtTrim ( + char *String); + +static void +DtLinkField ( + DT_FIELD *Field); + +static ACPI_STATUS +DtParseLine ( + char *LineBuffer, + UINT32 Line, + UINT32 Offset); + +static void +DtWriteBinary ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue); + +static void +DtDumpBuffer ( + UINT32 FileId, + UINT8 *Buffer, + UINT32 Offset, + UINT32 Length); + + +/* States for DtGetNextLine */ + +#define DT_NORMAL_TEXT 0 +#define DT_START_QUOTED_STRING 1 +#define DT_START_COMMENT 2 +#define DT_SLASH_ASTERISK_COMMENT 3 +#define DT_SLASH_SLASH_COMMENT 4 +#define DT_END_COMMENT 5 +#define DT_MERGE_LINES 6 +#define DT_ESCAPE_SEQUENCE 7 + +static UINT32 Gbl_NextLineOffset; + + +/****************************************************************************** + * + * FUNCTION: DtTrim + * + * PARAMETERS: String - Current source code line to trim + * + * RETURN: Trimmed line. Must be freed by caller. + * + * DESCRIPTION: Trim left and right spaces + * + *****************************************************************************/ + +static char * +DtTrim ( + char *String) +{ + char *Start; + char *End; + char *ReturnString; + ACPI_SIZE Length; + + + /* Skip lines that start with a space */ + + if (!ACPI_STRCMP (String, " ")) + { + ReturnString = UtLocalCalloc (1); + return (ReturnString); + } + + /* Setup pointers to start and end of input string */ + + Start = String; + End = String + ACPI_STRLEN (String) - 1; + + /* Find first non-whitespace character */ + + while ((Start <= End) && ((*Start == ' ') || (*Start == '\t'))) + { + Start++; + } + + /* Find last non-space character */ + + while (End >= Start) + { + if (*End == '\r' || *End == '\n') + { + End--; + continue; + } + + if (*End != ' ') + { + break; + } + + End--; + } + + /* Remove any quotes around the string */ + + if (*Start == '\"') + { + Start++; + } + if (*End == '\"') + { + End--; + } + + /* Create the trimmed return string */ + + Length = ACPI_PTR_DIFF (End, Start) + 1; + ReturnString = UtLocalCalloc (Length + 1); + if (ACPI_STRLEN (Start)) + { + ACPI_STRNCPY (ReturnString, Start, Length); + } + + ReturnString[Length] = 0; + return (ReturnString); +} + + +/****************************************************************************** + * + * FUNCTION: DtLinkField + * + * PARAMETERS: Field - New field object to link + * + * RETURN: None + * + * DESCRIPTION: Link one field name and value to the list + * + *****************************************************************************/ + +static void +DtLinkField ( + DT_FIELD *Field) +{ + DT_FIELD *Prev; + DT_FIELD *Next; + + + Prev = Next = Gbl_FieldList; + + while (Next) + { + Prev = Next; + Next = Next->Next; + } + + if (Prev) + { + Prev->Next = Field; + } + else + { + Gbl_FieldList = Field; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtParseLine + * + * PARAMETERS: LineBuffer - Current source code line + * Line - Current line number in the source + * Offset - Current byte offset of the line + * + * RETURN: Status + * + * DESCRIPTION: Parse one source line + * + *****************************************************************************/ + +static ACPI_STATUS +DtParseLine ( + char *LineBuffer, + UINT32 Line, + UINT32 Offset) +{ + char *Start; + char *End; + char *TmpName; + char *TmpValue; + char *Name; + char *Value; + char *Colon; + UINT32 Length; + DT_FIELD *Field; + UINT32 Column; + UINT32 NameColumn; + BOOLEAN IsNullString = FALSE; + + + if (!LineBuffer) + { + return (AE_OK); + } + + /* All lines after "Raw Table Data" are ingored */ + + if (strstr (LineBuffer, ACPI_RAW_TABLE_DATA_HEADER)) + { + return (AE_NOT_FOUND); + } + + Colon = strchr (LineBuffer, ':'); + if (!Colon) + { + return (AE_OK); + } + + Start = LineBuffer; + End = Colon; + + while (Start < Colon) + { + if (*Start == ' ') + { + Start++; + continue; + } + + /* Found left bracket, go to the right bracket */ + + if (*Start == '[') + { + while (Start < Colon && *Start != ']') + { + Start++; + } + + if (Start == Colon) + { + break; + } + + Start++; + continue; + } + + break; + } + + /* + * There are two column values. One for the field name, + * and one for the field value. + */ + Column = ACPI_PTR_DIFF (Colon, LineBuffer) + 3; + NameColumn = ACPI_PTR_DIFF (Start, LineBuffer) + 1; + + Length = ACPI_PTR_DIFF (End, Start); + + TmpName = UtLocalCalloc (Length + 1); + ACPI_STRNCPY (TmpName, Start, Length); + Name = DtTrim (TmpName); + ACPI_FREE (TmpName); + + Start = End = (Colon + 1); + while (*End) + { + /* Found left quotation, go to the right quotation and break */ + + if (*End == '"') + { + End++; + + /* Check for an explicit null string */ + + if (*End == '"') + { + IsNullString = TRUE; + } + while (*End && (*End != '"')) + { + End++; + } + + End++; + break; + } + + /* + * Special "comment" fields at line end, ignore them. + * Note: normal slash-slash and slash-asterisk comments are + * stripped already by the DtGetNextLine parser. + * + * TBD: Perhaps DtGetNextLine should parse the following type + * of comments also. + */ + if (*End == '[') + { + End--; + break; + } + End++; + } + + Length = ACPI_PTR_DIFF (End, Start); + TmpValue = UtLocalCalloc (Length + 1); + + ACPI_STRNCPY (TmpValue, Start, Length); + Value = DtTrim (TmpValue); + ACPI_FREE (TmpValue); + + /* Create a new field object only if we have a valid value field */ + + if ((Value && *Value) || IsNullString) + { + Field = UtLocalCalloc (sizeof (DT_FIELD)); + Field->Name = Name; + Field->Value = Value; + Field->Line = Line; + Field->ByteOffset = Offset; + Field->NameColumn = NameColumn; + Field->Column = Column; + + DtLinkField (Field); + } + else /* Ignore this field, it has no valid data */ + { + ACPI_FREE (Name); + ACPI_FREE (Value); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetNextLine + * + * PARAMETERS: Handle - Open file handle for the source file + * + * RETURN: Filled line buffer and offset of start-of-line (ASL_EOF on EOF) + * + * DESCRIPTION: Get the next valid source line. Removes all comments. + * Ignores empty lines. + * + * Handles both slash-asterisk and slash-slash comments. + * Also, quoted strings, but no escapes within. + * + * Line is returned in Gbl_CurrentLineBuffer. + * Line number in original file is returned in Gbl_CurrentLineNumber. + * + *****************************************************************************/ + +UINT32 +DtGetNextLine ( + FILE *Handle) +{ + BOOLEAN LineNotAllBlanks = FALSE; + UINT32 State = DT_NORMAL_TEXT; + UINT32 CurrentLineOffset; + UINT32 BeyondBufferCount; + UINT32 i; + char c; + + + for (i = 0; i < ASL_LINE_BUFFER_SIZE;) + { + c = (char) getc (Handle); + if (c == EOF) + { + switch (State) + { + case DT_START_QUOTED_STRING: + case DT_SLASH_ASTERISK_COMMENT: + case DT_SLASH_SLASH_COMMENT: + + AcpiOsPrintf ("**** EOF within comment/string %u\n", State); + break; + + default: + break; + } + + return (ASL_EOF); + } + + switch (State) + { + case DT_NORMAL_TEXT: + + /* Normal text, insert char into line buffer */ + + Gbl_CurrentLineBuffer[i] = c; + switch (c) + { + case '/': + State = DT_START_COMMENT; + break; + + case '"': + State = DT_START_QUOTED_STRING; + LineNotAllBlanks = TRUE; + i++; + break; + + case '\\': + /* + * The continuation char MUST be last char on this line. + * Otherwise, it will be assumed to be a valid ASL char. + */ + State = DT_MERGE_LINES; + break; + + case '\n': + CurrentLineOffset = Gbl_NextLineOffset; + Gbl_NextLineOffset = (UINT32) ftell (Handle); + Gbl_CurrentLineNumber++; + + /* + * Exit if line is complete. Ignore empty lines (only \n) + * or lines that contain nothing but blanks. + */ + if ((i != 0) && LineNotAllBlanks) + { + Gbl_CurrentLineBuffer[i+1] = 0; /* Terminate string */ + return (CurrentLineOffset); + } + + /* Toss this line and start a new one */ + + i = 0; + LineNotAllBlanks = FALSE; + break; + + default: + if (c != ' ') + { + LineNotAllBlanks = TRUE; + } + + i++; + break; + } + break; + + case DT_START_QUOTED_STRING: + + /* Insert raw chars until end of quoted string */ + + Gbl_CurrentLineBuffer[i] = c; + i++; + + switch (c) + { + case '"': + State = DT_NORMAL_TEXT; + break; + + case '\\': + State = DT_ESCAPE_SEQUENCE; + break; + + case '\n': + AcpiOsPrintf ("ERROR at line %u: Unterminated quoted string\n", + Gbl_CurrentLineNumber++); + State = DT_NORMAL_TEXT; + break; + + default: /* Get next character */ + break; + } + break; + + case DT_ESCAPE_SEQUENCE: + + /* Just copy the escaped character. TBD: sufficient for table compiler? */ + + Gbl_CurrentLineBuffer[i] = c; + i++; + State = DT_START_QUOTED_STRING; + break; + + case DT_START_COMMENT: + + /* Open comment if this character is an asterisk or slash */ + + switch (c) + { + case '*': + State = DT_SLASH_ASTERISK_COMMENT; + break; + + case '/': + State = DT_SLASH_SLASH_COMMENT; + break; + + default: /* Not a comment */ + i++; /* Save the preceeding slash */ + Gbl_CurrentLineBuffer[i] = c; + i++; + State = DT_NORMAL_TEXT; + break; + } + break; + + case DT_SLASH_ASTERISK_COMMENT: + + /* Ignore chars until an asterisk-slash is found */ + + switch (c) + { + case '\n': + Gbl_NextLineOffset = (UINT32) ftell (Handle); + Gbl_CurrentLineNumber++; + break; + + case '*': + State = DT_END_COMMENT; + break; + + default: + break; + } + break; + + case DT_SLASH_SLASH_COMMENT: + + /* Ignore chars until end-of-line */ + + if (c == '\n') + { + /* We will exit via the NORMAL_TEXT path */ + + ungetc (c, Handle); + State = DT_NORMAL_TEXT; + } + break; + + case DT_END_COMMENT: + + /* End comment if this char is a slash */ + + switch (c) + { + case '/': + State = DT_NORMAL_TEXT; + break; + + case '\n': + CurrentLineOffset = Gbl_NextLineOffset; + Gbl_NextLineOffset = (UINT32) ftell (Handle); + Gbl_CurrentLineNumber++; + break; + + case '*': + /* Consume all adjacent asterisks */ + break; + + default: + State = DT_SLASH_ASTERISK_COMMENT; + break; + } + break; + + case DT_MERGE_LINES: + + if (c != '\n') + { + /* + * This is not a continuation backslash, it is a normal + * normal ASL backslash - for example: Scope(\_SB_) + */ + i++; /* Keep the backslash that is already in the buffer */ + + ungetc (c, Handle); + State = DT_NORMAL_TEXT; + } + else + { + /* + * This is a continuation line -- a backlash followed + * immediately by a newline. Insert a space between the + * lines (overwrite the backslash) + */ + Gbl_CurrentLineBuffer[i] = ' '; + i++; + + /* Ignore newline, this will merge the lines */ + + CurrentLineOffset = Gbl_NextLineOffset; + Gbl_NextLineOffset = (UINT32) ftell (Handle); + Gbl_CurrentLineNumber++; + State = DT_NORMAL_TEXT; + } + break; + + default: + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, "Unknown input state"); + return (ASL_EOF); + } + } + + /* Line is too long for internal buffer. Determine actual length */ + + BeyondBufferCount = 1; + c = (char) getc (Handle); + while (c != '\n') + { + c = (char) getc (Handle); + BeyondBufferCount++; + } + + printf ("ERROR - At %u: Input line (%u bytes) is too long (max %u)\n", + Gbl_CurrentLineNumber++, ASL_LINE_BUFFER_SIZE + BeyondBufferCount, + ASL_LINE_BUFFER_SIZE); + return (ASL_EOF); +} + + +/****************************************************************************** + * + * FUNCTION: DtScanFile + * + * PARAMETERS: Handle - Open file handle for the source file + * + * RETURN: Pointer to start of the constructed parse tree. + * + * DESCRIPTION: Scan source file, link all field names and values + * to the global parse tree: Gbl_FieldList + * + *****************************************************************************/ + +DT_FIELD * +DtScanFile ( + FILE *Handle) +{ + ACPI_STATUS Status; + UINT32 Offset; + DT_FIELD *Next; + + + ACPI_FUNCTION_NAME (DtScanFile); + + + /* Get the file size */ + + Gbl_InputByteCount = DtGetFileSize (Handle); + + Gbl_CurrentLineNumber = 0; + Gbl_CurrentLineOffset = 0; + Gbl_NextLineOffset = 0; + + /* Scan line-by-line */ + + while ((Offset = DtGetNextLine (Handle)) != ASL_EOF) + { + ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", + Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); + + Status = DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); + if (Status == AE_NOT_FOUND) + { + break; + } + } + + /* Dump the parse tree if debug enabled */ + + if (Gbl_DebugFlag) + { + Next = Gbl_FieldList; + DbgPrint (ASL_DEBUG_OUTPUT, "Tree: %32s %32s %8s %8s %8s %8s %8s %8s\n\n", + "Name", "Value", "Line", "ByteOff", "NameCol", "Column", "TableOff", "Flags"); + + while (Next) + { + DbgPrint (ASL_DEBUG_OUTPUT, "Field: %32.32s %32.32s %.8X %.8X %.8X %.8X %.8X %.8X\n", + Next->Name, + Next->Value, + Next->Line, + Next->ByteOffset, + Next->NameColumn, + Next->Column, + Next->TableOffset, + Next->Flags); + + Next = Next->Next; + } + } + + return (Gbl_FieldList); +} + + +/* + * Output functions + */ + +/****************************************************************************** + * + * FUNCTION: DtWriteBinary + * + * PARAMETERS: DT_WALK_CALLBACK + * + * RETURN: Status + * + * DESCRIPTION: Write one subtable of a binary ACPI table + * + *****************************************************************************/ + +static void +DtWriteBinary ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue) +{ + + FlWriteFile (ASL_FILE_AML_OUTPUT, Subtable->Buffer, Subtable->Length); +} + + +/****************************************************************************** + * + * FUNCTION: DtOutputBinary + * + * PARAMETERS: + * + * RETURN: Status + * + * DESCRIPTION: Write entire binary ACPI table (result of compilation) + * + *****************************************************************************/ + +void +DtOutputBinary ( + DT_SUBTABLE *RootTable) +{ + + if (!RootTable) + { + return; + } + + /* Walk the entire parse tree, emitting the binary data */ + + DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL); + Gbl_TableLength = DtGetFileSize (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); +} + + +/* + * Listing support + */ + +/****************************************************************************** + * + * FUNCTION: DtDumpBuffer + * + * PARAMETERS: FileID - Where to write buffer data + * Buffer - Buffer to dump + * Offset - Offset in current table + * Length - Buffer Length + * + * RETURN: None + * + * DESCRIPTION: Another copy of DumpBuffer routine (unfortunately). + * + * TBD: merge dump buffer routines + * + *****************************************************************************/ + +static void +DtDumpBuffer ( + UINT32 FileId, + UINT8 *Buffer, + UINT32 Offset, + UINT32 Length) +{ + UINT32 i; + UINT32 j; + UINT8 BufChar; + + + FlPrintFile (FileId, "Output: [%3.3Xh %4.4d %3d] ", + Offset, Offset, Length); + + i = 0; + while (i < Length) + { + if (i >= 16) + { + FlPrintFile (FileId, "%24s", ""); + } + + /* Print 16 hex chars */ + + for (j = 0; j < 16;) + { + if (i + j >= Length) + { + /* Dump fill spaces */ + + FlPrintFile (FileId, " "); + j++; + continue; + } + + FlPrintFile (FileId, "%02X ", Buffer[i+j]); + j++; + } + + FlPrintFile (FileId, " "); + for (j = 0; j < 16; j++) + { + if (i + j >= Length) + { + FlPrintFile (FileId, "\n\n"); + return; + } + + BufChar = Buffer[(ACPI_SIZE) i + j]; + if (ACPI_IS_PRINT (BufChar)) + { + FlPrintFile (FileId, "%c", BufChar); + } + else + { + FlPrintFile (FileId, "."); + } + } + + /* Done with that line. */ + + FlPrintFile (FileId, "\n"); + i += 16; + } + + FlPrintFile (FileId, "\n\n"); +} + + +/****************************************************************************** + * + * FUNCTION: DtWriteFieldToListing + * + * PARAMETERS: Buffer - Contains the compiled data + * Field - Field node for the input line + * Length - Length of the output data + * + * RETURN: None + * + * DESCRIPTION: Write one field to the listing file (if listing is enabled). + * + *****************************************************************************/ + +void +DtWriteFieldToListing ( + UINT8 *Buffer, + DT_FIELD *Field, + UINT32 Length) +{ + UINT8 FileByte; + + + if (!Gbl_ListingFlag || !Field) + { + return; + } + + /* Dump the original source line */ + + FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Input: "); + FlSeekFile (ASL_FILE_INPUT, Field->ByteOffset); + + while (FlReadFile (ASL_FILE_INPUT, &FileByte, 1) == AE_OK) + { + FlWriteFile (ASL_FILE_LISTING_OUTPUT, &FileByte, 1); + if (FileByte == '\n') + { + break; + } + } + + /* Dump the line as parsed and represented internally */ + + FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Parsed: %*s : %.64s", + Field->Column-4, Field->Name, Field->Value); + + if (strlen (Field->Value) > 64) + { + FlPrintFile (ASL_FILE_LISTING_OUTPUT, "...Additional data, length 0x%X\n", + strlen (Field->Value)); + } + FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n"); + + /* Dump the hex data that will be output for this field */ + + DtDumpBuffer (ASL_FILE_LISTING_OUTPUT, Buffer, Field->TableOffset, Length); +} + + +/****************************************************************************** + * + * FUNCTION: DtWriteTableToListing + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Write the entire compiled table to the listing file + * in hex format + * + *****************************************************************************/ + +void +DtWriteTableToListing ( + void) +{ + UINT8 *Buffer; + + + if (!Gbl_ListingFlag) + { + return; + } + + /* Read the entire table from the output file */ + + Buffer = UtLocalCalloc (Gbl_TableLength); + FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + FlReadFile (ASL_FILE_AML_OUTPUT, Buffer, Gbl_TableLength); + + /* Dump the raw table data */ + + AcpiOsRedirectOutput (Gbl_Files[ASL_FILE_LISTING_OUTPUT].Handle); + + AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n", + ACPI_RAW_TABLE_DATA_HEADER, Gbl_TableLength, Gbl_TableLength); + AcpiUtDumpBuffer2 (Buffer, Gbl_TableLength, DB_BYTE_DISPLAY); + + AcpiOsRedirectOutput (stdout); +} diff --git a/sys/contrib/dev/acpica/compiler/dtparser.l b/sys/contrib/dev/acpica/compiler/dtparser.l new file mode 100644 index 0000000..b6fd6ff --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtparser.l @@ -0,0 +1,133 @@ +%{ +/****************************************************************************** + * + * Module Name: dtparser.l - Flex input file for table compiler lexer + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "dtparser.y.h" + +#define YY_NO_INPUT /* No file input, we use strings only */ + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("dtscanner") +%} + +%option noyywrap +%option nounput + +Number [0-9a-fA-F]+ +HexNumber 0[xX][0-9a-fA-F]+ +DecimalNumber 0[dD][0-9]+ +LabelRef $[a-zA-Z][0-9a-zA-Z]* +WhiteSpace [ \t\v\r]+ +NewLine [\n] + +%% + +\( return (EXPOP_PAREN_OPEN); +\) return (EXPOP_PAREN_CLOSE); +\~ return (EXPOP_ONES_COMPLIMENT); +\! return (EXPOP_LOGICAL_NOT); +\* return (EXPOP_MULTIPLY); +\/ return (EXPOP_DIVIDE); +\% return (EXPOP_MODULO); +\+ return (EXPOP_ADD); +\- return (EXPOP_SUBTRACT); +">>" return (EXPOP_SHIFT_RIGHT); +"<<" return (EXPOP_SHIFT_LEFT); +\< return (EXPOP_LESS); +\> return (EXPOP_GREATER); +"<=" return (EXPOP_LESS_EQUAL); +">=" return (EXPOP_GREATER_EQUAL); +"==" return (EXPOP_EQUAL); +"!=" return (EXPOP_NOT_EQUAL); +\& return (EXPOP_AND); +\^ return (EXPOP_XOR); +\| return (EXPOP_OR); +"&&" return (EXPOP_LOGICAL_AND); +"||" return (EXPOP_LOGICAL_OR); +<<EOF>> return (EXPOP_EOF); /* null end-of-string */ + +{LabelRef} return (EXPOP_LABEL); +{Number} return (EXPOP_NUMBER); +{HexNumber} return (EXPOP_HEX_NUMBER); +{NewLine} return (EXPOP_NEW_LINE); +{WhiteSpace} /* Ignore */ + +. return (EXPOP_EOF); + +%% + +/* + * Local support functions + */ +YY_BUFFER_STATE LexBuffer; + +/****************************************************************************** + * + * FUNCTION: DtInitLexer, DtTerminateLexer + * + * PARAMETERS: String - Input string to be parsed + * + * RETURN: None + * + * DESCRIPTION: Initialization and termination routines for lexer. Lexer needs + * a buffer to handle strings instead of a file. + * + *****************************************************************************/ + +int +DtInitLexer ( + char *String) +{ + + LexBuffer = yy_scan_string (String); + return (LexBuffer == NULL); +} + +void +DtTerminateLexer ( + void) +{ + + yy_delete_buffer (LexBuffer); +} diff --git a/sys/contrib/dev/acpica/compiler/dtparser.y b/sys/contrib/dev/acpica/compiler/dtparser.y new file mode 100644 index 0000000..cf9fb98 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtparser.y @@ -0,0 +1,277 @@ +%{ +/****************************************************************************** + * + * Module Name: dtparser.y - Bison input file for table compiler parser + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtparser") + +int DtParserlex (void); +int DtParserparse (void); +void DtParsererror (char const *msg); +extern char *DtParsertext; +extern DT_FIELD *Gbl_CurrentField; + +UINT64 DtParserResult; /* Expression return value */ + +/* Bison/yacc configuration */ + +#define yytname DtParsername +#define YYDEBUG 1 /* Enable debug output */ +#define YYERROR_VERBOSE 1 /* Verbose error messages */ +#define YYFLAG -32768 + +/* Define YYMALLOC/YYFREE to prevent redefinition errors */ + +#define YYMALLOC malloc +#define YYFREE free +%} + +%union +{ + UINT64 value; + UINT32 op; +} + +/*! [Begin] no source code translation */ + +%type <value> Expression + +%token <op> EXPOP_EOF +%token <op> EXPOP_NEW_LINE +%token <op> EXPOP_NUMBER +%token <op> EXPOP_HEX_NUMBER +%token <op> EXPOP_DECIMAL_NUMBER +%token <op> EXPOP_LABEL +%token <op> EXPOP_PAREN_OPEN +%token <op> EXPOP_PAREN_CLOSE + +%left <op> EXPOP_LOGICAL_OR +%left <op> EXPOP_LOGICAL_AND +%left <op> EXPOP_OR +%left <op> EXPOP_XOR +%left <op> EXPOP_AND +%left <op> EXPOP_EQUAL EXPOP_NOT_EQUAL +%left <op> EXPOP_GREATER EXPOP_LESS EXPOP_GREATER_EQUAL EXPOP_LESS_EQUAL +%left <op> EXPOP_SHIFT_RIGHT EXPOP_SHIFT_LEFT +%left <op> EXPOP_ADD EXPOP_SUBTRACT +%left <op> EXPOP_MULTIPLY EXPOP_DIVIDE EXPOP_MODULO +%right <op> EXPOP_ONES_COMPLIMENT EXPOP_LOGICAL_NOT + +%% + +/* + * Operator precedence rules (from K&R) + * + * 1) ( ) + * 2) ! ~ (unary operators that are supported here) + * 3) * / % + * 4) + - + * 5) >> << + * 6) < > <= >= + * 7) == != + * 8) & + * 9) ^ + * 10) | + * 11) && + * 12) || + */ +Value + : Expression EXPOP_NEW_LINE { DtParserResult=$1; return 0; } /* End of line (newline) */ + | Expression EXPOP_EOF { DtParserResult=$1; return 0; } /* End of string (0) */ + ; + +Expression + + /* Unary operators */ + + : EXPOP_LOGICAL_NOT Expression { $$ = DtDoOperator ($2, EXPOP_LOGICAL_NOT, $2);} + | EXPOP_ONES_COMPLIMENT Expression { $$ = DtDoOperator ($2, EXPOP_ONES_COMPLIMENT, $2);} + + /* Binary operators */ + + | Expression EXPOP_MULTIPLY Expression { $$ = DtDoOperator ($1, EXPOP_MULTIPLY, $3);} + | Expression EXPOP_DIVIDE Expression { $$ = DtDoOperator ($1, EXPOP_DIVIDE, $3);} + | Expression EXPOP_MODULO Expression { $$ = DtDoOperator ($1, EXPOP_MODULO, $3);} + | Expression EXPOP_ADD Expression { $$ = DtDoOperator ($1, EXPOP_ADD, $3);} + | Expression EXPOP_SUBTRACT Expression { $$ = DtDoOperator ($1, EXPOP_SUBTRACT, $3);} + | Expression EXPOP_SHIFT_RIGHT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_RIGHT, $3);} + | Expression EXPOP_SHIFT_LEFT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_LEFT, $3);} + | Expression EXPOP_GREATER Expression { $$ = DtDoOperator ($1, EXPOP_GREATER, $3);} + | Expression EXPOP_LESS Expression { $$ = DtDoOperator ($1, EXPOP_LESS, $3);} + | Expression EXPOP_GREATER_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_GREATER_EQUAL, $3);} + | Expression EXPOP_LESS_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_LESS_EQUAL, $3);} + | Expression EXPOP_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_EQUAL, $3);} + | Expression EXPOP_NOT_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_NOT_EQUAL, $3);} + | Expression EXPOP_AND Expression { $$ = DtDoOperator ($1, EXPOP_AND, $3);} + | Expression EXPOP_XOR Expression { $$ = DtDoOperator ($1, EXPOP_XOR, $3);} + | Expression EXPOP_OR Expression { $$ = DtDoOperator ($1, EXPOP_OR, $3);} + | Expression EXPOP_LOGICAL_AND Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_AND, $3);} + | Expression EXPOP_LOGICAL_OR Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_OR, $3);} + + /* Parentheses: '(' Expression ')' */ + + | EXPOP_PAREN_OPEN Expression + EXPOP_PAREN_CLOSE { $$ = $2;} + + /* Label references (prefixed with $) */ + + | EXPOP_LABEL { $$ = DtResolveLabel (DtParsertext);} + + /* Default base for a non-prefixed integer is 16 */ + + | EXPOP_NUMBER { UtStrtoul64 (DtParsertext, 16, &$$);} + + /* Standard hex number (0x1234) */ + + | EXPOP_HEX_NUMBER { UtStrtoul64 (DtParsertext, 16, &$$);} + + /* TBD: Decimal number with prefix (0d1234) - Not supported by UtStrtoul64 at this time */ + + | EXPOP_DECIMAL_NUMBER { UtStrtoul64 (DtParsertext, 10, &$$);} + ; +%% + +/*! [End] no source code translation !*/ + +/* + * Local support functions, including parser entry point + */ +#define PR_FIRST_PARSE_OPCODE EXPOP_EOF +#define PR_YYTNAME_START 3 + + +/****************************************************************************** + * + * FUNCTION: DtParsererror + * + * PARAMETERS: Message - Parser-generated error message + * + * RETURN: None + * + * DESCRIPTION: Handler for parser errors + * + *****************************************************************************/ + +void +DtParsererror ( + char const *Message) +{ + DtError (ASL_ERROR, ASL_MSG_SYNTAX, + Gbl_CurrentField, (char *) Message); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetOpName + * + * PARAMETERS: ParseOpcode - Parser token (EXPOP_*) + * + * RETURN: Pointer to the opcode name + * + * DESCRIPTION: Get the ascii name of the parse opcode for debug output + * + *****************************************************************************/ + +char * +DtGetOpName ( + UINT32 ParseOpcode) +{ +#ifdef ASL_YYTNAME_START + /* + * First entries (PR_YYTNAME_START) in yytname are special reserved names. + * Ignore first 6 characters of name (EXPOP_) + */ + return ((char *) yytname + [(ParseOpcode - PR_FIRST_PARSE_OPCODE) + PR_YYTNAME_START] + 6); +#else + return ("[Unknown parser generator]"); +#endif +} + + +/****************************************************************************** + * + * FUNCTION: DtEvaluateExpression + * + * PARAMETERS: ExprString - Expression to be evaluated. Must be + * terminated by either a newline or a NUL + * string terminator + * + * RETURN: 64-bit value for the expression + * + * DESCRIPTION: Main entry point for the DT expression parser + * + *****************************************************************************/ + +UINT64 +DtEvaluateExpression ( + char *ExprString) +{ + + DbgPrint (ASL_DEBUG_OUTPUT, + "**** Input expression: %s (Base 16)\n", ExprString); + + /* Point lexer to the input string */ + + if (DtInitLexer (ExprString)) + { + DtError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, + Gbl_CurrentField, "Could not initialize lexer"); + return (0); + } + + /* Parse/Evaluate the input string (value returned in DtParserResult) */ + + DtParserparse (); + DtTerminateLexer (); + + DbgPrint (ASL_DEBUG_OUTPUT, + "**** Parser returned value: %u (%8.8X%8.8X)\n", + (UINT32) DtParserResult, ACPI_FORMAT_UINT64 (DtParserResult)); + + return (DtParserResult); +} diff --git a/sys/contrib/dev/acpica/compiler/dtsubtable.c b/sys/contrib/dev/acpica/compiler/dtsubtable.c new file mode 100644 index 0000000..9eebe83 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtsubtable.c @@ -0,0 +1,375 @@ +/****************************************************************************** + * + * Module Name: dtsubtable.c - handling of subtables within ACPI tables + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTSUBTABLE_C__ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtsubtable") + + +/****************************************************************************** + * + * FUNCTION: DtCreateSubtable + * + * PARAMETERS: Buffer - Input buffer + * Length - Buffer length + * RetSubtable - Returned newly created subtable + * + * RETURN: None + * + * DESCRIPTION: Create a subtable that is not listed with ACPI_DMTABLE_INFO + * For example, FACS has 24 bytes reserved at the end + * and it's not listed at AcpiDmTableInfoFacs + * + *****************************************************************************/ + +void +DtCreateSubtable ( + UINT8 *Buffer, + UINT32 Length, + DT_SUBTABLE **RetSubtable) +{ + DT_SUBTABLE *Subtable; + + + Subtable = UtLocalCalloc (sizeof (DT_SUBTABLE)); + + /* Create a new buffer for the subtable data */ + + Subtable->Buffer = UtLocalCalloc (Length); + ACPI_MEMCPY (Subtable->Buffer, Buffer, Length); + + Subtable->Length = Length; + Subtable->TotalLength = Length; + + *RetSubtable = Subtable; +} + + +/****************************************************************************** + * + * FUNCTION: DtInsertSubtable + * + * PARAMETERS: ParentTable - The Parent of the new subtable + * Subtable - The new subtable to insert + * + * RETURN: None + * + * DESCRIPTION: Insert the new subtable to the parent table + * + *****************************************************************************/ + +void +DtInsertSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *Subtable) +{ + DT_SUBTABLE *ChildTable; + + + Subtable->Peer = NULL; + Subtable->Parent = ParentTable; + + /* Link the new entry into the child list */ + + if (!ParentTable->Child) + { + ParentTable->Child = Subtable; + } + else + { + /* Walk to the end of the child list */ + + ChildTable = ParentTable->Child; + while (ChildTable->Peer) + { + ChildTable = ChildTable->Peer; + } + + /* Add new subtable at the end of the child list */ + + ChildTable->Peer = Subtable; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtPushSubtable + * + * PARAMETERS: Subtable - Subtable to push + * + * RETURN: None + * + * DESCRIPTION: Push a subtable onto a subtable stack + * + *****************************************************************************/ + +void +DtPushSubtable ( + DT_SUBTABLE *Subtable) +{ + + Subtable->StackTop = Gbl_SubtableStack; + Gbl_SubtableStack = Subtable; +} + + +/****************************************************************************** + * + * FUNCTION: DtPopSubtable + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Pop a subtable from a subtable stack. Uses global SubtableStack + * + *****************************************************************************/ + +void +DtPopSubtable ( + void) +{ + DT_SUBTABLE *Subtable; + + + Subtable = Gbl_SubtableStack; + + if (Subtable) + { + Gbl_SubtableStack = Subtable->StackTop; + } +} + + +/****************************************************************************** + * + * FUNCTION: DtPeekSubtable + * + * PARAMETERS: None + * + * RETURN: The subtable on top of stack + * + * DESCRIPTION: Get the subtable on top of stack + * + *****************************************************************************/ + +DT_SUBTABLE * +DtPeekSubtable ( + void) +{ + + return (Gbl_SubtableStack); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetNextSubtable + * + * PARAMETERS: ParentTable - Parent table whose children we are + * getting + * ChildTable - Previous child that was found. + * The NEXT child will be returned + * + * RETURN: Pointer to the NEXT child or NULL if none is found. + * + * DESCRIPTION: Return the next peer subtable within the tree. + * + *****************************************************************************/ + +DT_SUBTABLE * +DtGetNextSubtable ( + DT_SUBTABLE *ParentTable, + DT_SUBTABLE *ChildTable) +{ + ACPI_FUNCTION_ENTRY (); + + + if (!ChildTable) + { + /* It's really the parent's _scope_ that we want */ + + return (ParentTable->Child); + } + + /* Otherwise just return the next peer (NULL if at end-of-list) */ + + return (ChildTable->Peer); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetParentSubtable + * + * PARAMETERS: Subtable - Current subtable + * + * RETURN: Parent of the given subtable + * + * DESCRIPTION: Get the parent of the given subtable in the tree + * + *****************************************************************************/ + +DT_SUBTABLE * +DtGetParentSubtable ( + DT_SUBTABLE *Subtable) +{ + + if (!Subtable) + { + return (NULL); + } + + return (Subtable->Parent); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetSubtableLength + * + * PARAMETERS: Field - Current field list pointer + * Info - Data table info + * + * RETURN: Subtable length + * + * DESCRIPTION: Get length of bytes needed to compile the subtable + * + *****************************************************************************/ + +UINT32 +DtGetSubtableLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info) +{ + UINT32 ByteLength = 0; + UINT8 Step; + UINT8 i; + + + /* Walk entire Info table; Null name terminates */ + + for (; Info->Name; Info++) + { + if (Info->Opcode == ACPI_DMT_EXTRA_TEXT) + { + continue; + } + + if (!Field) + { + goto Error; + } + + ByteLength += DtGetFieldLength (Field, Info); + + switch (Info->Opcode) + { + case ACPI_DMT_GAS: + Step = 5; + break; + + case ACPI_DMT_HESTNTFY: + Step = 9; + break; + + default: + Step = 1; + break; + } + + for (i = 0; i < Step; i++) + { + if (!Field) + { + goto Error; + } + + Field = Field->Next; + } + } + + return (ByteLength); + +Error: + if (!Field) + { + sprintf (MsgBuffer, "Found NULL field - Field name \"%s\" needed", + Info->Name); + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); + } + + return (ASL_EOF); +} + + +/****************************************************************************** + * + * FUNCTION: DtSetSubtableLength + * + * PARAMETERS: Subtable - Subtable + * + * RETURN: None + * + * DESCRIPTION: Set length of the subtable into its length field + * + *****************************************************************************/ + +void +DtSetSubtableLength ( + DT_SUBTABLE *Subtable) +{ + + if (!Subtable->LengthField) + { + return; + } + + ACPI_MEMCPY (Subtable->LengthField, &Subtable->TotalLength, + Subtable->SizeOfLengthField); +} diff --git a/sys/contrib/dev/acpica/compiler/dttable.c b/sys/contrib/dev/acpica/compiler/dttable.c new file mode 100644 index 0000000..efec963 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dttable.c @@ -0,0 +1,2020 @@ +/****************************************************************************** + * + * Module Name: dttable.c - handling for specific ACPI tables + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTTABLE_C__ + +/* Compile all complex data tables */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dttable") + + +/* TBD: merge these into dmtbinfo.c? */ + +static ACPI_DMTABLE_INFO TableInfoAsfAddress[] = +{ + {ACPI_DMT_BUFFER, 0, "Addresses", 0}, + {ACPI_DMT_EXIT, 0, NULL, 0} +}; + +static ACPI_DMTABLE_INFO TableInfoDmarPciPath[] = +{ + {ACPI_DMT_PCI_PATH, 0, "PCI Path", 0}, + {ACPI_DMT_EXIT, 0, NULL, 0} +}; + + +/* TBD: move to acmacros.h */ + +#define ACPI_SUB_PTR(t, a, b) \ + ACPI_CAST_PTR (t, (ACPI_CAST_PTR (UINT8, (a)) - (ACPI_SIZE)(b))) + + +/* Local prototypes */ + +static ACPI_STATUS +DtCompileTwoSubtables ( + void **List, + ACPI_DMTABLE_INFO *TableInfo1, + ACPI_DMTABLE_INFO *TableInfo2); + + +/****************************************************************************** + * + * FUNCTION: DtCompileTwoSubtables + * + * PARAMETERS: List - Current field list pointer + * TableInfo1 - Info table 1 + * TableInfo1 - Info table 2 + * + * RETURN: Status + * + * DESCRIPTION: Compile tables with a header and one or more same subtables. + * Include CPEP, EINJ, ERST, MCFG, MSCT, WDAT + * + *****************************************************************************/ + +static ACPI_STATUS +DtCompileTwoSubtables ( + void **List, + ACPI_DMTABLE_INFO *TableInfo1, + ACPI_DMTABLE_INFO *TableInfo2) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + + + Status = DtCompileTable (PFieldList, TableInfo1, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + Status = DtCompileTable (PFieldList, TableInfo2, &Subtable, FALSE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileFacs + * + * PARAMETERS: PFieldList - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile FACS. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileFacs ( + DT_FIELD **PFieldList) +{ + DT_SUBTABLE *Subtable; + UINT8 *ReservedBuffer; + ACPI_STATUS Status; + UINT32 ReservedSize; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFacs, + &Gbl_RootTable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + /* Large FACS reserved area at the end of the table */ + + ReservedSize = (UINT32) sizeof (((ACPI_TABLE_FACS *) NULL)->Reserved1); + ReservedBuffer = UtLocalCalloc (ReservedSize); + + DtCreateSubtable (ReservedBuffer, ReservedSize, &Subtable); + + ACPI_FREE (ReservedBuffer); + DtInsertSubtable (Gbl_RootTable, Subtable); + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileRsdp + * + * PARAMETERS: PFieldList - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile RSDP. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileRsdp ( + DT_FIELD **PFieldList) +{ + DT_SUBTABLE *Subtable; + ACPI_TABLE_RSDP *Rsdp; + ACPI_RSDP_EXTENSION *RsdpExtension; + ACPI_STATUS Status; + + + /* Compile the "common" RSDP (ACPI 1.0) */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoRsdp1, + &Gbl_RootTable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Rsdp = ACPI_CAST_PTR (ACPI_TABLE_RSDP, Gbl_RootTable->Buffer); + DtSetTableChecksum (&Rsdp->Checksum); + + if (Rsdp->Revision > 0) + { + /* Compile the "extended" part of the RSDP as a subtable */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoRsdp2, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (Gbl_RootTable, Subtable); + + /* Set length and extended checksum for entire RSDP */ + + RsdpExtension = ACPI_CAST_PTR (ACPI_RSDP_EXTENSION, Subtable->Buffer); + RsdpExtension->Length = Gbl_RootTable->Length + Subtable->Length; + DtSetTableChecksum (&RsdpExtension->ExtendedChecksum); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileAsf + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile ASF!. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileAsf ( + void **List) +{ + ACPI_ASF_INFO *AsfTable; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + ACPI_DMTABLE_INFO *InfoTable; + ACPI_DMTABLE_INFO *DataInfoTable = NULL; + UINT32 DataCount = 0; + ACPI_STATUS Status; + UINT32 i; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoAsfHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + AsfTable = ACPI_CAST_PTR (ACPI_ASF_INFO, Subtable->Buffer); + + switch (AsfTable->Header.Type & 0x7F) /* Mask off top bit */ + { + case ACPI_ASF_TYPE_INFO: + InfoTable = AcpiDmTableInfoAsf0; + break; + + case ACPI_ASF_TYPE_ALERT: + InfoTable = AcpiDmTableInfoAsf1; + break; + + case ACPI_ASF_TYPE_CONTROL: + InfoTable = AcpiDmTableInfoAsf2; + break; + + case ACPI_ASF_TYPE_BOOT: + InfoTable = AcpiDmTableInfoAsf3; + break; + + case ACPI_ASF_TYPE_ADDRESS: + InfoTable = AcpiDmTableInfoAsf4; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "ASF!"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + switch (AsfTable->Header.Type & 0x7F) /* Mask off top bit */ + { + case ACPI_ASF_TYPE_INFO: + DataInfoTable = NULL; + break; + + case ACPI_ASF_TYPE_ALERT: + DataInfoTable = AcpiDmTableInfoAsf1a; + DataCount = ACPI_CAST_PTR (ACPI_ASF_ALERT, + ACPI_SUB_PTR (UINT8, Subtable->Buffer, + sizeof (ACPI_ASF_HEADER)))->Alerts; + break; + + case ACPI_ASF_TYPE_CONTROL: + DataInfoTable = AcpiDmTableInfoAsf2a; + DataCount = ACPI_CAST_PTR (ACPI_ASF_REMOTE, + ACPI_SUB_PTR (UINT8, Subtable->Buffer, + sizeof (ACPI_ASF_HEADER)))->Controls; + break; + + case ACPI_ASF_TYPE_BOOT: + DataInfoTable = NULL; + break; + + case ACPI_ASF_TYPE_ADDRESS: + DataInfoTable = TableInfoAsfAddress; + DataCount = ACPI_CAST_PTR (ACPI_ASF_ADDRESS, + ACPI_SUB_PTR (UINT8, Subtable->Buffer, + sizeof (ACPI_ASF_HEADER)))->Devices; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "ASF!"); + return (AE_ERROR); + } + + if (DataInfoTable) + { + switch (AsfTable->Header.Type & 0x7F) + { + case ACPI_ASF_TYPE_ADDRESS: + + while (DataCount > 0) + { + Status = DtCompileTable (PFieldList, DataInfoTable, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + DataCount = DataCount - Subtable->Length; + } + break; + + default: + + for (i = 0; i < DataCount; i++) + { + Status = DtCompileTable (PFieldList, DataInfoTable, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + break; + } + } + + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileCpep + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile CPEP. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileCpep ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoCpep, AcpiDmTableInfoCpep0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileDmar + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile DMAR. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileDmar ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_DMTABLE_INFO *InfoTable; + ACPI_DMAR_HEADER *DmarHeader; + UINT8 *ReservedBuffer; + UINT32 ReservedSize; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoDmar, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + /* DMAR Reserved area */ + + ReservedSize = (UINT32) sizeof (((ACPI_TABLE_DMAR *) NULL)->Reserved); + ReservedBuffer = UtLocalCalloc (ReservedSize); + + DtCreateSubtable (ReservedBuffer, ReservedSize, &Subtable); + + ACPI_FREE (ReservedBuffer); + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + /* DMAR Header */ + + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoDmarHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + DmarHeader = ACPI_CAST_PTR (ACPI_DMAR_HEADER, Subtable->Buffer); + + switch (DmarHeader->Type) + { + case ACPI_DMAR_TYPE_HARDWARE_UNIT: + InfoTable = AcpiDmTableInfoDmar0; + break; + case ACPI_DMAR_TYPE_RESERVED_MEMORY: + InfoTable = AcpiDmTableInfoDmar1; + break; + case ACPI_DMAR_TYPE_ATSR: + InfoTable = AcpiDmTableInfoDmar2; + break; + case ACPI_DMAR_HARDWARE_AFFINITY: + InfoTable = AcpiDmTableInfoDmar3; + break; + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "DMAR"); + return (AE_ERROR); + } + + /* DMAR Subtable */ + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + /* Optional Device Scope subtables */ + + while (*PFieldList) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoDmarScope, + &Subtable, FALSE); + if (Status == AE_NOT_FOUND) + { + break; + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + /* Optional PCI Paths */ + + while (*PFieldList) + { + Status = DtCompileTable (PFieldList, TableInfoDmarPciPath, + &Subtable, FALSE); + if (Status == AE_NOT_FOUND) + { + DtPopSubtable (); + break; + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + } + } + + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileEinj + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile EINJ. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileEinj ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoEinj, AcpiDmTableInfoEinj0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileErst + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile ERST. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileErst ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoErst, AcpiDmTableInfoEinj0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileFadt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile FADT. + * + *****************************************************************************/ + +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 Revision; + + + 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); + Revision = Table->Revision; + + if (Revision == 2) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt2, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + else if (Revision >= 2) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt3, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + + if (Revision >= 5) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFadt5, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileFpdt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile FPDT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileFpdt ( + void **List) +{ + ACPI_STATUS Status; + ACPI_FPDT_HEADER *FpdtHeader; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + ACPI_DMTABLE_INFO *InfoTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoFpdtHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + FpdtHeader = ACPI_CAST_PTR (ACPI_FPDT_HEADER, Subtable->Buffer); + + switch (FpdtHeader->Type) + { + case ACPI_FPDT_TYPE_BOOT: + InfoTable = AcpiDmTableInfoFpdt0; + break; + + case ACPI_FPDT_TYPE_S3PERF: + InfoTable = AcpiDmTableInfoFpdt1; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "FPDT"); + return (AE_ERROR); + break; + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileHest + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile HEST. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileHest ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_DMTABLE_INFO *InfoTable; + UINT16 Type; + UINT32 BankCount; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoHest, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + /* Get subtable type */ + + SubtableStart = *PFieldList; + DtCompileInteger ((UINT8 *) &Type, *PFieldList, 2, 0); + + switch (Type) + { + case ACPI_HEST_TYPE_IA32_CHECK: + InfoTable = AcpiDmTableInfoHest0; + break; + + case ACPI_HEST_TYPE_IA32_CORRECTED_CHECK: + InfoTable = AcpiDmTableInfoHest1; + break; + + case ACPI_HEST_TYPE_IA32_NMI: + InfoTable = AcpiDmTableInfoHest2; + break; + + case ACPI_HEST_TYPE_AER_ROOT_PORT: + InfoTable = AcpiDmTableInfoHest6; + break; + + case ACPI_HEST_TYPE_AER_ENDPOINT: + InfoTable = AcpiDmTableInfoHest7; + break; + + case ACPI_HEST_TYPE_AER_BRIDGE: + InfoTable = AcpiDmTableInfoHest8; + break; + + case ACPI_HEST_TYPE_GENERIC_ERROR: + InfoTable = AcpiDmTableInfoHest9; + break; + + default: + /* Cannot continue on unknown type */ + + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "HEST"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + + /* + * Additional subtable data - IA32 Error Bank(s) + */ + BankCount = 0; + switch (Type) + { + case ACPI_HEST_TYPE_IA32_CHECK: + BankCount = (ACPI_CAST_PTR (ACPI_HEST_IA_MACHINE_CHECK, + Subtable->Buffer))->NumHardwareBanks; + break; + + case ACPI_HEST_TYPE_IA32_CORRECTED_CHECK: + BankCount = (ACPI_CAST_PTR (ACPI_HEST_IA_CORRECTED, + Subtable->Buffer))->NumHardwareBanks; + break; + + default: + break; + } + + while (BankCount) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoHestBank, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + BankCount--; + } + } + + return AE_OK; +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileIvrs + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile IVRS. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileIvrs ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_DMTABLE_INFO *InfoTable; + ACPI_IVRS_HEADER *IvrsHeader; + UINT8 EntryType; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoIvrs, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoIvrsHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + IvrsHeader = ACPI_CAST_PTR (ACPI_IVRS_HEADER, Subtable->Buffer); + + switch (IvrsHeader->Type) + { + case ACPI_IVRS_TYPE_HARDWARE: + InfoTable = AcpiDmTableInfoIvrs0; + break; + + case ACPI_IVRS_TYPE_MEMORY1: + case ACPI_IVRS_TYPE_MEMORY2: + case ACPI_IVRS_TYPE_MEMORY3: + InfoTable = AcpiDmTableInfoIvrs1; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "IVRS"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + if (IvrsHeader->Type == ACPI_IVRS_TYPE_HARDWARE) + { + while (*PFieldList && + !ACPI_STRCMP ((*PFieldList)->Name, "Entry Type")) + { + SubtableStart = *PFieldList; + DtCompileInteger (&EntryType, *PFieldList, 1, 0); + + switch (EntryType) + { + /* 4-byte device entries */ + + case ACPI_IVRS_TYPE_PAD4: + case ACPI_IVRS_TYPE_ALL: + case ACPI_IVRS_TYPE_SELECT: + case ACPI_IVRS_TYPE_START: + case ACPI_IVRS_TYPE_END: + + InfoTable = AcpiDmTableInfoIvrs4; + break; + + /* 8-byte entries, type A */ + + case ACPI_IVRS_TYPE_ALIAS_SELECT: + case ACPI_IVRS_TYPE_ALIAS_START: + + InfoTable = AcpiDmTableInfoIvrs8a; + break; + + /* 8-byte entries, type B */ + + case ACPI_IVRS_TYPE_PAD8: + case ACPI_IVRS_TYPE_EXT_SELECT: + case ACPI_IVRS_TYPE_EXT_START: + + InfoTable = AcpiDmTableInfoIvrs8b; + break; + + /* 8-byte entries, type C */ + + case ACPI_IVRS_TYPE_SPECIAL: + + InfoTable = AcpiDmTableInfoIvrs8c; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, + "IVRS Device Entry"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + } + } + + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileMadt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile MADT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileMadt ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_SUBTABLE_HEADER *MadtHeader; + ACPI_DMTABLE_INFO *InfoTable; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMadt, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMadtHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + MadtHeader = ACPI_CAST_PTR (ACPI_SUBTABLE_HEADER, Subtable->Buffer); + + switch (MadtHeader->Type) + { + case ACPI_MADT_TYPE_LOCAL_APIC: + InfoTable = AcpiDmTableInfoMadt0; + break; + case ACPI_MADT_TYPE_IO_APIC: + InfoTable = AcpiDmTableInfoMadt1; + break; + case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE: + InfoTable = AcpiDmTableInfoMadt2; + break; + case ACPI_MADT_TYPE_NMI_SOURCE: + InfoTable = AcpiDmTableInfoMadt3; + break; + case ACPI_MADT_TYPE_LOCAL_APIC_NMI: + InfoTable = AcpiDmTableInfoMadt4; + break; + case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: + InfoTable = AcpiDmTableInfoMadt5; + break; + case ACPI_MADT_TYPE_IO_SAPIC: + InfoTable = AcpiDmTableInfoMadt6; + break; + case ACPI_MADT_TYPE_LOCAL_SAPIC: + InfoTable = AcpiDmTableInfoMadt7; + break; + case ACPI_MADT_TYPE_INTERRUPT_SOURCE: + InfoTable = AcpiDmTableInfoMadt8; + break; + case ACPI_MADT_TYPE_LOCAL_X2APIC: + InfoTable = AcpiDmTableInfoMadt9; + break; + case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI: + InfoTable = AcpiDmTableInfoMadt10; + break; + case ACPI_MADT_TYPE_GENERIC_INTERRUPT: + InfoTable = AcpiDmTableInfoMadt11; + break; + case ACPI_MADT_TYPE_GENERIC_DISTRIBUTOR: + InfoTable = AcpiDmTableInfoMadt12; + break; + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "MADT"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileMcfg + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile MCFG. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileMcfg ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoMcfg, AcpiDmTableInfoMcfg0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileMpst + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile MPST. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileMpst ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + ACPI_MPST_CHANNEL *MpstChannelInfo; + ACPI_MPST_POWER_NODE *MpstPowerNode; + ACPI_MPST_DATA_HDR *MpstDataHeader; + UINT16 SubtableCount; + UINT8 PowerStateCount; + UINT8 ComponentCount; + + + /* Main table */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMpst, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + MpstChannelInfo = ACPI_CAST_PTR (ACPI_MPST_CHANNEL, Subtable->Buffer); + SubtableCount = MpstChannelInfo->PowerNodeCount; + + while (*PFieldList && SubtableCount) + { + /* Subtable: Memory Power Node(s) */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMpst0, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + MpstPowerNode = ACPI_CAST_PTR (ACPI_MPST_POWER_NODE, Subtable->Buffer); + PowerStateCount = MpstPowerNode->NumPowerStates; + ComponentCount = MpstPowerNode->NumPhysicalComponents; + + ParentTable = DtPeekSubtable (); + + /* Sub-subtables - Memory Power State Structure(s) */ + + while (*PFieldList && PowerStateCount) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMpst0A, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + PowerStateCount--; + } + + /* Sub-subtables - Physical Component ID Structure(s) */ + + while (*PFieldList && ComponentCount) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMpst0B, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + ComponentCount--; + } + + SubtableCount--; + DtPopSubtable (); + } + + /* Subtable: Count of Memory Power State Characteristic structures */ + + DtPopSubtable (); + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMpst1, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + MpstDataHeader = ACPI_CAST_PTR (ACPI_MPST_DATA_HDR, Subtable->Buffer); + SubtableCount = MpstDataHeader->CharacteristicsCount; + + ParentTable = DtPeekSubtable (); + + /* Subtable: Memory Power State Characteristics structure(s) */ + + while (*PFieldList && SubtableCount) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoMpst2, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + SubtableCount--; + } + + DtPopSubtable (); + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileMsct + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile MSCT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileMsct ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoMsct, AcpiDmTableInfoMsct0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompilePmtt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile PMTT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompilePmtt ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_PMTT_HEADER *PmttHeader; + ACPI_PMTT_CONTROLLER *PmttController; + UINT16 DomainCount; + UINT8 PrevType = ACPI_PMTT_TYPE_SOCKET; + + + /* Main table */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoPmtt, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoPmttHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + PmttHeader = ACPI_CAST_PTR (ACPI_PMTT_HEADER, Subtable->Buffer); + while (PrevType >= PmttHeader->Type) + { + DtPopSubtable (); + + if (PrevType == ACPI_PMTT_TYPE_SOCKET) + { + break; + } + PrevType--; + } + PrevType = PmttHeader->Type; + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + switch (PmttHeader->Type) + { + case ACPI_PMTT_TYPE_SOCKET: + + /* Subtable: Socket Structure */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoPmtt0, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + break; + + case ACPI_PMTT_TYPE_CONTROLLER: + + /* Subtable: Memory Controller Structure */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoPmtt1, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + PmttController = ACPI_CAST_PTR (ACPI_PMTT_CONTROLLER, + (Subtable->Buffer - sizeof (ACPI_PMTT_HEADER))); + DomainCount = PmttController->DomainCount; + + while (DomainCount) + { + Status = DtCompileTable (PFieldList, AcpiDmTableInfoPmtt1a, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtInsertSubtable (ParentTable, Subtable); + DomainCount--; + } + break; + + case ACPI_PMTT_TYPE_DIMM: + + /* Subtable: Physical Component Structure */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoPmtt2, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + break; + + default: + + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "PMTT"); + return (AE_ERROR); + } + } + + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileRsdt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile RSDT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileRsdt ( + void **List) +{ + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD *FieldList = *(DT_FIELD **) List; + UINT32 Address; + + + ParentTable = DtPeekSubtable (); + + while (FieldList) + { + DtCompileInteger ((UINT8 *) &Address, FieldList, 4, DT_NON_ZERO); + + DtCreateSubtable ((UINT8 *) &Address, 4, &Subtable); + DtInsertSubtable (ParentTable, Subtable); + FieldList = FieldList->Next; + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileS3pt + * + * PARAMETERS: PFieldList - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile S3PT (Pointed to by FPDT) + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileS3pt ( + DT_FIELD **PFieldList) +{ + ACPI_STATUS Status; + ACPI_S3PT_HEADER *S3ptHeader; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + ACPI_DMTABLE_INFO *InfoTable; + DT_FIELD *SubtableStart; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoS3pt, + &Gbl_RootTable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DtPushSubtable (Gbl_RootTable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoS3ptHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + S3ptHeader = ACPI_CAST_PTR (ACPI_S3PT_HEADER, Subtable->Buffer); + + switch (S3ptHeader->Type) + { + case ACPI_S3PT_TYPE_RESUME: + InfoTable = AcpiDmTableInfoS3pt0; + break; + + case ACPI_S3PT_TYPE_SUSPEND: + InfoTable = AcpiDmTableInfoS3pt1; + break; + + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "S3PT"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileSlic + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile SLIC. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileSlic ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_SLIC_HEADER *SlicHeader; + ACPI_DMTABLE_INFO *InfoTable; + + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoSlicHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + SlicHeader = ACPI_CAST_PTR (ACPI_SLIC_HEADER, Subtable->Buffer); + + switch (SlicHeader->Type) + { + case ACPI_SLIC_TYPE_PUBLIC_KEY: + InfoTable = AcpiDmTableInfoSlic0; + break; + case ACPI_SLIC_TYPE_WINDOWS_MARKER: + InfoTable = AcpiDmTableInfoSlic1; + break; + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "SLIC"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileSlit + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile SLIT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileSlit ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *FieldList; + UINT32 Localities; + UINT8 *LocalityBuffer; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoSlit, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + Localities = *ACPI_CAST_PTR (UINT32, Subtable->Buffer); + LocalityBuffer = UtLocalCalloc (Localities); + + /* Compile each locality buffer */ + + FieldList = *PFieldList; + while (FieldList) + { + DtCompileBuffer (LocalityBuffer, + FieldList->Value, FieldList, Localities); + + DtCreateSubtable (LocalityBuffer, Localities, &Subtable); + DtInsertSubtable (ParentTable, Subtable); + FieldList = FieldList->Next; + } + + ACPI_FREE (LocalityBuffer); + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileSrat + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile SRAT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileSrat ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + DT_FIELD *SubtableStart; + ACPI_SUBTABLE_HEADER *SratHeader; + ACPI_DMTABLE_INFO *InfoTable; + + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoSrat, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + while (*PFieldList) + { + SubtableStart = *PFieldList; + Status = DtCompileTable (PFieldList, AcpiDmTableInfoSratHdr, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPushSubtable (Subtable); + + SratHeader = ACPI_CAST_PTR (ACPI_SUBTABLE_HEADER, Subtable->Buffer); + + switch (SratHeader->Type) + { + case ACPI_SRAT_TYPE_CPU_AFFINITY: + InfoTable = AcpiDmTableInfoSrat0; + break; + case ACPI_SRAT_TYPE_MEMORY_AFFINITY: + InfoTable = AcpiDmTableInfoSrat1; + break; + case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: + InfoTable = AcpiDmTableInfoSrat2; + break; + default: + DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, SubtableStart, "SRAT"); + return (AE_ERROR); + } + + Status = DtCompileTable (PFieldList, InfoTable, &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + DtPopSubtable (); + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetGenericTableInfo + * + * PARAMETERS: Name - Generic type name + * + * RETURN: Info entry + * + * DESCRIPTION: Obtain table info for a generic name entry + * + *****************************************************************************/ + +ACPI_DMTABLE_INFO * +DtGetGenericTableInfo ( + char *Name) +{ + ACPI_DMTABLE_INFO *Info; + UINT32 i; + + + if (!Name) + { + return (NULL); + } + + /* Search info table for name match */ + + for (i = 0; ; i++) + { + Info = AcpiDmTableInfoGeneric[i]; + if (Info->Opcode == ACPI_DMT_EXIT) + { + Info = NULL; + break; + } + + /* Use caseless compare for generic keywords */ + + if (!AcpiUtStricmp (Name, Info->Name)) + { + break; + } + } + + return (Info); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileUefi + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile UEFI. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileUefi ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + UINT16 *DataOffset; + + + /* Compile the predefined portion of the UEFI table */ + + Status = DtCompileTable (PFieldList, AcpiDmTableInfoUefi, + &Subtable, TRUE); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + DataOffset = (UINT16 *) (Subtable->Buffer + 16); + *DataOffset = sizeof (ACPI_TABLE_UEFI); + + ParentTable = DtPeekSubtable (); + DtInsertSubtable (ParentTable, Subtable); + + /* + * Compile the "generic" portion of the UEFI table. This + * part of the table is not predefined and any of the generic + * operators may be used. + */ + + DtCompileGeneric ((void **) PFieldList); + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileWdat + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile WDAT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileWdat ( + void **List) +{ + ACPI_STATUS Status; + + + Status = DtCompileTwoSubtables (List, + AcpiDmTableInfoWdat, AcpiDmTableInfoWdat0); + return (Status); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileXsdt + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile XSDT. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileXsdt ( + void **List) +{ + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD *FieldList = *(DT_FIELD **) List; + UINT64 Address; + + ParentTable = DtPeekSubtable (); + + while (FieldList) + { + DtCompileInteger ((UINT8 *) &Address, FieldList, 8, DT_NON_ZERO); + + DtCreateSubtable ((UINT8 *) &Address, 8, &Subtable); + DtInsertSubtable (ParentTable, Subtable); + FieldList = FieldList->Next; + } + + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtCompileGeneric + * + * PARAMETERS: List - Current field list pointer + * + * RETURN: Status + * + * DESCRIPTION: Compile generic unknown table. + * + *****************************************************************************/ + +ACPI_STATUS +DtCompileGeneric ( + void **List) +{ + ACPI_STATUS Status; + DT_SUBTABLE *Subtable; + DT_SUBTABLE *ParentTable; + DT_FIELD **PFieldList = (DT_FIELD **) List; + ACPI_DMTABLE_INFO *Info; + + + ParentTable = DtPeekSubtable (); + + /* + * Compile the "generic" portion of the table. This + * part of the table is not predefined and any of the generic + * operators may be used. + */ + + /* Find any and all labels in the entire generic portion */ + + DtDetectAllLabels (*PFieldList); + + /* Now we can actually compile the parse tree */ + + while (*PFieldList) + { + Info = DtGetGenericTableInfo ((*PFieldList)->Name); + if (!Info) + { + sprintf (MsgBuffer, "Generic data type \"%s\" not found", + (*PFieldList)->Name); + DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME, + (*PFieldList), MsgBuffer); + + *PFieldList = (*PFieldList)->Next; + continue; + } + + Status = DtCompileTable (PFieldList, Info, + &Subtable, TRUE); + if (ACPI_SUCCESS (Status)) + { + DtInsertSubtable (ParentTable, Subtable); + } + else + { + *PFieldList = (*PFieldList)->Next; + + if (Status == AE_NOT_FOUND) + { + sprintf (MsgBuffer, "Generic data type \"%s\" not found", + (*PFieldList)->Name); + DtNameError (ASL_ERROR, ASL_MSG_INVALID_FIELD_NAME, + (*PFieldList), MsgBuffer); + } + } + } + + return (AE_OK); +} diff --git a/sys/contrib/dev/acpica/compiler/dttemplate.c b/sys/contrib/dev/acpica/compiler/dttemplate.c new file mode 100644 index 0000000..0c35280 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dttemplate.c @@ -0,0 +1,374 @@ +/****************************************************************************** + * + * Module Name: dttemplate - ACPI table template generation + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/include/acapps.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> +#include <contrib/dev/acpica/compiler/dttemplate.h> /* Contains the hex ACPI table templates */ + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dttemplate") + + +/* Local prototypes */ + +static BOOLEAN +AcpiUtIsSpecialTable ( + char *Signature); + +static ACPI_STATUS +DtCreateOneTemplate ( + char *Signature, + ACPI_DMTABLE_DATA *TableData); + +static ACPI_STATUS +DtCreateAllTemplates ( + void); + + +/******************************************************************************* + * + * FUNCTION: AcpiUtIsSpecialTable + * + * PARAMETERS: Signature - ACPI table signature + * + * RETURN: TRUE if signature is a special ACPI table + * + * DESCRIPTION: Check for valid ACPI tables that are not in the main ACPI + * table data structure (AcpiDmTableData). + * + ******************************************************************************/ + +static BOOLEAN +AcpiUtIsSpecialTable ( + char *Signature) +{ + + if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT) || + ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT) || + ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS) || + ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME)) + { + return (TRUE); + } + + return (FALSE); +} + + +/******************************************************************************* + * + * FUNCTION: DtCreateTemplates + * + * PARAMETERS: Signature - ACPI table signature + * + * RETURN: Status + * + * DESCRIPTION: Create one or more template files. + * + ******************************************************************************/ + +ACPI_STATUS +DtCreateTemplates ( + char *Signature) +{ + ACPI_DMTABLE_DATA *TableData; + ACPI_STATUS Status; + + + AslInitializeGlobals (); + AcpiUtStrupr (Signature); + + /* Create all known templates if requested */ + + if (!ACPI_STRNCMP (Signature, "ALL", 3) || + !ACPI_STRCMP (Signature, "*")) + { + Status = DtCreateAllTemplates (); + return (Status); + } + + /* + * Validate signature and get the template data: + * 1) Signature must be 4 characters + * 2) Signature must be a recognized ACPI table + * 3) There must be a template associated with the signature + */ + if (strlen (Signature) != ACPI_NAME_SIZE) + { + fprintf (stderr, "%s, Invalid ACPI table signature\n", Signature); + return (AE_ERROR); + } + + /* + * Some slack for the two strange tables whose name is different than + * their signatures: MADT->APIC and FADT->FACP. + */ + if (!strcmp (Signature, "MADT")) + { + Signature = "APIC"; + } + else if (!strcmp (Signature, "FADT")) + { + Signature = "FACP"; + } + + TableData = AcpiDmGetTableData (Signature); + if (TableData) + { + if (!TableData->Template) + { + fprintf (stderr, "%4.4s, No template available\n", Signature); + return (AE_ERROR); + } + } + else if (!AcpiUtIsSpecialTable (Signature)) + { + fprintf (stderr, + "%4.4s, Unrecognized ACPI table signature\n", Signature); + return (AE_ERROR); + } + + Status = AdInitialize (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Status = DtCreateOneTemplate (Signature, TableData); + return (Status); +} + + +/******************************************************************************* + * + * FUNCTION: DtCreateAllTemplates + * + * PARAMETERS: None + * + * RETURN: Status + * + * DESCRIPTION: Create all currently defined template files + * + ******************************************************************************/ + +static ACPI_STATUS +DtCreateAllTemplates ( + void) +{ + ACPI_DMTABLE_DATA *TableData; + ACPI_STATUS Status; + + + Status = AdInitialize (); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + fprintf (stderr, "Creating all supported Template files\n"); + + /* Walk entire ACPI table data structure */ + + for (TableData = AcpiDmTableData; TableData->Signature; TableData++) + { + /* If table has a template, create the template file */ + + if (TableData->Template) + { + Status = DtCreateOneTemplate (TableData->Signature, + TableData); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + } + } + + /* + * Create the "special ACPI tables: + * 1) DSDT/SSDT are AML tables, not data tables + * 2) FACS and RSDP have non-standard headers + */ + Status = DtCreateOneTemplate (ACPI_SIG_DSDT, NULL); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Status = DtCreateOneTemplate (ACPI_SIG_SSDT, NULL); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Status = DtCreateOneTemplate (ACPI_SIG_FACS, NULL); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + Status = DtCreateOneTemplate (ACPI_RSDP_NAME, NULL); + if (ACPI_FAILURE (Status)) + { + return (Status); + } + + return (AE_OK); +} + + +/******************************************************************************* + * + * FUNCTION: DtCreateOneTemplate + * + * PARAMETERS: Signature - ACPI signature, NULL terminated. + * TableData - Entry in ACPI table data structure. + * NULL if a special ACPI table. + * + * RETURN: Status + * + * DESCRIPTION: Create one template source file for the requested ACPI table. + * + ******************************************************************************/ + +static ACPI_STATUS +DtCreateOneTemplate ( + char *Signature, + ACPI_DMTABLE_DATA *TableData) +{ + char *DisasmFilename; + FILE *File; + ACPI_STATUS Status = AE_OK; + + + /* New file will have a .asl suffix */ + + DisasmFilename = FlGenerateFilename ( + Signature, FILE_SUFFIX_ASL_CODE); + if (!DisasmFilename) + { + fprintf (stderr, "Could not generate output filename\n"); + return (AE_ERROR); + } + + /* Probably should prompt to overwrite the file */ + + AcpiUtStrlwr (DisasmFilename); + File = fopen (DisasmFilename, "w+"); + if (!File) + { + fprintf (stderr, "Could not open output file %s\n", DisasmFilename); + return (AE_ERROR); + } + + /* Emit the common file header */ + + AcpiOsRedirectOutput (File); + + AcpiOsPrintf ("/*\n"); + AcpiOsPrintf (ACPI_COMMON_HEADER ("iASL Compiler/Disassembler", " * ")); + + AcpiOsPrintf (" * Template for [%4.4s] ACPI Table\n", + Signature); + + /* Dump the actual ACPI table */ + + if (TableData) + { + /* Normal case, tables that appear in AcpiDmTableData */ + + if (Gbl_VerboseTemplates) + { + AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]" + " FieldName : HexFieldValue\n */\n\n"); + } + else + { + AcpiOsPrintf (" * Format: [ByteLength]" + " FieldName : HexFieldValue\n */\n\n"); + } + + AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, + TableData->Template)); + } + else + { + /* Special ACPI tables - DSDT, SSDT, FACS, RSDP */ + + AcpiOsPrintf (" */\n\n"); + if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_DSDT)) + { + fwrite (TemplateDsdt, sizeof (TemplateDsdt) -1, 1, File); + } + else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_SSDT)) + { + fwrite (TemplateSsdt, sizeof (TemplateSsdt) -1, 1, File); + } + else if (ACPI_COMPARE_NAME (Signature, ACPI_SIG_FACS)) + { + AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, + TemplateFacs)); + } + else if (ACPI_COMPARE_NAME (Signature, ACPI_RSDP_NAME)) + { + AcpiDmDumpDataTable (ACPI_CAST_PTR (ACPI_TABLE_HEADER, + TemplateRsdp)); + } + else + { + fprintf (stderr, + "%4.4s, Unrecognized ACPI table signature\n", Signature); + return (AE_ERROR); + } + } + + fprintf (stderr, + "Created ACPI table template for [%4.4s], written to \"%s\"\n", + Signature, DisasmFilename); + + fclose (File); + AcpiOsRedirectOutput (stdout); + ACPI_FREE (DisasmFilename); + return (Status); +} diff --git a/sys/contrib/dev/acpica/compiler/dttemplate.h b/sys/contrib/dev/acpica/compiler/dttemplate.h new file mode 100644 index 0000000..4d43704 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dttemplate.h @@ -0,0 +1,897 @@ +/****************************************************************************** + * + * Module Name: dttemplate.h - ACPI table template definitions + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#ifndef __DTTEMPLATE_H +#define __DTTEMPLATE_H + + +/* Special templates for DSDT and SSDT (AML byte-code tables) */ + +const char TemplateDsdt[] = + "DefinitionBlock (\"dsdt.aml\", \"DSDT\", 2, \"Intel\", \"Template\", 0x00000001)\n" + "{\n" + " Method (MAIN, 0, NotSerialized)\n" + " {\n" + " Return (Zero)\n" + " }\n" + "}\n\n"; + +const char TemplateSsdt[] = + "DefinitionBlock (\"ssdt.aml\", \"SSDT\", 2, \"Intel\", \"Template\", 0x00000001)\n" + "{\n" + " Method (MAIN, 0, NotSerialized)\n" + " {\n" + " Return (Zero)\n" + " }\n" + "}\n\n"; + + +/* Templates for ACPI data tables */ + +const unsigned char TemplateAsf[] = +{ + 0x41,0x53,0x46,0x21,0x72,0x00,0x00,0x00, /* 00000000 "ASF!r..." */ + 0x10,0x0B,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x10,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x14,0x00, /* 00000030 "........" */ + 0x00,0x00,0x01,0x0C,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x02,0x00,0x0C,0x00,0x01,0x04,0x00,0x00, /* 00000048 "........" */ + 0x00,0x00,0x00,0x00,0x03,0x00,0x17,0x00, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x84,0x00,0x07,0x00,0x00, /* 00000068 "........" */ + 0x01,0x00 /* 00000070 ".." */ +}; + +const unsigned char TemplateBgrt[] = +{ + 0x42,0x47,0x52,0x54,0x38,0x00,0x00,0x00, /* 00000000 "BGRT8..." */ + 0x01,0x0D,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x23,0x06,0x11,0x20,0x01,0x00,0x00,0x00, /* 00000020 "#.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000030 "........" */ +}; + +const unsigned char TemplateBert[] = +{ + 0x42,0x45,0x52,0x54,0x30,0x00,0x00,0x00, /* 00000000 "BERT0..." */ + 0x01,0x15,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000028 "........" */ +}; + +const unsigned char TemplateBoot[] = +{ + 0x42,0x4F,0x4F,0x54,0x28,0x00,0x00,0x00, /* 00000000 "BOOT(..." */ + 0x01,0x0D,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x04,0x06,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00 /* 00000020 "(.. ...." */ +}; + +const unsigned char TemplateCpep[] = +{ + 0x43,0x50,0x45,0x50,0x34,0x00,0x00,0x00, /* 00000000 "CPEP4..." */ + 0x01,0x0F,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00 /* 00000030 "...." */ +}; + +const unsigned char TemplateDbgp[] = +{ + 0x44,0x42,0x47,0x50,0x34,0x00,0x00,0x00, /* 00000000 "DBGP4..." */ + 0x01,0x1A,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00 /* 00000030 "...." */ +}; + +const unsigned char TemplateDmar[] = +{ + 0x44,0x4D,0x41,0x52,0x8C,0x00,0x00,0x00, /* 00000000 "DMAR...." */ + 0x01,0x15,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x2F,0x01,0x00,0x00, /* 00000020 "(.. /..." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x18,0x00,0x01,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x02,0xFD,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x03,0x08,0x00,0x00,0x08,0xF0,0x1F,0x07, /* 00000040 "........" */ + 0x01,0x00,0x20,0x00,0x00,0x00,0x00,0x00, /* 00000048 ".. ....." */ + 0x00,0x10,0xC2,0x78,0x00,0x00,0x00,0x00, /* 00000050 "...x...." */ + 0xFF,0x3F,0xC2,0x78,0x00,0x00,0x00,0x00, /* 00000058 ".?.x...." */ + 0x01,0x08,0x00,0x00,0x00,0x00,0x1D,0x00, /* 00000060 "........" */ + 0x02,0x00,0x10,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x02,0x08,0x00,0x00,0x00,0x00,0x01,0x00, /* 00000070 "........" */ + 0x03,0x00,0x14,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x02,0xFD,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0x00,0x00,0x00,0x00 /* 00000088 "...." */ +}; + +const unsigned char TemplateEcdt[] = +{ + 0x45,0x43,0x44,0x54,0x42,0x00,0x00,0x00, /* 00000000 "ECDTB..." */ + 0x01,0x2D,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 ".-INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x01,0x08,0x00,0x00, /* 00000020 "(.. ...." */ + 0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "f......." */ + 0x01,0x08,0x00,0x00,0x62,0x00,0x00,0x00, /* 00000030 "....b..." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x09,0x00 /* 00000040 ".." */ +}; + +const unsigned char TemplateEinj[] = +{ + 0x45,0x49,0x4E,0x4A,0x30,0x01,0x00,0x00, /* 00000000 "EINJ0..." */ + 0x01,0x09,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x30,0x00,0x00,0x00, /* 00000020 "(.. 0..." */ + 0x00,0x00,0x00,0x00,0x0A,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000030 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000048 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000050 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000068 "........" */ + 0x02,0x02,0x01,0x00,0x00,0x40,0x00,0x04, /* 00000070 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000088 "........" */ + 0x03,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000090 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000000A8 "........" */ + 0x04,0x03,0x01,0x00,0x00,0x40,0x00,0x04, /* 000000B0 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000C0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000000C8 "........" */ + 0x05,0x03,0x01,0x00,0x01,0x10,0x00,0x02, /* 000000D0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000D8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000000E8 "........" */ + 0x06,0x01,0x00,0x00,0x00,0x40,0x00,0x04, /* 000000F0 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000100 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000108 "........" */ + 0x07,0x00,0x01,0x00,0x00,0x40,0x00,0x04, /* 00000110 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000118 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000120 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF /* 00000128 "........" */ +}; + +const unsigned char TemplateErst[] = +{ + 0x45,0x52,0x53,0x54,0x30,0x02,0x00,0x00, /* 00000000 "ERST0..." */ + 0x01,0xAB,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x30,0x00,0x00,0x00, /* 00000020 "(.. 0..." */ + 0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x03,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000030 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000048 "........" */ + 0x01,0x03,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000050 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000068 "........" */ + 0x02,0x03,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000070 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000088 "........" */ + 0x03,0x04,0x01,0x00,0x00,0x40,0x00,0x04, /* 00000090 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000000A8 "........" */ + 0x04,0x02,0x00,0x00,0x00,0x40,0x00,0x04, /* 000000B0 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000C0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000000C8 "........" */ + 0x05,0x03,0x00,0x00,0x01,0x08,0x00,0x01, /* 000000D0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000D8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000000E8 "........" */ + 0x06,0x01,0x00,0x00,0x00,0x40,0x00,0x04, /* 000000F0 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000100 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000108 "........" */ + 0x07,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000110 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000118 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000120 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000128 "........" */ + 0x08,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000130 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000138 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000140 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000148 "........" */ + 0x09,0x02,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000150 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000158 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000160 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000168 "........" */ + 0x0A,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000170 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000178 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000180 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000188 "........" */ + 0x0B,0x03,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000190 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000198 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001A0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000001A8 "........" */ + 0x0C,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 000001B0 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001B8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001C0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000001C8 "........" */ + 0x0D,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 000001D0 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001D8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001E0 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 000001E8 "........" */ + 0x0E,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 000001F0 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001F8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000200 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* 00000208 "........" */ + 0x0F,0x00,0x00,0x00,0x00,0x40,0x00,0x04, /* 00000210 ".....@.." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000218 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000220 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF /* 00000228 "........" */ +}; + +const unsigned char TemplateFacs[] = +{ + 0x46,0x41,0x43,0x53,0x40,0x00,0x00,0x00, /* 00000000 "FACS@..." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000008 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000010 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000018 "........" */ + 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000020 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000038 "........" */ +}; + +/* Version 5 FADT */ + +const unsigned char TemplateFadt[] = +{ + 0x46,0x41,0x43,0x50,0x0C,0x01,0x00,0x00, /* 00000000 "FACP...." */ + 0x05,0x18,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x23,0x11,0x11,0x20,0x01,0x00,0x00,0x00, /* 00000020 "#.. ...." */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000048 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000050 "........" */ + 0x04,0x02,0x01,0x04,0x08,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x08,0x00,0x01, /* 00000070 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000080 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000088 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x20,0x00,0x02, /* 00000090 "..... .." */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x10,0x00,0x02, /* 000000A8 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B0 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B8 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x08,0x00,0x00, /* 000000C0 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000C8 "........" */ + 0x01,0x20,0x00,0x03,0x01,0x00,0x00,0x00, /* 000000D0 ". ......" */ + 0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x01, /* 000000D8 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E8 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x08,0x00,0x01, /* 000000F0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F8 "........" */ + 0x01,0x08,0x00,0x01,0x00,0x00,0x00,0x00, /* 00000100 "........" */ + 0x00,0x00,0x00,0x00 /* 00000108 "...." */ +}; + +const unsigned char TemplateFpdt[] = +{ + 0x46,0x50,0x44,0x54,0x64,0x00,0x00,0x00, /* 00000000 "FPDTd..." */ + 0x01,0xBD,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x04,0x08,0x11,0x20,0x00,0x00,0x30,0x01, /* 00000020 "... ..0." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000048 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x10,0x01, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00 /* 00000060 "...." */ +}; + +const unsigned char TemplateGtdt[] = +{ + 0x47,0x54,0x44,0x54,0x50,0x00,0x00,0x00, /* 00000000 "GTDTP..." */ + 0x01,0xF1,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x23,0x06,0x11,0x20,0x00,0x00,0x00,0x00, /* 00000020 "#.. ...." */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000048 "........" */ +}; + +const unsigned char TemplateHest[] = +{ + 0x48,0x45,0x53,0x54,0xD4,0x01,0x00,0x00, /* 00000000 "HEST...." */ + 0x01,0x20,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 ". INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x04,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01, /* 00000028 "........" */ + 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000048 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000070 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0x01,0x00,0x01,0x00,0x00,0x00,0x00,0x01, /* 00000088 "........" */ + 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000090 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A8 "........" */ + 0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00, /* 000000B0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000C0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000C8 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 000000D0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000D8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E8 "........" */ + 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x01, /* 000000F0 "........" */ + 0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 000000F8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000100 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000108 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000110 "........" */ + 0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00, /* 00000118 "........" */ + 0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00, /* 00000120 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000128 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000130 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000138 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000140 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000148 "........" */ + 0x00,0x00,0x00,0x00,0x09,0x00,0x02,0x00, /* 00000150 "........" */ + 0xFF,0xFF,0x00,0x01,0x01,0x00,0x00,0x00, /* 00000158 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x10,0x00,0x00, /* 00000160 "........" */ + 0x00,0x40,0x00,0x04,0x00,0x00,0x00,0x00, /* 00000168 ".@......" */ + 0x00,0x00,0x00,0x00,0x03,0x1C,0x00,0x00, /* 00000170 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000178 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000180 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000188 "........" */ + 0x00,0x10,0x00,0x00,0x09,0x00,0x03,0x00, /* 00000190 "........" */ + 0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00, /* 00000198 "........" */ + 0x01,0x00,0x00,0x00,0x00,0x10,0x00,0x00, /* 000001A0 "........" */ + 0x00,0x40,0x00,0x04,0x00,0x00,0x00,0x00, /* 000001A8 ".@......" */ + 0x00,0x00,0x00,0x00,0x04,0x1C,0x00,0x00, /* 000001B0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001B8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001C0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000001C8 "........" */ + 0x00,0x10,0x00,0x00 /* 000001D0 "...." */ +}; + +const unsigned char TemplateHpet[] = +{ + 0x48,0x50,0x45,0x54,0x38,0x00,0x00,0x00, /* 00000000 "HPET8..." */ + 0x01,0x09,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000030 "........" */ +}; + +const unsigned char TemplateIvrs[] = +{ + 0x49,0x56,0x52,0x53,0xBC,0x00,0x00,0x00, /* 00000000 "IVRS...." */ + 0x01,0x87,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x10,0x14,0x34,0x00,0x00,0x00,0x00,0x00, /* 00000030 "..4....." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00, /* 00000048 "....@..." */ + 0x00,0x00,0x00,0x00,0x42,0x00,0x00,0x00, /* 00000050 "....B..." */ + 0x00,0x00,0x00,0x00,0x48,0x00,0x00,0x00, /* 00000058 "....H..." */ + 0x00,0x00,0x00,0x00,0x20,0x08,0x20,0x00, /* 00000060 ".... . ." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000070 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x21,0x04,0x20,0x00, /* 00000080 "....!. ." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000088 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000090 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x00,0x00,0x00,0x00,0x10,0x14,0x18,0x00, /* 000000A0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B0 "........" */ + 0x00,0x00,0x00,0x00 /* 000000B8 "...." */ +}; + +/* MADT with ACPI 5.0 subtables */ + +const unsigned char TemplateMadt[] = +{ + 0x41,0x50,0x49,0x43,0xF6,0x00,0x00,0x00, /* 00000000 "APIC...." */ + 0x01,0xB0,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x23,0x06,0x11,0x20,0x00,0x00,0x00,0x00, /* 00000020 "#.. ...." */ + 0x01,0x00,0x00,0x00,0x00,0x08,0x00,0x00, /* 00000028 "........" */ + 0x01,0x00,0x00,0x00,0x01,0x0C,0x01,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x02,0x0A,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x03,0x08,0x0D,0x00,0x01,0x00, /* 00000048 "........" */ + 0x00,0x00,0x04,0x06,0x00,0x05,0x00,0x01, /* 00000050 "........" */ + 0x05,0x0C,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x06,0x10,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x07,0x16,0x00,0x00, /* 00000070 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x5C,0x43,0x50,0x55, /* 00000080 "....\CPU" */ + 0x30,0x00,0x08,0x10,0x05,0x00,0x00,0x00, /* 00000088 "0......." */ + 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00, /* 00000090 "........" */ + 0x00,0x00,0x09,0x10,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0x00,0x00,0x0A,0x0C,0x05,0x00,0x00,0x00, /* 000000A8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x28, /* 000000B0 ".......(" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B8 "........" */ + 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, /* 000000C0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000C8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000D0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x18, /* 000000D8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00 /* 000000F0 "......" */ +}; + +const unsigned char TemplateMcfg[] = +{ + 0x4D,0x43,0x46,0x47,0x3C,0x00,0x00,0x00, /* 00000000 "MCFG<..." */ + 0x01,0x19,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00 /* 00000038 "...." */ +}; + +const unsigned char TemplateMchi[] = +{ + 0x4D,0x43,0x48,0x49,0x45,0x00,0x00,0x00, /* 00000000 "MCHIE..." */ + 0x01,0xE4,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x15,0x07,0x00,0x02,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x01,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x02,0x08,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00 /* 00000040 "....." */ +}; + +const unsigned char TemplateMpst[] = +{ + 0x4D,0x50,0x53,0x54,0x6E,0x00,0x00,0x00, /* 00000000 "MPSTn..." */ + 0x01,0x98,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x04,0x08,0x11,0x20,0x00,0x00,0x00,0x00, /* 00000020 "... ...." */ + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x02,0x03,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000048 "........" */ + 0x01,0x00,0x41,0x00,0x00,0x00,0x00,0x00, /* 00000050 "..A....." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00 /* 00000068 "......" */ +}; + +const unsigned char TemplateMsct[] = +{ + 0x4D,0x53,0x43,0x54,0x90,0x00,0x00,0x00, /* 00000000 "MSCT...." */ + 0x01,0xB7,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x38,0x00,0x00,0x00, /* 00000020 "(.. 8..." */ + 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0xFF,0xFF,0xFF,0xFF,0xFF,0x0F,0x00,0x00, /* 00000030 "........" */ + 0x01,0x16,0x00,0x00,0x00,0x00,0x03,0x00, /* 00000038 "........" */ + 0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x40,0x00,0x00,0x00,0x01,0x16, /* 00000048 "..@....." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x16,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000070 "........" */ + 0x00,0x00,0x01,0x16,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000088 "........" */ +}; + +const unsigned char TemplatePmtt[] = +{ + 0x50,0x4D,0x54,0x54,0xB4,0x00,0x00,0x00, /* 00000000 "PMTT...." */ + 0x01,0x3A,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 ".:INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x26,0x08,0x11,0x20,0x00,0x00,0x00,0x00, /* 00000020 "&.. ...." */ + 0x00,0x00,0x80,0x00,0x01,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x54,0x00, /* 00000030 "......T." */ + 0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000048 "........" */ + 0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x02,0x00,0x14,0x00,0x02,0x00,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x02,0x00,0x14,0x00, /* 00000070 "........" */ + 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0x01,0x00,0x20,0x00,0x01,0x00,0x00,0x00, /* 00000088 ".. ....." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000090 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0x00,0x00,0x0C,0x00,0x01,0x00,0x00,0x00, /* 000000A8 "........" */ + 0x00,0x00,0x00,0x00 /* 000000B0 "...." */ +}; + +const unsigned char TemplateRsdp[] = +{ + 0x52,0x53,0x44,0x20,0x50,0x54,0x52,0x20, /* 00000000 "RSD PTR " */ + 0x43,0x49,0x4E,0x54,0x45,0x4C,0x20,0x02, /* 00000008 "CINTEL ." */ + 0x00,0x00,0x00,0x00,0x24,0x00,0x00,0x00, /* 00000010 "....$..." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000018 "........" */ + 0xDC,0x00,0x00,0x00 /* 00000020 "...." */ +}; + +const unsigned char TemplateRsdt[] = +{ + 0x52,0x53,0x44,0x54,0x44,0x00,0x00,0x00, /* 00000000 "RSDTD..." */ + 0x01,0xB1,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x10,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x20,0x00,0x00,0x00,0x30,0x00,0x00,0x00, /* 00000028 " ...0..." */ + 0x40,0x00,0x00,0x00,0x50,0x00,0x00,0x00, /* 00000030 "@...P..." */ + 0x60,0x00,0x00,0x00,0x70,0x00,0x00,0x00, /* 00000038 "`...p..." */ + 0x80,0x00,0x00,0x00 /* 00000040 "...." */ +}; + +const unsigned char TemplateS3pt[] = +{ + 0x53,0x33,0x50,0x54,0x34,0x00,0x00,0x00, /* 00000000 "S3PT4..." */ + 0x00,0x00,0x18,0x01,0x00,0x00,0x00,0x00, /* 00000008 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000010 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000018 "........" */ + 0x01,0x00,0x14,0x01,0x00,0x00,0x00,0x00, /* 00000020 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00 /* 00000030 "...." */ +}; + +const unsigned char TemplateSbst[] = +{ + 0x53,0x42,0x53,0x54,0x30,0x00,0x00,0x00, /* 00000000 "SBST0..." */ + 0x01,0x06,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000028 "........" */ +}; + +const unsigned char TemplateSlic[] = +{ + 0x53,0x4C,0x49,0x43,0x76,0x01,0x00,0x00, /* 00000000 "SLICv..." */ + 0x01,0x07,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x11,0x02,0x11,0x20,0x00,0x00,0x00,0x00, /* 00000020 "... ...." */ + 0x9C,0x00,0x00,0x00,0x06,0x02,0x00,0x00, /* 00000028 "........" */ + 0x00,0x24,0x00,0x00,0x52,0x53,0x41,0x31, /* 00000030 ".$..RSA1" */ + 0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000048 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000070 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000078 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000080 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000088 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000090 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000098 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000A8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000B8 "........" */ + 0x01,0x00,0x00,0x00,0xB6,0x00,0x00,0x00, /* 000000C0 "........" */ + 0x00,0x00,0x02,0x00,0x49,0x4E,0x54,0x45, /* 000000C8 "....INTE" */ + 0x4C,0x20,0x54,0x45,0x4D,0x50,0x4C,0x41, /* 000000D0 "L TEMPLA" */ + 0x54,0x45,0x57,0x49,0x4E,0x44,0x4F,0x57, /* 000000D8 "TEWINDOW" */ + 0x53,0x20,0x01,0x00,0x02,0x00,0x00,0x00, /* 000000E0 "S ......" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000E8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F0 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 000000F8 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000100 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000108 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000110 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000118 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000120 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000128 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000130 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000138 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000140 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000148 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000150 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000158 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000160 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000168 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00 /* 00000170 "......" */ +}; + +const unsigned char TemplateSlit[] = +{ + 0x53,0x4C,0x49,0x54,0xBC,0x01,0x00,0x00, /* 00000000 "SLIT...." */ + 0x01,0x00,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x16,0x03,0x11,0x20,0x14,0x00,0x00,0x00, /* 00000020 "... ...." */ + 0x00,0x00,0x00,0x00,0x0A,0x10,0x16,0x17, /* 00000028 "........" */ + 0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, /* 00000030 "........" */ + 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27, /* 00000038 " !"#$%&'" */ + 0x10,0x0A,0x15,0x16,0x17,0x18,0x19,0x1A, /* 00000040 "........" */ + 0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22, /* 00000048 "..... !"" */ + 0x23,0x24,0x25,0x26,0x16,0x15,0x0A,0x10, /* 00000050 "#$%&...." */ + 0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D, /* 00000058 "........" */ + 0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25, /* 00000060 ".. !"#$%" */ + 0x17,0x16,0x10,0x0A,0x15,0x16,0x17,0x18, /* 00000068 "........" */ + 0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20, /* 00000070 "....... " */ + 0x21,0x22,0x23,0x24,0x18,0x17,0x16,0x15, /* 00000078 "!"#$...." */ + 0x0A,0x10,0x16,0x17,0x18,0x19,0x1A,0x1B, /* 00000080 "........" */ + 0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23, /* 00000088 ".... !"#" */ + 0x19,0x18,0x17,0x16,0x10,0x0A,0x15,0x16, /* 00000090 "........" */ + 0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E, /* 00000098 "........" */ + 0x1F,0x20,0x21,0x22,0x1A,0x19,0x18,0x17, /* 000000A0 ". !"...." */ + 0x16,0x15,0x0A,0x10,0x16,0x17,0x18,0x19, /* 000000A8 "........" */ + 0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21, /* 000000B0 "...... !" */ + 0x1B,0x1A,0x19,0x18,0x17,0x16,0x10,0x0A, /* 000000B8 "........" */ + 0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C, /* 000000C0 "........" */ + 0x1D,0x1E,0x1F,0x20,0x1C,0x1B,0x1A,0x19, /* 000000C8 "... ...." */ + 0x18,0x17,0x16,0x15,0x0A,0x10,0x16,0x17, /* 000000D0 "........" */ + 0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, /* 000000D8 "........" */ + 0x1D,0x1C,0x1B,0x1A,0x19,0x18,0x17,0x16, /* 000000E0 "........" */ + 0x10,0x0A,0x15,0x16,0x17,0x18,0x19,0x1A, /* 000000E8 "........" */ + 0x1B,0x1C,0x1D,0x1E,0x1E,0x1D,0x1C,0x1B, /* 000000F0 "........" */ + 0x1A,0x19,0x18,0x17,0x16,0x15,0x0A,0x10, /* 000000F8 "........" */ + 0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D, /* 00000100 "........" */ + 0x1F,0x1E,0x1D,0x1C,0x1B,0x1A,0x19,0x18, /* 00000108 "........" */ + 0x17,0x16,0x10,0x0A,0x15,0x16,0x17,0x18, /* 00000110 "........" */ + 0x19,0x1A,0x1B,0x1C,0x20,0x1F,0x1E,0x1D, /* 00000118 ".... ..." */ + 0x1C,0x1B,0x1A,0x19,0x18,0x17,0x16,0x15, /* 00000120 "........" */ + 0x0A,0x10,0x16,0x17,0x18,0x19,0x1A,0x1B, /* 00000128 "........" */ + 0x21,0x20,0x1F,0x1E,0x1D,0x1C,0x1B,0x1A, /* 00000130 "! ......" */ + 0x19,0x18,0x17,0x16,0x10,0x0A,0x15,0x16, /* 00000138 "........" */ + 0x17,0x18,0x19,0x1A,0x22,0x21,0x20,0x1F, /* 00000140 "...."! ." */ + 0x1E,0x1D,0x1C,0x1B,0x1A,0x19,0x18,0x17, /* 00000148 "........" */ + 0x16,0x15,0x0A,0x10,0x16,0x17,0x18,0x19, /* 00000150 "........" */ + 0x23,0x22,0x21,0x20,0x1F,0x1E,0x1D,0x1C, /* 00000158 "#"! ...." */ + 0x1B,0x1A,0x19,0x18,0x17,0x16,0x10,0x0A, /* 00000160 "........" */ + 0x15,0x16,0x17,0x18,0x24,0x23,0x22,0x21, /* 00000168 "....$#"!" */ + 0x20,0x1F,0x1E,0x1D,0x1C,0x1B,0x1A,0x19, /* 00000170 " ......." */ + 0x18,0x17,0x16,0x15,0x0A,0x10,0x16,0x17, /* 00000178 "........" */ + 0x25,0x24,0x23,0x22,0x21,0x20,0x1F,0x1E, /* 00000180 "%$#"! .." */ + 0x1D,0x1C,0x1B,0x1A,0x19,0x18,0x17,0x16, /* 00000188 "........" */ + 0x10,0x0A,0x15,0x16,0x26,0x25,0x24,0x23, /* 00000190 "....&%$#" */ + 0x22,0x21,0x20,0x1F,0x1E,0x1D,0x1C,0x1B, /* 00000198 ""! ....." */ + 0x1A,0x19,0x18,0x17,0x16,0x15,0x0A,0x10, /* 000001A0 "........" */ + 0x27,0x26,0x25,0x24,0x23,0x22,0x21,0x20, /* 000001A8 "'&%$#"! " */ + 0x1F,0x1E,0x1D,0x1C,0x1B,0x1A,0x19,0x18, /* 000001B0 "........" */ + 0x17,0x16,0x10,0x0A /* 000001B8 "...." */ +}; + +const unsigned char TemplateSpcr[] = +{ + 0x53,0x50,0x43,0x52,0x50,0x00,0x00,0x00, /* 00000000 "SPCRP..." */ + 0x01,0xE3,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000048 "........" */ +}; + +const unsigned char TemplateSpmi[] = +{ + 0x53,0x50,0x4D,0x49,0x41,0x00,0x00,0x00, /* 00000000 "SPMIA..." */ + 0x04,0xED,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x08,0x00,0x01,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x00 /* 00000040 "." */ +}; + +const unsigned char TemplateSrat[] = +{ + 0x53,0x52,0x41,0x54,0x80,0x00,0x00,0x00, /* 00000000 "SRAT...." */ + 0x03,0x5A,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 ".ZINTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x01,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x10,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x01,0x28,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000040 ".(......" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000048 "........" */ + 0x00,0xFC,0x09,0x00,0x00,0x00,0x00,0x00, /* 00000050 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000060 "........" */ + 0x02,0x18,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000068 "........" */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000070 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000078 "........" */ +}; + +const unsigned char TemplateTcpa[] = +{ + 0x54,0x43,0x50,0x41,0x32,0x00,0x00,0x00, /* 00000000 "TCPA2..." */ + 0x01,0x67,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 ".gINTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x80,0x31,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 ".1..INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00 /* 00000030 ".." */ +}; + +const unsigned char TemplateUefi[] = +{ + 0x55,0x45,0x46,0x49,0x36,0x00,0x00,0x00, /* 00000000 "UEFI6..." */ + 0x01,0x9B,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x01,0x02,0x03, /* 00000020 "(.. ...." */ + 0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B, /* 00000028 "........" */ + 0x0C,0x0D,0x0E,0x0F,0x00,0x00 /* 00000030 "......" */ +}; + +const unsigned char TemplateWaet[] = +{ + 0x57,0x41,0x45,0x54,0x28,0x00,0x00,0x00, /* 00000000 "WAET(..." */ + 0x01,0x19,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00 /* 00000020 "(.. ...." */ +}; + +const unsigned char TemplateWdat[] = +{ + 0x57,0x44,0x41,0x54,0x5C,0x00,0x00,0x00, /* 00000000 "WDAT\..." */ + 0x01,0xE3,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x20,0x00,0x00,0x00, /* 00000020 "(.. ..." */ + 0xFF,0x00,0xFF,0xFF,0xFF,0x00,0x00,0x00, /* 00000028 "........" */ + 0x58,0x02,0x00,0x00,0xFF,0x03,0x00,0x00, /* 00000030 "X......." */ + 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000038 "........" */ + 0x0E,0x00,0x00,0x00,0x01,0x02,0x00,0x00, /* 00000040 "........" */ + 0x01,0x10,0x00,0x02,0x60,0x04,0x00,0x00, /* 00000048 "....`..." */ + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00, /* 00000050 "........" */ + 0x01,0x00,0x00,0x00 /* 00000058 "...." */ +}; + +const unsigned char TemplateWddt[] = +{ + 0x57,0x44,0x44,0x54,0x40,0x00,0x00,0x00, /* 00000000 "WDDT@..." */ + 0x01,0x00,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x01,0xFF,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 "........" */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 /* 00000038 "........" */ +}; + +const unsigned char TemplateWdrt[] = +{ + 0x57,0x44,0x52,0x54,0x47,0x00,0x00,0x00, /* 00000000 "WDRTG..." */ + 0x01,0xB0,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x00,0x20,0x00,0x00, /* 00000020 "(.. . .." */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000028 "........" */ + 0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00, /* 00000030 ". ......" */ + 0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF, /* 00000038 "........" */ + 0x00,0x00,0x00,0x00,0xFF,0xFF,0x00 /* 00000040 "......." */ +}; + +const unsigned char TemplateXsdt[] = +{ + 0x58,0x53,0x44,0x54,0x64,0x00,0x00,0x00, /* 00000000 "XSDTd..." */ + 0x01,0x8B,0x49,0x4E,0x54,0x45,0x4C,0x20, /* 00000008 "..INTEL " */ + 0x54,0x45,0x4D,0x50,0x4C,0x41,0x54,0x45, /* 00000010 "TEMPLATE" */ + 0x01,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C, /* 00000018 "....INTL" */ + 0x28,0x05,0x10,0x20,0x10,0x00,0x00,0x00, /* 00000020 "(.. ...." */ + 0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00, /* 00000028 ".... ..." */ + 0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00, /* 00000030 "....0..." */ + 0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00, /* 00000038 "....@..." */ + 0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00, /* 00000040 "....P..." */ + 0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00, /* 00000048 "....`..." */ + 0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x00, /* 00000050 "....p..." */ + 0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00, /* 00000058 "........" */ + 0x00,0x00,0x00,0x00 /* 00000060 "...." */ +}; + +#endif diff --git a/sys/contrib/dev/acpica/compiler/dtutils.c b/sys/contrib/dev/acpica/compiler/dtutils.c new file mode 100644 index 0000000..f87fa20 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/dtutils.c @@ -0,0 +1,882 @@ +/****************************************************************************** + * + * Module Name: dtutils.c - Utility routines for the data table compiler + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __DTUTILS_C__ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> +#include <contrib/dev/acpica/include/actables.h> + +#define _COMPONENT DT_COMPILER + ACPI_MODULE_NAME ("dtutils") + +/* Local prototypes */ + +static void +DtSum ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue); + + +/****************************************************************************** + * + * FUNCTION: DtError + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * Op - Parse node where error happened + * ExtraMessage - additional error message + * + * RETURN: None + * + * DESCRIPTION: Common error interface for data table compiler + * + *****************************************************************************/ + +void +DtError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage) +{ + + switch (Level) + { + case ASL_WARNING2: + case ASL_WARNING3: + if (Gbl_WarningLevel < Level) + { + return; + } + break; + + default: + break; + } + + if (FieldObject) + { + AslCommonError (Level, MessageId, + FieldObject->Line, + FieldObject->Line, + FieldObject->ByteOffset, + FieldObject->Column, + Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage); + } + else + { + AslCommonError (Level, MessageId, 0, + 0, 0, 0, 0, ExtraMessage); + } +} + + +/****************************************************************************** + * + * FUNCTION: DtNameError + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * Op - Parse node where error happened + * ExtraMessage - additional error message + * + * RETURN: None + * + * DESCRIPTION: Error interface for named objects + * + *****************************************************************************/ + +void +DtNameError ( + UINT8 Level, + UINT8 MessageId, + DT_FIELD *FieldObject, + char *ExtraMessage) +{ + + switch (Level) + { + case ASL_WARNING2: + case ASL_WARNING3: + if (Gbl_WarningLevel < Level) + { + return; + } + break; + + default: + break; + } + + if (FieldObject) + { + AslCommonError (Level, MessageId, + FieldObject->Line, + FieldObject->Line, + FieldObject->ByteOffset, + FieldObject->NameColumn, + Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage); + } + else + { + AslCommonError (Level, MessageId, 0, + 0, 0, 0, 0, ExtraMessage); + } +} + + +/******************************************************************************* + * + * FUNCTION: DtFatal + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Dump the error log and abort the compiler. Used for serious + * compile or I/O errors + * + ******************************************************************************/ + +void +DtFatal ( + UINT8 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 +} + + +/****************************************************************************** + * + * FUNCTION: DtStrtoul64 + * + * PARAMETERS: String - Null terminated string + * ReturnInteger - Where the converted integer is returned + * + * RETURN: Status + * + * DESCRIPTION: Simple conversion of a string hex integer constant to unsigned + * value. Assumes no leading "0x" for the constant. + * + * Portability note: The reason this function exists is because a 64-bit + * sscanf is not available in all environments. + * + *****************************************************************************/ + +ACPI_STATUS +DtStrtoul64 ( + char *String, + UINT64 *ReturnInteger) +{ + char *ThisChar = String; + UINT32 ThisDigit; + UINT64 ReturnValue = 0; + int DigitCount = 0; + + + /* Skip over any white space in the buffer */ + + while ((*ThisChar == ' ') || (*ThisChar == '\t')) + { + ThisChar++; + } + + /* Skip leading zeros */ + + while ((*ThisChar) == '0') + { + ThisChar++; + } + + /* Convert character-by-character */ + + while (*ThisChar) + { + if (ACPI_IS_DIGIT (*ThisChar)) + { + /* Convert ASCII 0-9 to Decimal value */ + + ThisDigit = ((UINT8) *ThisChar) - '0'; + } + else /* Letter */ + { + ThisDigit = (UINT32) ACPI_TOUPPER (*ThisChar); + if (!ACPI_IS_XDIGIT ((char) ThisDigit)) + { + /* Not A-F */ + + return (AE_BAD_CHARACTER); + } + + /* Convert ASCII Hex char (A-F) to value */ + + ThisDigit = (ThisDigit - 'A') + 10; + } + + /* Insert the 4-bit hex digit */ + + ReturnValue <<= 4; + ReturnValue += ThisDigit; + + ThisChar++; + DigitCount++; + if (DigitCount > 16) + { + /* Value is too large (> 64 bits/8 bytes/16 hex digits) */ + + return (AE_LIMIT); + } + } + + *ReturnInteger = ReturnValue; + return (AE_OK); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFileSize + * + * PARAMETERS: Handle - Open file handler + * + * RETURN: Current file size + * + * DESCRIPTION: Get the current size of a file. Seek to the EOF and get the + * offset. Seek back to the original location. + * + *****************************************************************************/ + +UINT32 +DtGetFileSize ( + FILE *Handle) +{ + int CurrentOffset; + int LastOffset; + + + CurrentOffset = ftell (Handle); + fseek (Handle, 0, SEEK_END); + LastOffset = ftell (Handle); + fseek (Handle, CurrentOffset, SEEK_SET); + + return ((UINT32) LastOffset); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFieldValue + * + * PARAMETERS: Field - Current field list pointer + * + * RETURN: Field value + * + * DESCRIPTION: Get field value + * + *****************************************************************************/ + +char * +DtGetFieldValue ( + DT_FIELD *Field) +{ + if (!Field) + { + return (NULL); + } + + return (Field->Value); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFieldType + * + * PARAMETERS: Info - Data table info + * + * RETURN: Field type + * + * DESCRIPTION: Get field type + * + *****************************************************************************/ + +UINT8 +DtGetFieldType ( + ACPI_DMTABLE_INFO *Info) +{ + UINT8 Type; + + + /* DT_FLAG means that this is the start of a block of flag bits */ + /* TBD - we can make these a separate opcode later */ + + if (Info->Flags & DT_FLAG) + { + return (DT_FIELD_TYPE_FLAGS_INTEGER); + } + + /* Type is based upon the opcode for this field in the info table */ + + 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: + case ACPI_DMT_FLAGS0: + case ACPI_DMT_FLAGS1: + case ACPI_DMT_FLAGS2: + case ACPI_DMT_FLAGS4: + Type = DT_FIELD_TYPE_FLAG; + break; + + case ACPI_DMT_NAME4: + case ACPI_DMT_SIG: + case ACPI_DMT_NAME6: + case ACPI_DMT_NAME8: + case ACPI_DMT_STRING: + Type = DT_FIELD_TYPE_STRING; + break; + + case ACPI_DMT_BUFFER: + case ACPI_DMT_BUF7: + case ACPI_DMT_BUF16: + case ACPI_DMT_BUF128: + case ACPI_DMT_PCI_PATH: + Type = DT_FIELD_TYPE_BUFFER; + break; + + case ACPI_DMT_GAS: + case ACPI_DMT_HESTNTFY: + Type = DT_FIELD_TYPE_INLINE_SUBTABLE; + break; + + case ACPI_DMT_UNICODE: + Type = DT_FIELD_TYPE_UNICODE; + break; + + case ACPI_DMT_UUID: + Type = DT_FIELD_TYPE_UUID; + break; + + case ACPI_DMT_DEVICE_PATH: + Type = DT_FIELD_TYPE_DEVICE_PATH; + break; + + case ACPI_DMT_LABEL: + Type = DT_FIELD_TYPE_LABEL; + break; + + default: + Type = DT_FIELD_TYPE_INTEGER; + break; + } + + return (Type); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetBufferLength + * + * PARAMETERS: Buffer - List of integers, + * for example "10 3A 4F 2E" + * + * RETURN: Count of integer + * + * DESCRIPTION: Get length of bytes needed to store the integers + * + *****************************************************************************/ + +UINT32 +DtGetBufferLength ( + char *Buffer) +{ + UINT32 ByteLength = 0; + + + while (*Buffer) + { + if (*Buffer == ' ') + { + ByteLength++; + + while (*Buffer == ' ') + { + Buffer++; + } + } + + Buffer++; + } + + return (++ByteLength); +} + + +/****************************************************************************** + * + * FUNCTION: DtGetFieldLength + * + * PARAMETERS: Field - Current field + * Info - Data table info + * + * RETURN: Field length + * + * DESCRIPTION: Get length of bytes needed to compile the field + * + * Note: This function must remain in sync with AcpiDmDumpTable. + * + *****************************************************************************/ + +UINT32 +DtGetFieldLength ( + DT_FIELD *Field, + ACPI_DMTABLE_INFO *Info) +{ + UINT32 ByteLength = 0; + char *Value; + + + /* Length is based upon the opcode for this field in the info table */ + + 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: + case ACPI_DMT_FLAGS0: + case ACPI_DMT_FLAGS1: + case ACPI_DMT_FLAGS2: + case ACPI_DMT_FLAGS4: + case ACPI_DMT_LABEL: + case ACPI_DMT_EXTRA_TEXT: + ByteLength = 0; + break; + + case ACPI_DMT_UINT8: + case ACPI_DMT_CHKSUM: + case ACPI_DMT_SPACEID: + case ACPI_DMT_ACCWIDTH: + case ACPI_DMT_IVRS: + case ACPI_DMT_MADT: + case ACPI_DMT_PMTT: + case ACPI_DMT_SRAT: + case ACPI_DMT_ASF: + case ACPI_DMT_HESTNTYP: + case ACPI_DMT_FADTPM: + case ACPI_DMT_EINJACT: + case ACPI_DMT_EINJINST: + case ACPI_DMT_ERSTACT: + case ACPI_DMT_ERSTINST: + ByteLength = 1; + break; + + case ACPI_DMT_UINT16: + case ACPI_DMT_DMAR: + case ACPI_DMT_HEST: + case ACPI_DMT_PCI_PATH: + ByteLength = 2; + break; + + case ACPI_DMT_UINT24: + ByteLength = 3; + break; + + case ACPI_DMT_UINT32: + case ACPI_DMT_NAME4: + case ACPI_DMT_SLIC: + case ACPI_DMT_SIG: + ByteLength = 4; + break; + + case ACPI_DMT_UINT40: + ByteLength = 5; + break; + + case ACPI_DMT_UINT48: + case ACPI_DMT_NAME6: + ByteLength = 6; + break; + + case ACPI_DMT_UINT56: + case ACPI_DMT_BUF7: + ByteLength = 7; + break; + + case ACPI_DMT_UINT64: + case ACPI_DMT_NAME8: + ByteLength = 8; + break; + + case ACPI_DMT_STRING: + Value = DtGetFieldValue (Field); + if (Value) + { + ByteLength = ACPI_STRLEN (Value) + 1; + } + else + { /* At this point, this is a fatal error */ + + sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); + return (0); + } + break; + + case ACPI_DMT_GAS: + ByteLength = sizeof (ACPI_GENERIC_ADDRESS); + break; + + case ACPI_DMT_HESTNTFY: + ByteLength = sizeof (ACPI_HEST_NOTIFY); + break; + + case ACPI_DMT_BUFFER: + Value = DtGetFieldValue (Field); + if (Value) + { + ByteLength = DtGetBufferLength (Value); + } + else + { /* At this point, this is a fatal error */ + + sprintf (MsgBuffer, "Expected \"%s\"", Info->Name); + DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer); + return (0); + } + break; + + case ACPI_DMT_BUF16: + case ACPI_DMT_UUID: + ByteLength = 16; + break; + + case ACPI_DMT_BUF128: + ByteLength = 128; + break; + + case ACPI_DMT_UNICODE: + Value = DtGetFieldValue (Field); + + /* TBD: error if Value is NULL? (as below?) */ + + ByteLength = (ACPI_STRLEN (Value) + 1) * sizeof(UINT16); + break; + + default: + DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode"); + return (0); + } + + return (ByteLength); +} + + +/****************************************************************************** + * + * FUNCTION: DtSum + * + * PARAMETERS: DT_WALK_CALLBACK: + * Subtable - Subtable + * Context - Unused + * ReturnValue - Store the checksum of subtable + * + * RETURN: Status + * + * DESCRIPTION: Get the checksum of subtable + * + *****************************************************************************/ + +static void +DtSum ( + DT_SUBTABLE *Subtable, + void *Context, + void *ReturnValue) +{ + UINT8 Checksum; + UINT8 *Sum = ReturnValue; + + + Checksum = AcpiTbChecksum (Subtable->Buffer, Subtable->Length); + *Sum = (UINT8) (*Sum + Checksum); +} + + +/****************************************************************************** + * + * FUNCTION: DtSetTableChecksum + * + * PARAMETERS: ChecksumPointer - Where to return the checksum + * + * RETURN: None + * + * DESCRIPTION: Set checksum of the whole data table into the checksum field + * + *****************************************************************************/ + +void +DtSetTableChecksum ( + UINT8 *ChecksumPointer) +{ + UINT8 Checksum = 0; + UINT8 OldSum; + + + DtWalkTableTree (Gbl_RootTable, DtSum, NULL, &Checksum); + + OldSum = *ChecksumPointer; + Checksum = (UINT8) (Checksum - OldSum); + + /* Compute the final checksum */ + + Checksum = (UINT8) (0 - Checksum); + *ChecksumPointer = Checksum; +} + + +/****************************************************************************** + * + * FUNCTION: DtSetTableLength + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Walk the subtables and set all the length fields + * + *****************************************************************************/ + +void +DtSetTableLength ( + void) +{ + DT_SUBTABLE *ParentTable; + DT_SUBTABLE *ChildTable; + + + ParentTable = Gbl_RootTable; + ChildTable = NULL; + + if (!ParentTable) + { + return; + } + + DtSetSubtableLength (ParentTable); + + while (1) + { + ChildTable = DtGetNextSubtable (ParentTable, ChildTable); + if (ChildTable) + { + if (ChildTable->LengthField) + { + DtSetSubtableLength (ChildTable); + } + + if (ChildTable->Child) + { + ParentTable = ChildTable; + ChildTable = NULL; + } + else + { + ParentTable->TotalLength += ChildTable->TotalLength; + if (ParentTable->LengthField) + { + DtSetSubtableLength (ParentTable); + } + } + } + else + { + ChildTable = ParentTable; + + if (ChildTable == Gbl_RootTable) + { + break; + } + + ParentTable = DtGetParentSubtable (ParentTable); + + ParentTable->TotalLength += ChildTable->TotalLength; + if (ParentTable->LengthField) + { + DtSetSubtableLength (ParentTable); + } + } + } +} + + +/****************************************************************************** + * + * FUNCTION: DtWalkTableTree + * + * PARAMETERS: StartTable - Subtable in the tree where walking begins + * UserFunction - Called during the walk + * Context - Passed to user function + * ReturnValue - The return value of UserFunction + * + * RETURN: None + * + * DESCRIPTION: Performs a depth-first walk of the subtable tree + * + *****************************************************************************/ + +void +DtWalkTableTree ( + DT_SUBTABLE *StartTable, + DT_WALK_CALLBACK UserFunction, + void *Context, + void *ReturnValue) +{ + DT_SUBTABLE *ParentTable; + DT_SUBTABLE *ChildTable; + + + ParentTable = StartTable; + ChildTable = NULL; + + if (!ParentTable) + { + return; + } + + UserFunction (ParentTable, Context, ReturnValue); + + while (1) + { + ChildTable = DtGetNextSubtable (ParentTable, ChildTable); + if (ChildTable) + { + UserFunction (ChildTable, Context, ReturnValue); + + if (ChildTable->Child) + { + ParentTable = ChildTable; + ChildTable = NULL; + } + } + else + { + ChildTable = ParentTable; + if (ChildTable == Gbl_RootTable) + { + break; + } + + ParentTable = DtGetParentSubtable (ParentTable); + + if (ChildTable->Peer == StartTable) + { + break; + } + } + } +} + + +/****************************************************************************** + * + * FUNCTION: DtFreeFieldList + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Free the field list + * + *****************************************************************************/ + +void +DtFreeFieldList ( + void) +{ + DT_FIELD *Field = Gbl_FieldList; + DT_FIELD *NextField; + + + /* Walk and free entire field list */ + + while (Field) + { + NextField = Field->Next; /* Save link */ + + if (!(Field->Flags & DT_FIELD_NOT_ALLOCATED)) + { + ACPI_FREE (Field->Name); + ACPI_FREE (Field->Value); + } + + ACPI_FREE (Field); + Field = NextField; + } +} diff --git a/sys/contrib/dev/acpica/compiler/preprocess.h b/sys/contrib/dev/acpica/compiler/preprocess.h new file mode 100644 index 0000000..920c0b9 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/preprocess.h @@ -0,0 +1,273 @@ +/****************************************************************************** + * + * Module Name: preprocess.h - header for iASL Preprocessor + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define __PREPROCESS_H__ + +#ifndef _PREPROCESS +#define _PREPROCESS + +#undef PR_EXTERN + +#ifdef _DECLARE_PR_GLOBALS +#define PR_EXTERN +#define PR_INIT_GLOBAL(a,b) (a)=(b) +#else +#define PR_EXTERN extern +#define PR_INIT_GLOBAL(a,b) (a) +#endif + + +/* + * Configuration + */ +#define PR_MAX_MACRO_ARGS 32 /* Max number of macro args */ +#define PR_MAX_ARG_INSTANCES 24 /* Max instances of any one arg */ +#define PR_LINES_PER_BLOCK 4096 /* Max input source lines per block */ + + +/* + * Local defines and macros + */ +#define PR_TOKEN_SEPARATORS " ,(){}\t\n" +#define PR_MACRO_SEPARATORS " ,(){}~!*/%+-<>=&^|\"\t\n" +#define PR_MACRO_ARGUMENTS " ,\t\n" +#define PR_EXPR_SEPARATORS " ,(){}~!*/%+-<>=&^|\"\t\n" + +#define PR_PREFIX_ID "Pr(%.4u) - " /* Used for debug output */ + +#define THIS_TOKEN_OFFSET(t) ((t-Gbl_MainTokenBuffer) + 1) + + +/* + * Preprocessor structures + */ +typedef struct pr_macro_arg +{ + char *Name; + UINT32 Offset[PR_MAX_ARG_INSTANCES]; + UINT16 UseCount; + +} PR_MACRO_ARG; + +typedef struct pr_define_info +{ + struct pr_define_info *Previous; + struct pr_define_info *Next; + char *Identifier; + char *Replacement; + char *Body; /* Macro body */ + PR_MACRO_ARG *Args; /* Macro arg list */ + UINT16 ArgCount; /* Macro arg count */ + BOOLEAN Persist; /* Keep for entire compiler run */ + +} PR_DEFINE_INFO; + +typedef struct pr_directive_info +{ + char *Name; /* Directive name */ + UINT8 ArgCount; /* Required # of args */ + +} PR_DIRECTIVE_INFO; + +typedef struct pr_operator_info +{ + char *Op; + +} PR_OPERATOR_INFO; + +typedef struct pr_file_node +{ + struct pr_file_node *Next; + FILE *File; + char *Filename; + UINT32 CurrentLineNumber; + +} PR_FILE_NODE; + + +/* + * Globals + */ +PR_EXTERN char XXXEvalBuffer[ASL_LINE_BUFFER_SIZE]; +PR_EXTERN char Gbl_MainTokenBuffer[ASL_LINE_BUFFER_SIZE]; +PR_EXTERN char Gbl_MacroTokenBuffer[ASL_LINE_BUFFER_SIZE]; +PR_EXTERN char Gbl_ExpressionTokenBuffer[ASL_LINE_BUFFER_SIZE]; + +PR_EXTERN PR_FILE_NODE *Gbl_InputFileList; +PR_EXTERN PR_DEFINE_INFO PR_INIT_GLOBAL (*Gbl_DefineList, NULL); +PR_EXTERN UINT32 Gbl_PreprocessorLineNumber; +PR_EXTERN int Gbl_IfDepth; +PR_EXTERN BOOLEAN PR_INIT_GLOBAL (Gbl_PreprocessorError, FALSE); + + +/* + * prscan - Preprocessor entry + */ +void +PrInitializePreprocessor ( + void); + +void +PrInitializeGlobals ( + void); + +void +PrTerminatePreprocessor ( + void); + +BOOLEAN +PrDoPreprocess ( + void); + +UINT64 +PrIsDefined ( + char *Identifier); + +UINT64 +PrResolveDefine ( + char *Identifier); + +int +PrInitLexer ( + char *String); + +void +PrTerminateLexer ( + void); + + +/* + * prmacros - Support for #defines and macros + */ +void +PrDumpPredefinedNames ( + void); + +PR_DEFINE_INFO * +PrAddDefine ( + char *Token, + char *Token2, + BOOLEAN Persist); + +void +PrRemoveDefine ( + char *DefineName); + +PR_DEFINE_INFO * +PrMatchDefine ( + char *MatchString); + +void +PrAddMacro ( + char *Name, + char **Next); + +void +PrDoMacroInvocation ( + char *TokenBuffer, + char *MacroStart, + PR_DEFINE_INFO *DefineInfo, + char **Next); + + +/* + * prexpress - #if expression support + */ +ACPI_STATUS +PrResolveIntegerExpression ( + char *Line, + UINT64 *ReturnValue); + +char * +PrPrioritizeExpression ( + char *OriginalLine); + +/* + * prparser - lex/yacc expression parser + */ +UINT64 +PrEvaluateExpression ( + char *ExprString); + + +/* + * prutils - Preprocesor utilities + */ +char * +PrGetNextToken ( + char *Buffer, + char *MatchString, + char **Next); + +void +PrError ( + UINT8 Level, + UINT8 MessageId, + UINT32 Column); + +void +PrReplaceData ( + char *Buffer, + UINT32 LengthToRemove, + char *BufferToAdd, + UINT32 LengthToAdd); + +void +PrOpenIncludeFile ( + char *Filename); + +FILE * +PrOpenIncludeWithPrefix ( + char *PrefixDir, + char *Filename); + +void +PrPushInputFileStack ( + FILE *InputFile, + char *Filename); + +BOOLEAN +PrPopInputFileStack ( + void); + +#endif diff --git a/sys/contrib/dev/acpica/compiler/prexpress.c b/sys/contrib/dev/acpica/compiler/prexpress.c new file mode 100644 index 0000000..c0dccd9 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/prexpress.c @@ -0,0 +1,305 @@ +/****************************************************************************** + * + * Module Name: prexpress - Preprocessor #if expression support + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + + +#define _COMPONENT ASL_PREPROCESSOR + ACPI_MODULE_NAME ("prexpress") + +/* Local prototypes */ + +static char * +PrExpandMacros ( + char *Line); + + +#ifdef _UNDER_DEVELOPMENT +/****************************************************************************** + * + * FUNCTION: PrUnTokenize + * + * PARAMETERS: Buffer - Token Buffer + * Next - "Next" buffer from GetNextToken + * + * RETURN: None + * + * DESCRIPTION: Un-tokenized the current token buffer. The implementation is + * to simply set the null inserted by GetNextToken to a blank. + * If Next is NULL, there were no tokens found in the Buffer, + * so there is nothing to do. + * + *****************************************************************************/ + +static void +PrUnTokenize ( + char *Buffer, + char *Next) +{ + UINT32 Length = strlen (Buffer); + + + if (!Next) + { + return; + } + if (Buffer[Length] != '\n') + { + Buffer[strlen(Buffer)] = ' '; + } +} +#endif + + +/****************************************************************************** + * + * FUNCTION: PrExpandMacros + * + * PARAMETERS: Line - Pointer into the current line + * + * RETURN: Updated pointer into the current line + * + * DESCRIPTION: Expand any macros found in the current line buffer. + * + *****************************************************************************/ + +static char * +PrExpandMacros ( + char *Line) +{ + char *Token; + char *ReplaceString; + PR_DEFINE_INFO *DefineInfo; + ACPI_SIZE TokenOffset; + char *Next; + int OffsetAdjust; + + + strcpy (Gbl_ExpressionTokenBuffer, Gbl_CurrentLineBuffer); + Token = PrGetNextToken (Gbl_ExpressionTokenBuffer, PR_EXPR_SEPARATORS, &Next); + OffsetAdjust = 0; + + while (Token) + { + DefineInfo = PrMatchDefine (Token); + if (DefineInfo) + { + if (DefineInfo->Body) + { + /* This is a macro. TBD: Is this allowed? */ + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Matched Macro: %s->%s\n", + Gbl_CurrentLineNumber, DefineInfo->Identifier, + DefineInfo->Replacement); + + PrDoMacroInvocation (Gbl_ExpressionTokenBuffer, Token, + DefineInfo, &Next); + } + else + { + ReplaceString = DefineInfo->Replacement; + + /* Replace the name in the original line buffer */ + + TokenOffset = Token - Gbl_ExpressionTokenBuffer + OffsetAdjust; + PrReplaceData ( + &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token), + ReplaceString, strlen (ReplaceString)); + + /* Adjust for length difference between old and new name length */ + + OffsetAdjust += strlen (ReplaceString) - strlen (Token); + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Matched #define within expression: %s->%s\n", + Gbl_CurrentLineNumber, Token, + *ReplaceString ? ReplaceString : "(NULL STRING)"); + } + } + + Token = PrGetNextToken (NULL, PR_EXPR_SEPARATORS, &Next); + } + + return (Line); +} + + +/****************************************************************************** + * + * FUNCTION: PrIsDefined + * + * PARAMETERS: Identifier - Name to be resolved + * + * RETURN: 64-bit boolean integer value + * + * DESCRIPTION: Returns TRUE if the name is defined, FALSE otherwise (0). + * + *****************************************************************************/ + +UINT64 +PrIsDefined ( + char *Identifier) +{ + UINT64 Value; + PR_DEFINE_INFO *DefineInfo; + + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "**** Is defined?: %s\n", Gbl_CurrentLineNumber, Identifier); + + Value = 0; /* Default is "Not defined" -- FALSE */ + + DefineInfo = PrMatchDefine (Identifier); + if (DefineInfo) + { + Value = ACPI_UINT64_MAX; /* TRUE */ + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "[#if defined %s] resolved to: %8.8X%8.8X\n", + Gbl_CurrentLineNumber, Identifier, ACPI_FORMAT_UINT64 (Value)); + + return (Value); +} + + +/****************************************************************************** + * + * FUNCTION: PrResolveDefine + * + * PARAMETERS: Identifier - Name to be resolved + * + * RETURN: A 64-bit boolean integer value + * + * DESCRIPTION: Returns TRUE if the name is defined, FALSE otherwise (0). + * + *****************************************************************************/ + +UINT64 +PrResolveDefine ( + char *Identifier) +{ + UINT64 Value; + PR_DEFINE_INFO *DefineInfo; + + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "**** Resolve #define: %s\n", Gbl_CurrentLineNumber, Identifier); + + Value = 0; /* Default is "Not defined" -- FALSE */ + + DefineInfo = PrMatchDefine (Identifier); + if (DefineInfo) + { + Value = ACPI_UINT64_MAX; /* TRUE */ + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "[#if defined %s] resolved to: %8.8X%8.8X\n", + Gbl_CurrentLineNumber, Identifier, ACPI_FORMAT_UINT64 (Value)); + + return (Value); +} + + +/****************************************************************************** + * + * FUNCTION: PrResolveIntegerExpression + * + * PARAMETERS: Line - Pointer to integer expression + * ReturnValue - Where the resolved 64-bit integer is + * returned. + * + * RETURN: Status + * + * DESCRIPTION: Resolve an integer expression to a single value. Supports + * both integer constants and labels. + * + *****************************************************************************/ + +ACPI_STATUS +PrResolveIntegerExpression ( + char *Line, + UINT64 *ReturnValue) +{ + UINT64 Result; + char *ExpandedLine; + + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "**** Resolve #if: %s\n", Gbl_CurrentLineNumber, Line); + + /* Expand all macros within the expression first */ + + ExpandedLine = PrExpandMacros (Line); + + /* Now we can evaluate the expression */ + + Result = PrEvaluateExpression (ExpandedLine); + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "**** Expression Resolved to: %8.8X%8.8X\n", + Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Result)); + + *ReturnValue = Result; + return (AE_OK); + +#if 0 +InvalidExpression: + + ACPI_FREE (EvalBuffer); + PrError (ASL_ERROR, ASL_MSG_INVALID_EXPRESSION, 0); + return (AE_ERROR); + + +NormalExit: + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "**** Expression Resolved to: %8.8X%8.8X\n", + Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value1)); + + *ReturnValue = Value1; + return (AE_OK); +#endif +} diff --git a/sys/contrib/dev/acpica/compiler/prmacros.c b/sys/contrib/dev/acpica/compiler/prmacros.c new file mode 100644 index 0000000..82663a5 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/prmacros.c @@ -0,0 +1,574 @@ +/****************************************************************************** + * + * Module Name: prmacros - Preprocessor #define macro support + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + + +#define _COMPONENT ASL_PREPROCESSOR + ACPI_MODULE_NAME ("prmacros") + + +/******************************************************************************* + * + * FUNCTION: PrDumpPredefinedNames + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Dump the list of #defines. Used as the preprocessor starts, to + * display the names that were defined on the command line. + * Debug information only. + * + ******************************************************************************/ + +void +PrDumpPredefinedNames ( + void) +{ + PR_DEFINE_INFO *DefineInfo; + + + DefineInfo = Gbl_DefineList; + while (DefineInfo) + { + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Predefined #define: %s->%s\n", + 0, DefineInfo->Identifier, DefineInfo->Replacement); + + DefineInfo = DefineInfo->Next; + } +} + + +/******************************************************************************* + * + * FUNCTION: PrAddDefine + * + * PARAMETERS: Identifier - Name to be replaced + * Replacement - Replacement for Identifier + * Persist - Keep define across multiple compiles? + * + * RETURN: A new define_info struct. NULL on error. + * + * DESCRIPTION: Add a new #define to the global list + * + ******************************************************************************/ + +PR_DEFINE_INFO * +PrAddDefine ( + char *Identifier, + char *Replacement, + BOOLEAN Persist) +{ + char *IdentifierString; + char *ReplacementString; + PR_DEFINE_INFO *DefineInfo; + + + if (!Replacement) + { + Replacement = ""; + } + + /* Check for already-defined first */ + + DefineInfo = PrMatchDefine (Identifier); + if (DefineInfo) + { + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID, + "#define: name already exists: %s\n", + Gbl_CurrentLineNumber, Identifier); + + /* + * Name already exists. This is only an error if the target name + * is different. + */ + if (strcmp (Replacement, DefineInfo->Replacement)) + { + PrError (ASL_ERROR, ASL_MSG_EXISTING_NAME, + THIS_TOKEN_OFFSET (Identifier)); + + return (NULL); + } + + return (DefineInfo); + } + + /* Copy input strings */ + + IdentifierString = UtLocalCalloc (strlen (Identifier) + 1); + strcpy (IdentifierString, Identifier); + + ReplacementString = UtLocalCalloc (strlen (Replacement) + 1); + strcpy (ReplacementString, Replacement); + + /* Init and link new define info struct */ + + DefineInfo = UtLocalCalloc (sizeof (PR_DEFINE_INFO)); + DefineInfo->Replacement = ReplacementString; + DefineInfo->Identifier = IdentifierString; + DefineInfo->Persist = Persist; + + if (Gbl_DefineList) + { + Gbl_DefineList->Previous = DefineInfo; + } + + DefineInfo->Next = Gbl_DefineList; + Gbl_DefineList = DefineInfo; + return (DefineInfo); +} + + +/******************************************************************************* + * + * FUNCTION: PrRemoveDefine + * + * PARAMETERS: DefineName - Name of define to be removed + * + * RETURN: None + * + * DESCRIPTION: Implements #undef. Remove a #define if found in the global + * list. No error if the target of the #undef does not exist, + * as per the C #undef definition. + * + ******************************************************************************/ + +void +PrRemoveDefine ( + char *DefineName) +{ + PR_DEFINE_INFO *DefineInfo; + + + /* Match name and delete the node */ + + DefineInfo = Gbl_DefineList; + while (DefineInfo) + { + if (!strcmp (DefineName, DefineInfo->Identifier)) + { + /* Remove from linked list */ + + if (DefineInfo->Previous) + { + (DefineInfo->Previous)->Next = DefineInfo->Next; + } + else + { + Gbl_DefineList = DefineInfo->Next; + } + + if (DefineInfo->Next) + { + (DefineInfo->Next)->Previous = DefineInfo->Previous; + } + + free (DefineInfo); + return; + } + + DefineInfo = DefineInfo->Next; + } + + /* + * Name was not found. By definition of #undef, this is not + * an error, however. + */ + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "#undef: could not find %s\n", + Gbl_CurrentLineNumber, DefineName); +} + + +/******************************************************************************* + * + * FUNCTION: PrMatchDefine + * + * PARAMETERS: MatchString - Name associated with the #define + * + * RETURN: Matched string if found. NULL otherwise. + * + * DESCRIPTION: Find a name in global #define list + * + ******************************************************************************/ + +PR_DEFINE_INFO * +PrMatchDefine ( + char *MatchString) +{ + PR_DEFINE_INFO *DefineInfo; + + + DefineInfo = Gbl_DefineList; + while (DefineInfo) + { + if (!strcmp (MatchString, DefineInfo->Identifier)) + { + return (DefineInfo); + } + + DefineInfo = DefineInfo->Next; + } + + return (NULL); +} + + +/******************************************************************************* + * + * FUNCTION: PrAddMacro + * + * PARAMETERS: Name - Start of the macro definition + * Next - "Next" buffer from GetNextToken + * + * RETURN: None + * + * DESCRIPTION: Add a new macro to the list of #defines. Handles argument + * processing. + * + ******************************************************************************/ + +void +PrAddMacro ( + char *Name, + char **Next) +{ + char *Token = NULL; + ACPI_SIZE TokenOffset; + ACPI_SIZE MacroBodyOffset; + PR_DEFINE_INFO *DefineInfo; + PR_MACRO_ARG *Args; + char *Body; + char *BodyInSource; + UINT32 i; + UINT16 UseCount = 0; + UINT16 ArgCount = 0; + UINT32 Depth = 1; + UINT32 EndOfArgList; + char BufferChar; + + + /* Find the end of the arguments list */ + + TokenOffset = Name - Gbl_MainTokenBuffer + strlen (Name) + 1; + while (1) + { + BufferChar = Gbl_CurrentLineBuffer[TokenOffset]; + if (BufferChar == '(') + { + Depth++; + } + else if (BufferChar == ')') + { + Depth--; + } + else if (BufferChar == 0) + { + PrError (ASL_ERROR, ASL_MSG_MACRO_SYNTAX, TokenOffset); + return; + } + + if (Depth == 0) + { + /* Found arg list end */ + + EndOfArgList = TokenOffset; + break; + } + + TokenOffset++; + } + + /* At this point, we know that we have a reasonable argument list */ + + Args = UtLocalCalloc (sizeof (PR_MACRO_ARG) * PR_MAX_MACRO_ARGS); + + /* Get the macro argument names */ + + for (i = 0; i < PR_MAX_MACRO_ARGS; i++) + { + Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next); + if (!Token) + { + /* This is the case for a NULL macro body */ + + BodyInSource = ""; + goto AddMacroToList; + } + + /* Don't go beyond the argument list */ + + TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token); + if (TokenOffset > EndOfArgList) + { + break; + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Macro arg: %s \n", + Gbl_CurrentLineNumber, Token); + + Args[i].Name = UtLocalCalloc (strlen (Token) + 1); + strcpy (Args[i].Name, Token); + + Args[i].UseCount = 0; + + ArgCount++; + if (ArgCount >= PR_MAX_MACRO_ARGS) + { + PrError (ASL_ERROR, ASL_MSG_TOO_MANY_ARGUMENTS, TokenOffset); + return; + } + } + + /* Get the macro body. Token now points to start of body */ + + MacroBodyOffset = Token - Gbl_MainTokenBuffer; + + /* Match each method arg in the macro body for later use */ + + Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next); + while (Token) + { + /* Search the macro arg list for matching arg */ + + for (i = 0; Args[i].Name && (i < PR_MAX_MACRO_ARGS); i++) + { + /* + * Save argument offset within macro body. This is the mechanism + * used to expand the macro upon invocation. + * + * Handles multiple instances of the same argument + */ + if (!strcmp (Token, Args[i].Name)) + { + UseCount = Args[i].UseCount; + + Args[i].Offset[UseCount] = (Token - Gbl_MainTokenBuffer) - MacroBodyOffset; + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Macro Arg #%u: %s UseCount %u Offset %u \n", + Gbl_CurrentLineNumber, i, Token, + UseCount+1, Args[i].Offset[UseCount]); + + Args[i].UseCount++; + if (Args[i].UseCount >= PR_MAX_ARG_INSTANCES) + { + PrError (ASL_ERROR, ASL_MSG_TOO_MANY_ARGUMENTS, + THIS_TOKEN_OFFSET (Token)); + + return; + } + break; + } + } + + Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next); + } + + BodyInSource = &Gbl_CurrentLineBuffer[MacroBodyOffset]; + + +AddMacroToList: + + /* Check if name is already defined first */ + + DefineInfo = PrMatchDefine (Name); + if (DefineInfo) + { + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "#define: macro name already exists: %s\n", + Gbl_CurrentLineNumber, Name); + + /* Error only if not exactly the same macro */ + + if (strcmp (DefineInfo->Body, BodyInSource) || + (DefineInfo->ArgCount != ArgCount)) + { + PrError (ASL_ERROR, ASL_MSG_EXISTING_NAME, + THIS_TOKEN_OFFSET (Name)); + } + + return; + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Macro body: %s \n", + Gbl_CurrentLineNumber, BodyInSource); + + /* Add macro to the #define list */ + + DefineInfo = PrAddDefine (Name, BodyInSource, FALSE); + if (DefineInfo) + { + Body = UtLocalCalloc (strlen (BodyInSource) + 1); + strcpy (Body, BodyInSource); + + DefineInfo->Body = Body; + DefineInfo->Args = Args; + DefineInfo->ArgCount = ArgCount; + } +} + + +/******************************************************************************* + * + * FUNCTION: PrDoMacroInvocation + * + * PARAMETERS: TokenBuffer - Current line buffer + * MacroStart - Start of the macro invocation within + * the token buffer + * DefineInfo - Info for this macro + * Next - "Next" buffer from GetNextToken + * + * RETURN: None + * + * DESCRIPTION: Expand a macro invocation + * + ******************************************************************************/ + +void +PrDoMacroInvocation ( + char *TokenBuffer, + char *MacroStart, + PR_DEFINE_INFO *DefineInfo, + char **Next) +{ + PR_MACRO_ARG *Args; + char *Token = NULL; + UINT32 TokenOffset; + UINT32 Length; + UINT32 i; + + + /* Take a copy of the macro body for expansion */ + + strcpy (Gbl_MacroTokenBuffer, DefineInfo->Body); + + /* Replace each argument within the prototype body */ + + Args = DefineInfo->Args; + if (!Args->Name) + { + /* This macro has no arguments */ + + Token = PrGetNextToken (NULL, PR_MACRO_ARGUMENTS, Next); + if (!Token) + { + goto BadInvocation; + } + + TokenOffset = (MacroStart - TokenBuffer); + Length = Token - MacroStart + strlen (Token) + 1; + + PrReplaceData ( + &Gbl_CurrentLineBuffer[TokenOffset], Length, + Gbl_MacroTokenBuffer, strlen (Gbl_MacroTokenBuffer)); + return; + } + + while (Args->Name) + { + /* Get the next argument from macro invocation */ + + Token = PrGetNextToken (NULL, PR_MACRO_SEPARATORS, Next); + if (!Token) + { + goto BadInvocation; + } + + /* Replace all instances of this argument */ + + for (i = 0; i < Args->UseCount; i++) + { + /* Offset zero indicates "arg not used" */ + /* TBD: Not really needed now, with UseCount available */ + + if (Args->Offset[i] == 0) + { + break; + } + + PrReplaceData ( + &Gbl_MacroTokenBuffer[Args->Offset[i]], strlen (Args->Name), + Token, strlen (Token)); + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "ExpandArg: %s \n", + Gbl_CurrentLineNumber, Gbl_MacroTokenBuffer); + } + + Args++; + } + + /* TBD: need to make sure macro was not invoked with too many arguments */ + + if (!Token) + { + return; + } + + /* Replace the entire macro invocation with the expanded macro */ + + TokenOffset = (MacroStart - TokenBuffer); + Length = Token - MacroStart + strlen (Token) + 1; + + PrReplaceData ( + &Gbl_CurrentLineBuffer[TokenOffset], Length, + Gbl_MacroTokenBuffer, strlen (Gbl_MacroTokenBuffer)); + + return; + + +BadInvocation: + PrError (ASL_ERROR, ASL_MSG_INVALID_INVOCATION, + THIS_TOKEN_OFFSET (MacroStart)); + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Bad macro invocation: %s \n", + Gbl_CurrentLineNumber, Gbl_MacroTokenBuffer); + return; +} diff --git a/sys/contrib/dev/acpica/compiler/prparser.l b/sys/contrib/dev/acpica/compiler/prparser.l new file mode 100644 index 0000000..34daa48 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/prparser.l @@ -0,0 +1,153 @@ +%{ +/****************************************************************************** + * + * Module Name: prparser.l - Flex input file for preprocessor lexer + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include "prparser.y.h" + +/* Buffer to pass strings to the parser */ + +#define STRING_SETUP strcpy (StringBuffer, PrParsertext);\ + PrParserlval.str = StringBuffer + +#define YY_NO_INPUT /* No file input, we use strings only */ + +#define _COMPONENT ACPI_COMPILER + ACPI_MODULE_NAME ("prscanner") +%} + +%option noyywrap +%option nounput + +Number [0-9a-fA-F]+ +HexNumber 0[xX][0-9a-fA-F]+ +WhiteSpace [ \t\v\r]+ +NewLine [\n] +Identifier [a-zA-Z][0-9a-zA-Z]* + +%% + +\( return (EXPOP_PAREN_OPEN); +\) return (EXPOP_PAREN_CLOSE); +\~ return (EXPOP_ONES_COMPLIMENT); +\! return (EXPOP_LOGICAL_NOT); +\* return (EXPOP_MULTIPLY); +\/ return (EXPOP_DIVIDE); +\% return (EXPOP_MODULO); +\+ return (EXPOP_ADD); +\- return (EXPOP_SUBTRACT); +">>" return (EXPOP_SHIFT_RIGHT); +"<<" return (EXPOP_SHIFT_LEFT); +\< return (EXPOP_LESS); +\> return (EXPOP_GREATER); +"<=" return (EXPOP_LESS_EQUAL); +">=" return (EXPOP_GREATER_EQUAL); +"==" return (EXPOP_EQUAL); +"!=" return (EXPOP_NOT_EQUAL); +\& return (EXPOP_AND); +\^ return (EXPOP_XOR); +\| return (EXPOP_OR); +"&&" return (EXPOP_LOGICAL_AND); +"||" return (EXPOP_LOGICAL_OR); + +"defined" return (EXPOP_DEFINE); +{Identifier} {STRING_SETUP; return (EXPOP_IDENTIFIER);} + +<<EOF>> return (EXPOP_EOF); /* null end-of-string */ + +{Number} return (EXPOP_NUMBER); +{HexNumber} return (EXPOP_HEX_NUMBER); +{NewLine} return (EXPOP_NEW_LINE); +{WhiteSpace} /* Ignore */ + +. return (EXPOP_EOF); +%% + +/* + * Local support functions + */ +YY_BUFFER_STATE LexBuffer; + + +/****************************************************************************** + * + * FUNCTION: PrInitLexer + * + * PARAMETERS: String - Input string to be parsed + * + * RETURN: TRUE if parser returns NULL. FALSE otherwise. + * + * DESCRIPTION: Initialization routine for lexer. The lexer needs + * a buffer to handle strings instead of a file. + * + *****************************************************************************/ + +int +PrInitLexer ( + char *String) +{ + + LexBuffer = yy_scan_string (String); + return (LexBuffer == NULL); +} + + +/****************************************************************************** + * + * FUNCTION: PrTerminateLexer + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Termination routine for thelexer. + * + *****************************************************************************/ + +void +PrTerminateLexer ( + void) +{ + + yy_delete_buffer (LexBuffer); +} diff --git a/sys/contrib/dev/acpica/compiler/prparser.y b/sys/contrib/dev/acpica/compiler/prparser.y new file mode 100644 index 0000000..81cede3 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/prparser.y @@ -0,0 +1,284 @@ +%{ +/****************************************************************************** + * + * Module Name: prparser.y - Bison input file for preprocessor parser + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +#define _COMPONENT ASL_PREPROCESSOR + ACPI_MODULE_NAME ("prparser") + +int PrParserlex (void); +int PrParserparse (void); +void PrParsererror (char const *msg); +extern char *PrParsertext; + +UINT64 PrParserResult; /* Expression return value */ + +/* Bison/yacc configuration */ + +#define yytname PrParsername +#define YYDEBUG 1 /* Enable debug output */ +#define YYERROR_VERBOSE 1 /* Verbose error messages */ +#define YYFLAG -32768 + +/* Define YYMALLOC/YYFREE to prevent redefinition errors */ + +#define YYMALLOC malloc +#define YYFREE free +%} + +%union +{ + UINT64 value; + UINT32 op; + char *str; +} + +/*! [Begin] no source code translation */ + +%type <value> Expression + +%token <op> EXPOP_EOF +%token <op> EXPOP_NEW_LINE +%token <op> EXPOP_NUMBER +%token <op> EXPOP_HEX_NUMBER +%token <op> EXPOP_RESERVED1 +%token <op> EXPOP_RESERVED2 +%token <op> EXPOP_PAREN_OPEN +%token <op> EXPOP_PAREN_CLOSE + +%left <op> EXPOP_LOGICAL_OR +%left <op> EXPOP_LOGICAL_AND +%left <op> EXPOP_OR +%left <op> EXPOP_XOR +%left <op> EXPOP_AND +%left <op> EXPOP_EQUAL EXPOP_NOT_EQUAL +%left <op> EXPOP_GREATER EXPOP_LESS EXPOP_GREATER_EQUAL EXPOP_LESS_EQUAL +%left <op> EXPOP_SHIFT_RIGHT EXPOP_SHIFT_LEFT +%left <op> EXPOP_ADD EXPOP_SUBTRACT +%left <op> EXPOP_MULTIPLY EXPOP_DIVIDE EXPOP_MODULO +%right <op> EXPOP_ONES_COMPLIMENT EXPOP_LOGICAL_NOT + +/* Tokens above must be kept in synch with dtparser.y */ + +%token <op> EXPOP_DEFINE +%token <op> EXPOP_IDENTIFIER + +%% + +/* + * Operator precedence rules (from K&R) + * + * 1) ( ) + * 2) ! ~ (unary operators that are supported here) + * 3) * / % + * 4) + - + * 5) >> << + * 6) < > <= >= + * 7) == != + * 8) & + * 9) ^ + * 10) | + * 11) && + * 12) || + */ + +/*! [End] no source code translation !*/ + +Value + : Expression EXPOP_NEW_LINE { PrParserResult=$1; return 0; } /* End of line (newline) */ + | Expression EXPOP_EOF { PrParserResult=$1; return 0; } /* End of string (0) */ + ; + +Expression + + /* Unary operators */ + + : EXPOP_LOGICAL_NOT Expression { $$ = DtDoOperator ($2, EXPOP_LOGICAL_NOT, $2);} + | EXPOP_ONES_COMPLIMENT Expression { $$ = DtDoOperator ($2, EXPOP_ONES_COMPLIMENT, $2);} + + /* Binary operators */ + + | Expression EXPOP_MULTIPLY Expression { $$ = DtDoOperator ($1, EXPOP_MULTIPLY, $3);} + | Expression EXPOP_DIVIDE Expression { $$ = DtDoOperator ($1, EXPOP_DIVIDE, $3);} + | Expression EXPOP_MODULO Expression { $$ = DtDoOperator ($1, EXPOP_MODULO, $3);} + | Expression EXPOP_ADD Expression { $$ = DtDoOperator ($1, EXPOP_ADD, $3);} + | Expression EXPOP_SUBTRACT Expression { $$ = DtDoOperator ($1, EXPOP_SUBTRACT, $3);} + | Expression EXPOP_SHIFT_RIGHT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_RIGHT, $3);} + | Expression EXPOP_SHIFT_LEFT Expression { $$ = DtDoOperator ($1, EXPOP_SHIFT_LEFT, $3);} + | Expression EXPOP_GREATER Expression { $$ = DtDoOperator ($1, EXPOP_GREATER, $3);} + | Expression EXPOP_LESS Expression { $$ = DtDoOperator ($1, EXPOP_LESS, $3);} + | Expression EXPOP_GREATER_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_GREATER_EQUAL, $3);} + | Expression EXPOP_LESS_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_LESS_EQUAL, $3);} + | Expression EXPOP_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_EQUAL, $3);} + | Expression EXPOP_NOT_EQUAL Expression { $$ = DtDoOperator ($1, EXPOP_NOT_EQUAL, $3);} + | Expression EXPOP_AND Expression { $$ = DtDoOperator ($1, EXPOP_AND, $3);} + | Expression EXPOP_XOR Expression { $$ = DtDoOperator ($1, EXPOP_XOR, $3);} + | Expression EXPOP_OR Expression { $$ = DtDoOperator ($1, EXPOP_OR, $3);} + | Expression EXPOP_LOGICAL_AND Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_AND, $3);} + | Expression EXPOP_LOGICAL_OR Expression { $$ = DtDoOperator ($1, EXPOP_LOGICAL_OR, $3);} + + /* Parentheses: '(' Expression ')' */ + + | EXPOP_PAREN_OPEN Expression + EXPOP_PAREN_CLOSE { $$ = $2;} + + /* #if defined (ID) or #if defined ID */ + + | EXPOP_DEFINE EXPOP_PAREN_OPEN EXPOP_IDENTIFIER + EXPOP_PAREN_CLOSE { $$ = PrIsDefined (PrParserlval.str);} + + | EXPOP_DEFINE EXPOP_IDENTIFIER { $$ = PrIsDefined (PrParserlval.str);} + + | EXPOP_IDENTIFIER { $$ = PrResolveDefine (PrParserlval.str);} + + /* Default base for a non-prefixed integer is 10 */ + + | EXPOP_NUMBER { UtStrtoul64 (PrParsertext, 10, &$$);} + + /* Standard hex number (0x1234) */ + + | EXPOP_HEX_NUMBER { UtStrtoul64 (PrParsertext, 16, &$$);} + ; +%% + +/* + * Local support functions, including parser entry point + */ +#define PR_FIRST_PARSE_OPCODE EXPOP_EOF +#define PR_YYTNAME_START 3 + + +/****************************************************************************** + * + * FUNCTION: PrParsererror + * + * PARAMETERS: Message - Parser-generated error message + * + * RETURN: None + * + * DESCRIPTION: Handler for parser errors + * + *****************************************************************************/ + +void +PrParsererror ( + char const *Message) +{ + DtError (ASL_ERROR, ASL_MSG_SYNTAX, + NULL, (char *) Message); +} + + +/****************************************************************************** + * + * FUNCTION: PrGetOpName + * + * PARAMETERS: ParseOpcode - Parser token (EXPOP_*) + * + * RETURN: Pointer to the opcode name + * + * DESCRIPTION: Get the ascii name of the parse opcode for debug output + * + *****************************************************************************/ + +char * +PrGetOpName ( + UINT32 ParseOpcode) +{ +#ifdef ASL_YYTNAME_START + /* + * First entries (PR_YYTNAME_START) in yytname are special reserved names. + * Ignore first 6 characters of name (EXPOP_) + */ + return ((char *) yytname + [(ParseOpcode - PR_FIRST_PARSE_OPCODE) + PR_YYTNAME_START] + 6); +#else + return ("[Unknown parser generator]"); +#endif +} + + +/****************************************************************************** + * + * FUNCTION: PrEvaluateExpression + * + * PARAMETERS: ExprString - Expression to be evaluated. Must be + * terminated by either a newline or a NUL + * string terminator + * + * RETURN: 64-bit value for the expression + * + * DESCRIPTION: Main entry point for the DT expression parser + * + *****************************************************************************/ + +UINT64 +PrEvaluateExpression ( + char *ExprString) +{ + + DbgPrint (ASL_DEBUG_OUTPUT, + "**** Input expression: %s\n", ExprString); + + /* Point lexer to the input string */ + + if (PrInitLexer (ExprString)) + { + DtError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, + NULL, "Could not initialize lexer"); + return (0); + } + + /* Parse/Evaluate the input string (value returned in PrParserResult) */ + + PrParserparse (); + PrTerminateLexer (); + + DbgPrint (ASL_DEBUG_OUTPUT, + "**** Parser returned value: %u (%8.8X%8.8X)\n", + (UINT32) PrParserResult, ACPI_FORMAT_UINT64 (PrParserResult)); + + return (PrParserResult); +} diff --git a/sys/contrib/dev/acpica/compiler/prscan.c b/sys/contrib/dev/acpica/compiler/prscan.c new file mode 100644 index 0000000..a47f07f --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/prscan.c @@ -0,0 +1,772 @@ +/****************************************************************************** + * + * Module Name: prscan - Preprocessor start-up and file scan module + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#define _DECLARE_PR_GLOBALS + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + +/* + * TBDs: + * + * No nested macros, maybe never + * Implement ASL "Include" as well as "#include" here? + */ +#define _COMPONENT ASL_PREPROCESSOR + ACPI_MODULE_NAME ("prscan") + + +/* Local prototypes */ + +static void +PrPreprocessInputFile ( + void); + +static void +PrDoDirective ( + char *DirectiveToken, + char **Next, + BOOLEAN *IgnoringThisCodeBlock); + +static int +PrMatchDirective ( + char *Directive); + +/* + * Supported preprocessor directives + */ +static const PR_DIRECTIVE_INFO Gbl_DirectiveInfo[] = +{ + {"define", 1}, + {"elif", 0}, /* Converted to #else..#if internally */ + {"else", 0}, + {"endif", 0}, + {"error", 1}, + {"if", 1}, + {"ifdef", 1}, + {"ifndef", 1}, + {"include", 0}, /* Argument is not standard format, so 0 */ + {"line", 1}, + {"pragma", 1}, + {"undef", 1}, + {"warning", 1}, + {NULL, 0} +}; + +enum Gbl_DirectiveIndexes +{ + PR_DIRECTIVE_DEFINE = 0, + PR_DIRECTIVE_ELIF, + PR_DIRECTIVE_ELSE, + PR_DIRECTIVE_ENDIF, + PR_DIRECTIVE_ERROR, + PR_DIRECTIVE_IF, + PR_DIRECTIVE_IFDEF, + PR_DIRECTIVE_IFNDEF, + PR_DIRECTIVE_INCLUDE, + PR_DIRECTIVE_LINE, + PR_DIRECTIVE_PRAGMA, + PR_DIRECTIVE_UNDEF, + PR_DIRECTIVE_WARNING, +}; + +#define ASL_DIRECTIVE_NOT_FOUND -1 + + +/******************************************************************************* + * + * FUNCTION: PrInitializePreprocessor + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Startup initialization for the Preprocessor. + * + ******************************************************************************/ + +void +PrInitializePreprocessor ( + void) +{ + /* Init globals and the list of #defines */ + + PrInitializeGlobals (); + Gbl_DefineList = NULL; +} + + +/******************************************************************************* + * + * FUNCTION: PrInitializeGlobals + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Initialize globals for the Preprocessor. Used for startuup + * initialization and re-initialization between compiles during + * a multiple source file compile. + * + ******************************************************************************/ + +void +PrInitializeGlobals ( + void) +{ + /* Init globals */ + + Gbl_IfDepth = 0; + Gbl_InputFileList = NULL; + Gbl_CurrentLineNumber = 0; + Gbl_PreprocessorLineNumber = 1; + Gbl_PreprocessorError = FALSE; +} + + +/******************************************************************************* + * + * FUNCTION: PrTerminatePreprocessor + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Termination of the preprocessor. Delete lists. Keep any + * defines that were specified on the command line, in order to + * support multiple compiles with a single compiler invocation. + * + ******************************************************************************/ + +void +PrTerminatePreprocessor ( + void) +{ + PR_DEFINE_INFO *DefineInfo; + + + /* + * The persistent defines (created on the command line) are always at the + * end of the list. We save them. + */ + while ((Gbl_DefineList) && (!Gbl_DefineList->Persist)) + { + DefineInfo = Gbl_DefineList; + Gbl_DefineList = DefineInfo->Next; + + ACPI_FREE (DefineInfo->Replacement); + ACPI_FREE (DefineInfo->Identifier); + ACPI_FREE (DefineInfo); + } +} + + +/******************************************************************************* + * + * FUNCTION: PrDoPreprocess + * + * PARAMETERS: None + * + * RETURN: Error Status. TRUE if error, FALSE if OK. + * + * DESCRIPTION: Main entry point for the iASL Preprocessor. Input file must + * be already open. Handles multiple input files via the + * #include directive. + * + ******************************************************************************/ + +BOOLEAN +PrDoPreprocess ( + void) +{ + BOOLEAN MoreInputFiles; + + + DbgPrint (ASL_DEBUG_OUTPUT, "Starting preprocessing phase\n\n"); + + + FlSeekFile (ASL_FILE_INPUT, 0); + PrDumpPredefinedNames (); + + /* Main preprocessor loop, handles include files */ + + do + { + PrPreprocessInputFile (); + MoreInputFiles = PrPopInputFileStack (); + + } while (MoreInputFiles); + + + /* + * TBD: is this necessary? (Do we abort on any preprocessing errors?) + */ + if (Gbl_PreprocessorError) + { + /* TBD: can't use source_output file for preprocessor error reporting */ + + Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle = NULL; + PrTerminatePreprocessor (); + return (TRUE); + } + + /* Point compiler input to the new preprocessor file (.i) */ + + FlCloseFile (ASL_FILE_INPUT); + Gbl_Files[ASL_FILE_INPUT].Handle = Gbl_Files[ASL_FILE_PREPROCESSOR].Handle; + AslCompilerin = Gbl_Files[ASL_FILE_INPUT].Handle; + + /* Reset globals to allow compiler to run */ + + FlSeekFile (ASL_FILE_INPUT, 0); + Gbl_CurrentLineNumber = 1; + + DbgPrint (ASL_DEBUG_OUTPUT, "Preprocessing phase complete \n\n"); + return (FALSE); +} + + +/******************************************************************************* + * + * FUNCTION: PrPreprocessInputFile + * + * PARAMETERS: None + * + * RETURN: None + * + * DESCRIPTION: Preprocess one entire file, line-by-line. + * + * Input: Raw user ASL from ASL_FILE_INPUT + * Output: Preprocessed file written to ASL_FILE_PREPROCESSOR + * + ******************************************************************************/ + +static void +PrPreprocessInputFile ( + void) +{ + UINT32 Offset; + char *Token; + char *ReplaceString; + PR_DEFINE_INFO *DefineInfo; + ACPI_SIZE TokenOffset; + BOOLEAN IgnoringThisCodeBlock = FALSE; + char *Next; + int OffsetAdjust; + + + /* Scan line-by-line. Comments and blank lines are skipped by this function */ + + while ((Offset = DtGetNextLine (Gbl_Files[ASL_FILE_INPUT].Handle)) != ASL_EOF) + { + /* Need a copy of the input line for strok() */ + + strcpy (Gbl_MainTokenBuffer, Gbl_CurrentLineBuffer); + Token = PrGetNextToken (Gbl_MainTokenBuffer, PR_TOKEN_SEPARATORS, &Next); + OffsetAdjust = 0; + + /* All preprocessor directives must begin with '#' */ + + if (Token && (*Token == '#')) + { + if (strlen (Token) == 1) + { + Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); + } + else + { + Token++; /* Skip leading # */ + } + + /* Execute the directive, do not write line to output file */ + + PrDoDirective (Token, &Next, &IgnoringThisCodeBlock); + continue; + } + + /* + * If we are currently within the part of an IF/ELSE block that is + * FALSE, ignore the line and do not write it to the output file. + * This continues until an #else or #endif is encountered. + */ + if (IgnoringThisCodeBlock == TRUE) + { + continue; + } + + /* Match and replace all #defined names within this source line */ + + while (Token) + { + DefineInfo = PrMatchDefine (Token); + if (DefineInfo) + { + if (DefineInfo->Body) + { + /* This is a macro */ + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Matched Macro: %s->%s\n", + Gbl_CurrentLineNumber, DefineInfo->Identifier, + DefineInfo->Replacement); + + PrDoMacroInvocation (Gbl_MainTokenBuffer, Token, + DefineInfo, &Next); + } + else + { + ReplaceString = DefineInfo->Replacement; + + /* Replace the name in the original line buffer */ + + TokenOffset = Token - Gbl_MainTokenBuffer + OffsetAdjust; + PrReplaceData ( + &Gbl_CurrentLineBuffer[TokenOffset], strlen (Token), + ReplaceString, strlen (ReplaceString)); + + /* Adjust for length difference between old and new name length */ + + OffsetAdjust += strlen (ReplaceString) - strlen (Token); + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Matched #define: %s->%s\n", + Gbl_CurrentLineNumber, Token, + *ReplaceString ? ReplaceString : "(NULL STRING)"); + } + } + + Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, &Next); + } + +#if 0 +/* Line prefix */ + FlPrintFile (ASL_FILE_PREPROCESSOR, "/* %14s %.5u i:%.5u */ ", + Gbl_Files[ASL_FILE_INPUT].Filename, + Gbl_CurrentLineNumber, Gbl_PreprocessorLineNumber); +#endif + + /* + * Emit a #line directive if necessary, to keep the line numbers in + * the (.i) file synchronized with the original source code file, so + * that the correct line number appears in any error messages + * generated by the actual compiler. + */ + if (Gbl_CurrentLineNumber > (Gbl_PreviousLineNumber + 1)) + { + FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u\n", + Gbl_CurrentLineNumber); + } + + Gbl_PreviousLineNumber = Gbl_CurrentLineNumber; + Gbl_PreprocessorLineNumber++; + + /* + * Now we can write the possibly modified source line to the + * preprocessor (.i) file + */ + FlWriteFile (ASL_FILE_PREPROCESSOR, Gbl_CurrentLineBuffer, + strlen (Gbl_CurrentLineBuffer)); + } +} + + +/******************************************************************************* + * + * FUNCTION: PrDoDirective + * + * PARAMETERS: Directive - Pointer to directive name token + * Next - "Next" buffer from GetNextToken + * IgnoringThisCodeBlock - Where the "ignore code" flag is + * returned. + * + * RETURN: IgnoringThisCodeBlock: Set to TRUE if we are skipping the FALSE + * part of an #if or #else block. Set to FALSE when the + * corresponding #else or #endif is encountered. + * + * DESCRIPTION: Main processing for all preprocessor directives + * + ******************************************************************************/ + +static void +PrDoDirective ( + char *DirectiveToken, + char **Next, + BOOLEAN *IgnoringThisCodeBlock) +{ + char *Token = Gbl_MainTokenBuffer; + char *Token2; + char *End; + UINT64 Value; + ACPI_SIZE TokenOffset; + int Directive; + ACPI_STATUS Status; + + + if (!DirectiveToken) + { + goto SyntaxError; + } + + Directive = PrMatchDirective (DirectiveToken); + if (Directive == ASL_DIRECTIVE_NOT_FOUND) + { + PrError (ASL_ERROR, ASL_MSG_UNKNOWN_DIRECTIVE, + THIS_TOKEN_OFFSET (DirectiveToken)); + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "#%s: Unknown directive\n", + Gbl_CurrentLineNumber, DirectiveToken); + return; + } + + /* TBD: Need a faster way to do this: */ + + if ((Directive == PR_DIRECTIVE_ELIF) || + (Directive == PR_DIRECTIVE_ELSE) || + (Directive == PR_DIRECTIVE_ENDIF)) + { + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n", + Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name); + } + + /* + * Need to always check for #else, #elif, #endif regardless of + * whether we are ignoring the current code block, since these + * are conditional code block terminators. + */ + switch (Directive) + { + case PR_DIRECTIVE_ELIF: + *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock); + if (*IgnoringThisCodeBlock == TRUE) + { + /* Not executing the ELSE part -- all done here */ + return; + } + + /* Will execute the ELSE..IF part */ + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "#elif - Executing else block\n", + Gbl_CurrentLineNumber); + Directive = PR_DIRECTIVE_IF; + break; + + case PR_DIRECTIVE_ELSE: + *IgnoringThisCodeBlock = !(*IgnoringThisCodeBlock); + return; + + case PR_DIRECTIVE_ENDIF: + *IgnoringThisCodeBlock = FALSE; + Gbl_IfDepth--; + if (Gbl_IfDepth < 0) + { + PrError (ASL_ERROR, ASL_MSG_ENDIF_MISMATCH, + THIS_TOKEN_OFFSET (DirectiveToken)); + Gbl_IfDepth = 0; + } + return; + + default: + break; + } + + /* + * At this point, if we are ignoring the current code block, + * do not process any more directives (i.e., ignore them also.) + */ + if (*IgnoringThisCodeBlock == TRUE) + { + return; + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID "Begin #%s\n", + Gbl_CurrentLineNumber, Gbl_DirectiveInfo[Directive].Name); + + /* Most directives have at least one argument */ + + if (Gbl_DirectiveInfo[Directive].ArgCount == 1) + { + Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); + if (!Token) + { + goto SyntaxError; + } + } + + switch (Directive) + { + case PR_DIRECTIVE_DEFINE: + /* + * By definition, if first char after the name is a paren, + * this is a function macro. + */ + TokenOffset = Token - Gbl_MainTokenBuffer + strlen (Token); + if (*(&Gbl_CurrentLineBuffer[TokenOffset]) == '(') + { +#ifndef MACROS_SUPPORTED + AcpiOsPrintf ("%s ERROR - line %u: #define macros are not supported yet\n", + Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber); + exit(1); +#else + PrAddMacro (Token, Next); +#endif + } + else + { + /* Use the remainder of the line for the #define */ + + Token2 = *Next; + if (Token2) + { + while ((*Token2 == ' ') || (*Token2 == '\t')) + { + Token2++; + } + End = Token2; + while (*End != '\n') + { + End++; + } + *End = 0; + } + else + { + Token2 = ""; + } +#if 0 + Token2 = PrGetNextToken (NULL, "\n", /*PR_TOKEN_SEPARATORS,*/ Next); + if (!Token2) + { + Token2 = ""; + } +#endif + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "New #define: %s->%s\n", + Gbl_CurrentLineNumber, Token, Token2); + + PrAddDefine (Token, Token2, FALSE); + } + break; + + case PR_DIRECTIVE_ERROR: + /* TBD compiler should abort */ + /* Note: No macro expansion */ + + PrError (ASL_ERROR, ASL_MSG_ERROR_DIRECTIVE, + THIS_TOKEN_OFFSET (Token)); + break; + + case PR_DIRECTIVE_IF: + TokenOffset = Token - Gbl_MainTokenBuffer; + + /* Need to expand #define macros in the expression string first */ + + Status = PrResolveIntegerExpression ( + &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); + if (ACPI_FAILURE (Status)) + { + return; + } + + if (!Value) + { + *IgnoringThisCodeBlock = TRUE; + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Resolved #if: %8.8X%8.8X %s\n", + Gbl_CurrentLineNumber, ACPI_FORMAT_UINT64 (Value), + *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>"); + + Gbl_IfDepth++; + break; + + case PR_DIRECTIVE_IFDEF: + if (!PrMatchDefine (Token)) + { + *IgnoringThisCodeBlock = TRUE; + } + + Gbl_IfDepth++; + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Start #ifdef %s\n", Gbl_CurrentLineNumber, + *IgnoringThisCodeBlock ? "<Skipping Block>" : "<Executing Block>"); + break; + + case PR_DIRECTIVE_IFNDEF: + if (PrMatchDefine (Token)) + { + *IgnoringThisCodeBlock = TRUE; + } + + Gbl_IfDepth++; + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Start #ifndef %2.2X\n", Gbl_CurrentLineNumber, + *IgnoringThisCodeBlock, Gbl_CurrentLineNumber); + break; + + case PR_DIRECTIVE_INCLUDE: + Token = PrGetNextToken (NULL, " \"<>", Next); + if (!Token) + { + goto SyntaxError; + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Start #include file %s\n", Gbl_CurrentLineNumber, + Token, Gbl_CurrentLineNumber); + + PrOpenIncludeFile (Token); + break; + + case PR_DIRECTIVE_LINE: + TokenOffset = Token - Gbl_MainTokenBuffer; + + Status = PrResolveIntegerExpression ( + &Gbl_CurrentLineBuffer[TokenOffset-1], &Value); + if (ACPI_FAILURE (Status)) + { + return; + } + + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "User #line invocation %s\n", Gbl_CurrentLineNumber, + Token); + + /* Update local line numbers */ + + Gbl_CurrentLineNumber = (UINT32) Value; + Gbl_PreviousLineNumber = 0; + + /* Emit #line into the preprocessor file */ + + FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", + Gbl_CurrentLineNumber, Gbl_Files[ASL_FILE_INPUT].Filename); + break; + + case PR_DIRECTIVE_PRAGMA: + /* Only "#pragma message" supported at this time */ + + if (strcmp (Token, "message")) + { + PrError (ASL_ERROR, ASL_MSG_UNKNOWN_PRAGMA, + THIS_TOKEN_OFFSET (Token)); + return; + } + + Token = PrGetNextToken (NULL, PR_TOKEN_SEPARATORS, Next); + if (!Token) + { + goto SyntaxError; + } + + TokenOffset = Token - Gbl_MainTokenBuffer; + AcpiOsPrintf ("%s\n", &Gbl_CurrentLineBuffer[TokenOffset]); + break; + + case PR_DIRECTIVE_UNDEF: + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "#undef: %s\n", Gbl_CurrentLineNumber, Token); + + PrRemoveDefine (Token); + break; + + case PR_DIRECTIVE_WARNING: + PrError (ASL_WARNING, ASL_MSG_ERROR_DIRECTIVE, + THIS_TOKEN_OFFSET (Token)); + break; + + default: + /* Should never get here */ + DbgPrint (ASL_DEBUG_OUTPUT, PR_PREFIX_ID + "Unrecognized directive: %u\n", + Gbl_CurrentLineNumber, Directive); + break; + } + + return; + + +SyntaxError: + + PrError (ASL_ERROR, ASL_MSG_DIRECTIVE_SYNTAX, + THIS_TOKEN_OFFSET (DirectiveToken)); + return; +} + + +/******************************************************************************* + * + * FUNCTION: PrMatchDirective + * + * PARAMETERS: Directive - Pointer to directive name token + * + * RETURN: Index into command array, -1 if not found + * + * DESCRIPTION: Lookup the incoming directive in the known directives table. + * + ******************************************************************************/ + +static int +PrMatchDirective ( + char *Directive) +{ + int i; + + + if (!Directive || Directive[0] == 0) + { + return (ASL_DIRECTIVE_NOT_FOUND); + } + + for (i = 0; Gbl_DirectiveInfo[i].Name; i++) + { + if (!strcmp (Gbl_DirectiveInfo[i].Name, Directive)) + { + return (i); + } + } + + return (ASL_DIRECTIVE_NOT_FOUND); /* Command not recognized */ +} diff --git a/sys/contrib/dev/acpica/compiler/prutils.c b/sys/contrib/dev/acpica/compiler/prutils.c new file mode 100644 index 0000000..0bbd8f5 --- /dev/null +++ b/sys/contrib/dev/acpica/compiler/prutils.c @@ -0,0 +1,468 @@ +/****************************************************************************** + * + * Module Name: prutils - Preprocessor utilities + * + *****************************************************************************/ + +/* + * Copyright (C) 2000 - 2012, Intel Corp. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce at minimum a disclaimer + * substantially similar to the "NO WARRANTY" disclaimer below + * ("Disclaimer") and any redistribution must be conditioned upon + * including a substantially similar Disclaimer requirement for further + * binary redistribution. + * 3. Neither the names of the above-listed copyright holders nor the names + * of any contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * NO WARRANTY + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + */ + +#include <contrib/dev/acpica/compiler/aslcompiler.h> +#include <contrib/dev/acpica/compiler/dtcompiler.h> + + +#define _COMPONENT ASL_PREPROCESSOR + ACPI_MODULE_NAME ("prutils") + + +/****************************************************************************** + * + * FUNCTION: PrGetNextToken + * + * PARAMETERS: Buffer - Current line buffer + * MatchString - String with valid token delimiters + * Next - Set to next possible token in buffer + * + * RETURN: Next token (null-terminated). Modifies the input line. + * Remainder of line is stored in *Next. + * + * DESCRIPTION: Local implementation of strtok() with local storage for the + * next pointer. Not only thread-safe, but allows multiple + * parsing of substrings such as expressions. + * + *****************************************************************************/ + +char * +PrGetNextToken ( + char *Buffer, + char *MatchString, + char **Next) +{ + char *TokenStart; + + + if (!Buffer) + { + /* Use Next if it is valid */ + + Buffer = *Next; + if (!(*Next)) + { + return (NULL); + } + } + + /* Skip any leading delimiters */ + + while (*Buffer) + { + if (strchr (MatchString, *Buffer)) + { + Buffer++; + } + else + { + break; + } + } + + /* Anything left on the line? */ + + if (!(*Buffer)) + { + *Next = NULL; + return (NULL); + } + + TokenStart = Buffer; + + /* Find the end of this token */ + + while (*Buffer) + { + if (strchr (MatchString, *Buffer)) + { + *Buffer = 0; + *Next = Buffer+1; + if (!**Next) + { + *Next = NULL; + } + return (TokenStart); + } + Buffer++; + } + + *Next = NULL; + return (TokenStart); +} + + +/******************************************************************************* + * + * FUNCTION: PrError + * + * PARAMETERS: Level - Seriousness (Warning/error, etc.) + * MessageId - Index into global message buffer + * Column - Column in current line + * + * RETURN: None + * + * DESCRIPTION: Preprocessor error reporting. Front end to AslCommonError2 + * + ******************************************************************************/ + +void +PrError ( + UINT8 Level, + UINT8 MessageId, + UINT32 Column) +{ +#if 0 + AcpiOsPrintf ("%s (%u) : %s", Gbl_Files[ASL_FILE_INPUT].Filename, + Gbl_CurrentLineNumber, Gbl_CurrentLineBuffer); +#endif + + + if (Column > 120) + { + Column = 0; + } + + /* TBD: Need Logical line number? */ + + AslCommonError2 (Level, MessageId, + Gbl_CurrentLineNumber, Column, + Gbl_CurrentLineBuffer, + Gbl_Files[ASL_FILE_INPUT].Filename, "Preprocessor"); + + Gbl_PreprocessorError = TRUE; +} + + +/******************************************************************************* + * + * FUNCTION: PrReplaceData + * + * PARAMETERS: Buffer - Original(target) buffer pointer + * LengthToRemove - Length to be removed from target buffer + * BufferToAdd - Data to be inserted into target buffer + * LengthToAdd - Length of BufferToAdd + * + * RETURN: None + * + * DESCRIPTION: Generic buffer data replacement. + * + ******************************************************************************/ + +void +PrReplaceData ( + char *Buffer, + UINT32 LengthToRemove, + char *BufferToAdd, + UINT32 LengthToAdd) +{ + UINT32 BufferLength; + + + /* Buffer is a string, so the length must include the terminating zero */ + + BufferLength = strlen (Buffer) + 1; + + if (LengthToRemove != LengthToAdd) + { + /* + * Move some of the existing data + * 1) If adding more bytes than removing, make room for the new data + * 2) if removing more bytes than adding, delete the extra space + */ + if (LengthToRemove > 0) + { + memmove ((Buffer + LengthToAdd), (Buffer + LengthToRemove), + (BufferLength - LengthToRemove)); + } + } + + /* Now we can move in the new data */ + + if (LengthToAdd > 0) + { + memmove (Buffer, BufferToAdd, LengthToAdd); + } +} + + +/******************************************************************************* + * + * FUNCTION: PrOpenIncludeFile + * + * PARAMETERS: Filename - Filename or pathname for include file + * + * RETURN: None. + * + * DESCRIPTION: Open an include file and push it on the input file stack. + * + ******************************************************************************/ + +void +PrOpenIncludeFile ( + char *Filename) +{ + FILE *IncludeFile; + ASL_INCLUDE_DIR *NextDir; + + + /* + * start the actual include file on the next line + */ + Gbl_CurrentLineOffset++; + + /* Attempt to open the include file */ + + /* If the file specifies an absolute path, just open it */ + + if ((Filename[0] == '/') || + (Filename[0] == '\\') || + (Filename[1] == ':')) + { + IncludeFile = PrOpenIncludeWithPrefix ("", Filename); + if (!IncludeFile) + { + goto ErrorExit; + } + return; + } + + /* + * The include filename is not an absolute path. + * + * First, search for the file within the "local" directory -- meaning + * the same directory that contains the source file. + * + * Construct the file pathname from the global directory name. + */ + IncludeFile = PrOpenIncludeWithPrefix (Gbl_DirectoryPath, Filename); + if (IncludeFile) + { + return; + } + + /* + * Second, search for the file within the (possibly multiple) + * directories specified by the -I option on the command line. + */ + NextDir = Gbl_IncludeDirList; + while (NextDir) + { + IncludeFile = PrOpenIncludeWithPrefix (NextDir->Dir, Filename); + if (IncludeFile) + { + return; + } + + NextDir = NextDir->Next; + } + + /* We could not open the include file after trying very hard */ + +ErrorExit: + sprintf (Gbl_MainTokenBuffer, "%s, %s", Filename, strerror (errno)); + PrError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 0); +} + + +/******************************************************************************* + * + * FUNCTION: FlOpenIncludeWithPrefix + * + * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero + * length string. + * Filename - The include filename from the source ASL. + * + * RETURN: Valid file descriptor if successful. Null otherwise. + * + * DESCRIPTION: Open an include file and push it on the input file stack. + * + ******************************************************************************/ + +FILE * +PrOpenIncludeWithPrefix ( + char *PrefixDir, + char *Filename) +{ + FILE *IncludeFile; + char *Pathname; + + + /* Build the full pathname to the file */ + + Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1); + + strcpy (Pathname, PrefixDir); + strcat (Pathname, Filename); + + DbgPrint (ASL_PARSE_OUTPUT, "\n" PR_PREFIX_ID + "Opening include file: path %s\n", + Gbl_CurrentLineNumber, Pathname); + + /* Attempt to open the file, push if successful */ + + IncludeFile = fopen (Pathname, "r"); + if (IncludeFile) + { + /* Push the include file on the open input file stack */ + + PrPushInputFileStack (IncludeFile, Pathname); + return (IncludeFile); + } + + ACPI_FREE (Pathname); + return (NULL); +} + + +/******************************************************************************* + * + * FUNCTION: AslPushInputFileStack + * + * PARAMETERS: InputFile - Open file pointer + * Filename - Name of the file + * + * RETURN: None + * + * DESCRIPTION: Push the InputFile onto the file stack, and point the parser + * to this file. Called when an include file is successfully + * opened. + * + ******************************************************************************/ + +void +PrPushInputFileStack ( + FILE *InputFile, + char *Filename) +{ + PR_FILE_NODE *Fnode; + + + /* Save the current state in an Fnode */ + + Fnode = UtLocalCalloc (sizeof (PR_FILE_NODE)); + + Fnode->File = Gbl_Files[ASL_FILE_INPUT].Handle; + Fnode->Next = Gbl_InputFileList; + Fnode->Filename = Gbl_Files[ASL_FILE_INPUT].Filename; + Fnode->CurrentLineNumber = Gbl_CurrentLineNumber; + + /* Push it on the stack */ + + Gbl_InputFileList = Fnode; + + DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID + "Push InputFile Stack: handle %p\n\n", + Gbl_CurrentLineNumber, InputFile); + + /* Reset the global line count and filename */ + + Gbl_Files[ASL_FILE_INPUT].Filename = Filename; + Gbl_Files[ASL_FILE_INPUT].Handle = InputFile; + Gbl_PreviousLineNumber = 0; + Gbl_CurrentLineNumber = 0; + + /* Emit a new #line directive for the include file */ + + FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", + 1, Filename); +} + + +/******************************************************************************* + * + * FUNCTION: AslPopInputFileStack + * + * PARAMETERS: None + * + * RETURN: 0 if a node was popped, -1 otherwise + * + * DESCRIPTION: Pop the top of the input file stack and point the parser to + * the saved parse buffer contained in the fnode. Also, set the + * global line counters to the saved values. This function is + * called when an include file reaches EOF. + * + ******************************************************************************/ + +BOOLEAN +PrPopInputFileStack ( + void) +{ + PR_FILE_NODE *Fnode; + + + Fnode = Gbl_InputFileList; + DbgPrint (ASL_PARSE_OUTPUT, "\n" PR_PREFIX_ID + "Pop InputFile Stack, Fnode %p\n\n", + Gbl_CurrentLineNumber, Fnode); + + if (!Fnode) + { + return (FALSE); + } + + /* Close the current include file */ + + fclose (Gbl_Files[ASL_FILE_INPUT].Handle); + + /* Update the top-of-stack */ + + Gbl_InputFileList = Fnode->Next; + + /* Reset global line counter and filename */ + + Gbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename; + Gbl_Files[ASL_FILE_INPUT].Handle = Fnode->File; + Gbl_CurrentLineNumber = Fnode->CurrentLineNumber; + Gbl_PreviousLineNumber = 0; + + /* Emit a new #line directive after the include file */ + + FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", + Gbl_CurrentLineNumber + 1, Fnode->Filename); + + /* All done with this node */ + + ACPI_FREE (Fnode); + return (TRUE); +} |