diff options
Diffstat (limited to 'source/compiler')
-rw-r--r-- | source/compiler/aslcompiler.h | 9 | ||||
-rw-r--r-- | source/compiler/aslglobal.h | 3 | ||||
-rw-r--r-- | source/compiler/aslhex.c | 23 | ||||
-rw-r--r-- | source/compiler/aslload.c | 72 | ||||
-rw-r--r-- | source/compiler/aslmessages.c | 8 | ||||
-rw-r--r-- | source/compiler/aslmessages.h | 2 | ||||
-rw-r--r-- | source/compiler/asloperands.c | 15 | ||||
-rw-r--r-- | source/compiler/asltypes.h | 3 | ||||
-rw-r--r-- | source/compiler/aslutils.c | 91 | ||||
-rw-r--r-- | source/compiler/aslxref.c | 220 |
10 files changed, 235 insertions, 211 deletions
diff --git a/source/compiler/aslcompiler.h b/source/compiler/aslcompiler.h index ca5fa90e0ecb..bd02879d584a 100644 --- a/source/compiler/aslcompiler.h +++ b/source/compiler/aslcompiler.h @@ -1187,6 +1187,15 @@ UtDumpBasicOp ( ACPI_PARSE_OBJECT *Op, UINT32 Level); +void * +UtGetParentMethod ( + ACPI_NAMESPACE_NODE *Node); + +BOOLEAN +UtNodeIsDescendantOf ( + ACPI_NAMESPACE_NODE *Node1, + ACPI_NAMESPACE_NODE *Node2); + void UtDisplaySupportedTables ( void); diff --git a/source/compiler/aslglobal.h b/source/compiler/aslglobal.h index af65a4538812..93c51fae5660 100644 --- a/source/compiler/aslglobal.h +++ b/source/compiler/aslglobal.h @@ -220,7 +220,8 @@ const char *Gbl_OpFlagNames[ACPI_NUM_OP_FLAGS] = "OP_COMPILER_EMITTED", "OP_IS_DUPLICATE", "OP_IS_RESOURCE_DATA", - "OP_IS_NULL_RETURN" + "OP_IS_NULL_RETURN", + "OP_NOT_FOUND_DURING_LOAD" }; #else diff --git a/source/compiler/aslhex.c b/source/compiler/aslhex.c index fe2d58ada468..c1e3c76193be 100644 --- a/source/compiler/aslhex.c +++ b/source/compiler/aslhex.c @@ -150,6 +150,7 @@ *****************************************************************************/ #include "aslcompiler.h" +#include "acapps.h" #define _COMPONENT ACPI_COMPILER ACPI_MODULE_NAME ("ashex") @@ -265,6 +266,9 @@ HxReadAmlOutputFile ( * output file, but formatted into hex/ascii bytes suitable for * inclusion into a C source file. * + * Note: the base name of the hex output file is prepended to + * all symbols as they are output to the file. + * ******************************************************************************/ static void @@ -276,17 +280,29 @@ HxDoHexOutputC ( UINT32 Offset = 0; UINT32 AmlFileSize; UINT32 i; + char *FileBasename; + + /* Obtain the file basename (filename with no extension) */ + + FileBasename = FlGetFileBasename (Gbl_Files [ASL_FILE_HEX_OUTPUT].Filename); /* Get AML size, seek back to start */ AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT); FlSeekFile (ASL_FILE_AML_OUTPUT, 0); + /* Finish the file header and emit the non-data symbols */ + 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"); + + FlPrintFile (ASL_FILE_HEX_OUTPUT, "#ifndef __%s_HEX__\n", FileBasename); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "#define __%s_HEX__\n\n", FileBasename); + + AcpiUtStrlwr (FileBasename); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char %s_aml_code[] =\n{\n", FileBasename); while (Offset < AmlFileSize) { @@ -303,7 +319,7 @@ HxDoHexOutputC ( for (i = 0; i < LineLength; i++) { /* - * Print each hex byte. + * Output each hex byte in the form: "0xnn," * Add a comma until the very last byte of the AML file * (Some C compilers complain about a trailing comma) */ @@ -337,7 +353,8 @@ HxDoHexOutputC ( Offset += LineLength; } - FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n"); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n\n"); + FlPrintFile (ASL_FILE_HEX_OUTPUT, "#endif\n"); } diff --git a/source/compiler/aslload.c b/source/compiler/aslload.c index f32a7461348c..4082b388dcdd 100644 --- a/source/compiler/aslload.c +++ b/source/compiler/aslload.c @@ -153,9 +153,10 @@ #include "amlcode.h" #include "acdispat.h" #include "acnamesp.h" - +#include "acparser.h" #include "aslcompiler.y.h" + #define _COMPONENT ACPI_COMPILER ACPI_MODULE_NAME ("aslload") @@ -470,9 +471,13 @@ LdNamespace1Begin ( UINT32 i; BOOLEAN ForceNewScope = FALSE; ACPI_OWNER_ID OwnerId = 0; + const ACPI_OPCODE_INFO *OpInfo; + ACPI_PARSE_OBJECT *ParentOp; ACPI_FUNCTION_NAME (LdNamespace1Begin); + + ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op %p [%s]\n", Op, Op->Asl.ParseOpName)); @@ -548,6 +553,69 @@ LdNamespace1Begin ( return (AE_OK); } + /* Check for a possible illegal forward reference */ + + if ((Op->Asl.ParseOpcode == PARSEOP_NAMESEG) || + (Op->Asl.ParseOpcode == PARSEOP_NAMESTRING)) + { + /* + * Op->Asl.Namepath will be NULL for these opcodes. + * These opcodes are guaranteed to have a parent. + * Examine the parent opcode. + */ + Status = AE_OK; + ParentOp = Op->Asl.Parent; + OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Asl.AmlOpcode); + + /* + * Exclude all operators that actually declare a new name: + * Name (ABCD, 1) -> Ignore (AML_CLASS_NAMED_OBJECT) + * We only want references to named objects: + * Store (2, WXYZ) -> Attempt to resolve the name + */ + if (OpInfo->Class == AML_CLASS_NAMED_OBJECT) + { + return (AE_OK); + } + + /* + * Check if the referenced object exists at this point during + * the load: + * 1) If it exists, then this cannot be a forward reference. + * 2) If it does not exist, it could be a forward reference or + * it truly does not exist (and no external declaration). + */ + Status = AcpiNsLookup (WalkState->ScopeInfo, + Op->Asl.Value.Name, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, + ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, + WalkState, &Node); + if (Status == AE_NOT_FOUND) + { + /* + * This is either a foward reference or the object truly + * does not exist. The two cases can only be differentiated + * during the cross-reference stage later. Mark the Op/Name + * as not-found for now to indicate the need for further + * processing. + * + * Special case: Allow forward references from elements of + * Package objects. This provides compatibility with other + * ACPI implementations. To correctly implement this, the + * ACPICA table load defers package resolution until the entire + * namespace has been loaded. + */ + if ((ParentOp->Asl.ParseOpcode != PARSEOP_PACKAGE) && + (ParentOp->Asl.ParseOpcode != PARSEOP_VAR_PACKAGE)) + { + Op->Asl.CompileFlags |= OP_NOT_FOUND_DURING_LOAD; + } + + return (AE_OK); + } + + return (Status); + } + Path = Op->Asl.Namepath; if (!Path) { @@ -584,7 +652,6 @@ LdNamespace1Begin ( } break; - case PARSEOP_EXTERNAL: /* * "External" simply enters a name and type into the namespace. @@ -766,7 +833,6 @@ LdNamespace1Begin ( Status = AE_OK; goto FinishNode; - default: ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode); diff --git a/source/compiler/aslmessages.c b/source/compiler/aslmessages.c index e816b5385750..7f5cde73a552 100644 --- a/source/compiler/aslmessages.c +++ b/source/compiler/aslmessages.c @@ -342,8 +342,8 @@ const char *AslCompilerMsgs [] = /* ASL_MSG_RANGE */ "Constant out of range", /* ASL_MSG_BUFFER_ALLOCATION */ "Could not allocate line buffer", /* ASL_MSG_MISSING_DEPENDENCY */ "Missing dependency", -/* ASL_MSG_ILLEGAL_FORWARD_REF */ "Illegal forward reference within a method", -/* ASL_MSG_ILLEGAL_METHOD_REF */ "Illegal reference across two methods", +/* ASL_MSG_ILLEGAL_FORWARD_REF */ "Illegal forward reference", +/* ASL_MSG_ILLEGAL_METHOD_REF */ "Object is declared in a different method", /* ASL_MSG_LOCAL_NOT_USED */ "Method Local is set but never used", /* ASL_MSG_ARG_AS_LOCAL_NOT_USED */ "Method Argument (as a local) is set but never used", /* ASL_MSG_ARG_NOT_USED */ "Method Argument is never used", @@ -354,7 +354,9 @@ const char *AslCompilerMsgs [] = /* ASL_MSG_FOUND_HERE */ "Original name creation/declaration below: ", /* ASL_MSG_ILLEGAL_RECURSION */ "Illegal recursive call to method that creates named objects", /* ASL_MSG_EXTERN_COLLISION */ "A name cannot be defined and declared external in the same table", -/* ASL_MSG_FOUND_HERE_EXTERN*/ "Remove one of the declarations indicated above or below:" +/* ASL_MSG_FOUND_HERE_EXTERN */ "Remove one of the declarations indicated above or below:", +/* ASL_MSG_OEM_TABLE_ID */ "Invalid OEM Table ID", +/* ASL_MSG_OEM_ID */ "Invalid OEM ID" }; /* Table compiler */ diff --git a/source/compiler/aslmessages.h b/source/compiler/aslmessages.h index 3105f0be8daa..18e8144585b9 100644 --- a/source/compiler/aslmessages.h +++ b/source/compiler/aslmessages.h @@ -357,6 +357,8 @@ typedef enum ASL_MSG_ILLEGAL_RECURSION, ASL_MSG_EXTERN_COLLISION, ASL_MSG_EXTERN_FOUND_HERE, + ASL_MSG_OEM_TABLE_ID, + ASL_MSG_OEM_ID, /* These messages are used by the Data Table compiler only */ diff --git a/source/compiler/asloperands.c b/source/compiler/asloperands.c index fc0eb0b87130..1d1a1a94bfcb 100644 --- a/source/compiler/asloperands.c +++ b/source/compiler/asloperands.c @@ -1061,7 +1061,7 @@ OpnDoDefinitionBlock ( if (strlen (Gbl_TableSignature) != ACPI_NAME_SIZE) { AslError (ASL_ERROR, ASL_MSG_TABLE_SIGNATURE, Child, - "Length is not exactly 4"); + "Length must be exactly 4 characters"); } for (i = 0; i < ACPI_NAME_SIZE; i++) @@ -1078,6 +1078,7 @@ OpnDoDefinitionBlock ( Child = Child->Asl.Next; Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + /* * We used the revision to set the integer width earlier */ @@ -1086,6 +1087,12 @@ OpnDoDefinitionBlock ( Child = Child->Asl.Next; Child->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG; + if (Child->Asl.Value.String && + strlen (Child->Asl.Value.String) > ACPI_OEM_ID_SIZE) + { + AslError (ASL_ERROR, ASL_MSG_OEM_ID, Child, + "Length cannot exceed 6 characters"); + } /* OEM TableID */ @@ -1094,6 +1101,12 @@ OpnDoDefinitionBlock ( if (Child->Asl.Value.String) { Length = strlen (Child->Asl.Value.String); + if (Length > ACPI_OEM_TABLE_ID_SIZE) + { + AslError (ASL_ERROR, ASL_MSG_OEM_TABLE_ID, Child, + "Length cannot exceed 8 characters"); + } + Gbl_TableId = UtLocalCacheCalloc (Length + 1); strcpy (Gbl_TableId, Child->Asl.Value.String); diff --git a/source/compiler/asltypes.h b/source/compiler/asltypes.h index 645d00c1188d..f87358d0f751 100644 --- a/source/compiler/asltypes.h +++ b/source/compiler/asltypes.h @@ -183,8 +183,9 @@ #define OP_IS_DUPLICATE 0x00040000 #define OP_IS_RESOURCE_DATA 0x00080000 #define OP_IS_NULL_RETURN 0x00100000 +#define OP_NOT_FOUND_DURING_LOAD 0x00200000 -#define ACPI_NUM_OP_FLAGS 0x21 +#define ACPI_NUM_OP_FLAGS 0x22 /* Keeps information about individual control methods */ diff --git a/source/compiler/aslutils.c b/source/compiler/aslutils.c index 719ee874e693..16ef1f478fe7 100644 --- a/source/compiler/aslutils.c +++ b/source/compiler/aslutils.c @@ -238,6 +238,97 @@ UtQueryForOverwrite ( /******************************************************************************* * + * FUNCTION: UtNodeIsDescendantOf + * + * PARAMETERS: Node1 - Child node + * Node2 - Possible parent node + * + * RETURN: Boolean + * + * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise, + * return FALSE. Note, we assume a NULL Node2 element to be the + * topmost (root) scope. All nodes are descendants of the root. + * Note: Nodes at the same level (siblings) are not considered + * descendants. + * + ******************************************************************************/ + +BOOLEAN +UtNodeIsDescendantOf ( + ACPI_NAMESPACE_NODE *Node1, + ACPI_NAMESPACE_NODE *Node2) +{ + + if (Node1 == Node2) + { + return (FALSE); + } + + if (!Node2) + { + return (TRUE); /* All nodes descend from the root */ + } + + /* Walk upward until the root is reached or parent is found */ + + while (Node1) + { + if (Node1 == Node2) + { + return (TRUE); + } + + Node1 = Node1->Parent; + } + + return (FALSE); +} + + +/******************************************************************************* + * + * FUNCTION: UtGetParentMethod + * + * PARAMETERS: Node - Namespace node for any object + * + * RETURN: Namespace node for the parent method + * NULL - object is not within a method + * + * DESCRIPTION: Find the parent (owning) method node for a namespace object + * + ******************************************************************************/ + +void * +UtGetParentMethod ( + ACPI_NAMESPACE_NODE *Node) +{ + ACPI_NAMESPACE_NODE *ParentNode; + + + if (!Node) + { + return (NULL); + } + + /* Walk upward until a method is found, or the root is reached */ + + ParentNode = Node->Parent; + while (ParentNode) + { + if (ParentNode->Type == ACPI_TYPE_METHOD) + { + return (ParentNode); + } + + ParentNode = ParentNode->Parent; + } + + return (NULL); /* Object is not within a control method */ +} + + +/******************************************************************************* + * * FUNCTION: UtDisplaySupportedTables * * PARAMETERS: None diff --git a/source/compiler/aslxref.c b/source/compiler/aslxref.c index 94cf15bba014..c34ab49c8260 100644 --- a/source/compiler/aslxref.c +++ b/source/compiler/aslxref.c @@ -197,22 +197,6 @@ XfCheckFieldRange ( UINT32 FieldBitLength, UINT32 AccessBitWidth); -#ifdef __UNDER_DEVELOPMENT -static ACPI_PARSE_OBJECT * -XfGetParentMethod ( - ACPI_PARSE_OBJECT *Op); - -static void -XfCheckIllegalReference ( - ACPI_PARSE_OBJECT *Op, - ACPI_NAMESPACE_NODE *Node); - -static BOOLEAN -XfIsObjectParental ( - ACPI_PARSE_OBJECT *MethodOp1, - ACPI_PARSE_OBJECT *MethodOp2); -#endif - /******************************************************************************* * @@ -702,7 +686,7 @@ XfNamespaceLocateBegin ( Gbl_NsLookupCount++; Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType, - ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node)); + ACPI_IMODE_EXECUTE, Flags, WalkState, &Node); if (ACPI_FAILURE (Status)) { if (Status == AE_NOT_FOUND) @@ -760,6 +744,26 @@ XfNamespaceLocateBegin ( return_ACPI_STATUS (Status); } + /* Object was found above, check for an illegal forward reference */ + + if (Op->Asl.CompileFlags & OP_NOT_FOUND_DURING_LOAD) + { + /* + * During the load phase, this Op was flagged as a possible + * illegal forward reference + * + * Note: Allow "forward references" from within a method to an + * object that is not within any method (module-level code) + */ + if (!WalkState->ScopeInfo || (UtGetParentMethod (Node) && + !UtNodeIsDescendantOf (WalkState->ScopeInfo->Scope.Node, + UtGetParentMethod (Node)))) + { + AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op, + Op->Asl.ExternalName); + } + } + /* Check for a reference vs. name declaration */ if (!(OpInfo->Flags & AML_NAMED) && @@ -768,13 +772,6 @@ XfNamespaceLocateBegin ( /* This node has been referenced, mark it for reference check */ Node->Flags |= ANOBJ_IS_REFERENCED; - -#ifdef __UNDER_DEVELOPMENT - - /* Check for an illegal reference */ - - XfCheckIllegalReference (Op, Node); -#endif } /* Attempt to optimize the NamePath */ @@ -1205,178 +1202,3 @@ XfNamespaceLocateEnd ( return_ACPI_STATUS (AE_OK); } - - -#ifdef __UNDER_DEVELOPMENT -/******************************************************************************* - * - * FUNCTION: XfIsObjectParental - * - * PARAMETERS: ChildOp - Op to be checked - * PossibleParentOp - Determine if this op is in the family - * - * RETURN: TRUE if ChildOp is a descendent of PossibleParentOp - * - * DESCRIPTION: Determine if an Op is a descendent of another Op. Used to - * detect if a method is declared within another method. - * - ******************************************************************************/ - -static BOOLEAN -XfIsObjectParental ( - ACPI_PARSE_OBJECT *ChildOp, - ACPI_PARSE_OBJECT *PossibleParentOp) -{ - ACPI_PARSE_OBJECT *ParentOp; - - - /* Search upwards through the tree for possible parent */ - - ParentOp = ChildOp; - while (ParentOp) - { - if (ParentOp == PossibleParentOp) - { - return (TRUE); - } - - ParentOp = ParentOp->Asl.Parent; - } - - return (FALSE); -} - - -/******************************************************************************* - * - * FUNCTION: XfGetParentMethod - * - * PARAMETERS: Op - Op to be checked - * - * RETURN: Op for parent method. NULL if object is not within a method. - * - * DESCRIPTION: Determine if an object is within a control method. Used to - * implement special rules for named references from within a - * control method. - * - * NOTE: It would be better to have the parser set a flag in the Op if possible. - * - ******************************************************************************/ - -static ACPI_PARSE_OBJECT * -XfGetParentMethod ( - ACPI_PARSE_OBJECT *Op) -{ - ACPI_PARSE_OBJECT *ParentOp; - - - if (!Op) - { - return (NULL); - } - - if (Op->Asl.ParseOpcode == PARSEOP_METHOD) - { - return (NULL); - } - - /* Walk upwards through the parse tree, up to the root if necessary */ - - ParentOp = Op; - while (ParentOp) - { - if (ParentOp->Asl.ParseOpcode == PARSEOP_METHOD) - { - return (ParentOp); - } - - ParentOp = ParentOp->Asl.Parent; - } - - /* Object is not within a method */ - - return (NULL); -} - - -/******************************************************************************* - * - * FUNCTION: XfCheckIllegalReference - * - * PARAMETERS: Op - Op referring to the target - * TargetNode - Target of the reference - * - * RETURN: None. Emits error message for an illegal reference - * - * DESCRIPTION: Determine if a named reference is legal. A "named" reference - * is something like: Store(ABCD, ...), where ABCD is an AML - * Nameseg or Namepath. - * - * NOTE: Caller must ensure that the name Op is in fact a reference, and not - * an actual name declaration (creation of a named object). - * - ******************************************************************************/ - -static void -XfCheckIllegalReference ( - ACPI_PARSE_OBJECT *Op, - ACPI_NAMESPACE_NODE *TargetNode) -{ - ACPI_PARSE_OBJECT *MethodOp1; - ACPI_PARSE_OBJECT *MethodOp2; - ACPI_PARSE_OBJECT *TargetOp; - - - /* - * Check for an illegal reference to a named object: - * - * 1) References from one control method to another, non-parent - * method are not allowed, they will fail at runtime. - * - * 2) Forward references within a control method are not allowed. - * AML interpreters use a one-pass parse of control methods - * so these forward references will fail at runtime. - */ - TargetOp = TargetNode->Op; - - MethodOp1 = XfGetParentMethod (Op); - MethodOp2 = XfGetParentMethod (TargetOp); - - /* Are both objects within control method(s)? */ - - if (!MethodOp1 || !MethodOp2) - { - return; - } - - /* Objects not in the same method? */ - - if (MethodOp1 != MethodOp2) - { - /* - * 1) Cross-method named reference - * - * This is OK if and only if the target reference is within in a - * method that is a parent of current method - */ - if (!XfIsObjectParental (MethodOp1, MethodOp2)) - { - AslError (ASL_ERROR, ASL_MSG_ILLEGAL_METHOD_REF, Op, - Op->Asl.ExternalName); - } - } - - /* - * 2) Both reference and target are in the same method. Check if this is - * an (illegal) forward reference by examining the exact source code - * location of each (the referenced object and the object declaration). - * This is a bit nasty, yet effective. - */ - else if (Op->Asl.LogicalByteOffset < TargetOp->Asl.LogicalByteOffset) - { - AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op, - Op->Asl.ExternalName); - } - -} -#endif |