diff --git a/source/compiler/aslanalyze.c b/source/compiler/aslanalyze.c index 4d430de3d..d67fd85f6 100644 --- a/source/compiler/aslanalyze.c +++ b/source/compiler/aslanalyze.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Module Name: aslanalyze.c - check for semantic errors - * $Revision: 1.54 $ + * $Revision: 1.55 $ * *****************************************************************************/ @@ -132,7 +132,7 @@ * FUNCTION: AnMapArgTypeToBtype * * PARAMETERS: ArgType - The ARGI required type(s) for this argument, - * from the opcode info table + * from the opcode info table * * RETURN: The corresponding Bit-encoded types * @@ -191,10 +191,16 @@ AnMapArgTypeToBtype ( case ARGI_COMPUTEDATA: return (ACPI_BTYPE_COMPUTE_DATA); - case ARGI_DATAOBJECT: /* Buffer, string, package or reference to a Node - Used only by SizeOf operator*/ + case ARGI_DATAOBJECT: + + /* Buffer, string, package or reference to a Node - 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 */ + case ARGI_COMPLEXOBJ: + + /* Buffer, String, or package */ + return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE); case ARGI_MUTEX: @@ -220,7 +226,7 @@ AnMapArgTypeToBtype ( * * PARAMETERS: Etype - Encoded ACPI Type * - * RETURN: Btype + * 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) @@ -270,7 +276,10 @@ AnMapEtypeToBtype ( return (ACPI_BTYPE_INTEGER | ACPI_BTYPE_DDB_HANDLE); case ACPI_BTYPE_DEBUG_OBJECT: - return (0); /* Cannot be used as a source operand */ + + /* Cannot be used as a source operand */ + + return (0); default: return (1 << (Etype - 1)); @@ -310,7 +319,7 @@ AnMapEtypeToBtype ( * * PARAMETERS: Btype - Bitfield of ACPI types * - * RETURN: none + * RETURN: The Etype corresponding the the Btype * * DESCRIPTION: Convert a bitfield type to an encoded type * @@ -380,7 +389,6 @@ AnFormatBtype ( First = FALSE; strcat (Buffer, AcpiUtGetTypeName (Type)); } - Btype >>= 1; } @@ -412,9 +420,9 @@ AnFormatBtype ( * * FUNCTION: AnGetBtype * - * PARAMETERS: + * PARAMETERS: PsNode - Parse node whose type will be returned. * - * RETURN: None. + * RETURN: The Btype associated with the PsNode. * * DESCRIPTION: Get the (bitfield) ACPI type associated with the parse node. * Handles the case where the node is a name or method call and @@ -603,7 +611,7 @@ AnCheckForReservedMethod ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: none + * RETURN: Status * * DESCRIPTION: Descending callback for the analysis walk. Check methods for : * 1) Initialized local variables @@ -665,14 +673,15 @@ AnMethodAnalysisWalkBegin ( case METHODCALL: + if (MethodInfo && (Node->NsNode == MethodInfo->Node->NsNode)) { AslError (ASL_REMARK, ASL_MSG_RECURSION, Node, Node->ExternalName); } - break; + case LOCAL0: case LOCAL1: case LOCAL2: @@ -699,7 +708,6 @@ AnMethodAnalysisWalkBegin ( if (Node->Flags & NODE_IS_TARGET) { MethodInfo->LocalInitialized[RegisterNumber] = TRUE; - } /* @@ -740,7 +748,6 @@ AnMethodAnalysisWalkBegin ( if (Node->Flags & NODE_IS_TARGET) { MethodInfo->ArgInitialized[RegisterNumber] = TRUE; - } /* @@ -758,7 +765,6 @@ AnMethodAnalysisWalkBegin ( { AslError (ASL_REMARK, ASL_MSG_NOT_PARAMETER, Node, ArgName); } - break; @@ -804,7 +810,6 @@ AnMethodAnalysisWalkBegin ( AslError (ASL_ERROR, ASL_MSG_NO_WHILE, Node, NULL); } break; - } return AE_OK; @@ -815,7 +820,7 @@ AnMethodAnalysisWalkBegin ( * * FUNCTION: AnLastStatementIsReturn * - * PARAMETERS: Node - A method node + * PARAMETERS: Node - A method parse node * * RETURN: TRUE if last statement is an ASL RETURN. False otherwise * @@ -857,7 +862,7 @@ AnLastStatementIsReturn ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: None. + * RETURN: Status * * DESCRIPTION: Ascending callback for analysis walk. Complete method * return analysis. @@ -995,7 +1000,7 @@ AnMethodAnalysisWalkEnd ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: none + * RETURN: Status * * DESCRIPTION: Descending callback for the typing walk. * @@ -1018,7 +1023,7 @@ AnMethodTypingWalkBegin ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: None. + * RETURN: Status * * DESCRIPTION: Ascending callback for typing walk. Complete method * return analysis. Check methods for : @@ -1040,10 +1045,12 @@ AnMethodTypingWalkEnd ( switch (Node->ParseOpcode) { case METHOD: + Node->Flags |= NODE_METHOD_TYPED; break; case RETURN: + if ((Node->Child) && (Node->Child->ParseOpcode != DEFAULT_ARG)) { @@ -1080,7 +1087,7 @@ AnMethodTypingWalkEnd ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: none + * RETURN: Status * * DESCRIPTION: Descending callback for the analysis walk. Check methods for : * 1) Initialized local variables @@ -1106,7 +1113,7 @@ AnOperandTypecheckWalkBegin ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: None. + * RETURN: Status * * DESCRIPTION: Ascending callback for analysis walk. Complete method * return analysis. @@ -1143,6 +1150,9 @@ AnOperandTypecheckWalkEnd ( case AML_PACKAGE_LENGTH: case AML_UNASSIGNED_OPCODE: case AML_DEFAULT_ARG_OP: + + /* Ignore the internal (compiler-only) AML opcodes */ + return (AE_OK); } @@ -1217,7 +1227,6 @@ AnOperandTypecheckWalkEnd ( { AslError (ASL_ERROR, ASL_MSG_RESOURCE_FIELD, ArgNode, NULL); } - else { AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgNode, NULL); @@ -1330,7 +1339,6 @@ AnOperandTypecheckWalkEnd ( AslError (ASL_ERROR, ASL_MSG_INVALID_TYPE, ArgNode, MsgBuffer); } - NextArgument: ArgNode = ArgNode->Peer; INCREMENT_ARG_LIST (RuntimeArgTypes2); @@ -1338,7 +1346,6 @@ AnOperandTypecheckWalkEnd ( } } - return (AE_OK); } @@ -1349,7 +1356,7 @@ AnOperandTypecheckWalkEnd ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: none + * RETURN: Status * * DESCRIPTION: Descending callback for the analysis walk. Check methods for : * 1) Initialized local variables @@ -1375,7 +1382,7 @@ AnOtherSemanticAnalysisWalkBegin ( * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: None. + * RETURN: Status * * DESCRIPTION: Ascending callback for analysis walk. Complete method * return analysis. diff --git a/source/compiler/aslcodegen.c b/source/compiler/aslcodegen.c index d7474dfca..64218f29e 100644 --- a/source/compiler/aslcodegen.c +++ b/source/compiler/aslcodegen.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Module Name: aslcodegen - AML code generation - * $Revision: 1.37 $ + * $Revision: 1.39 $ * *****************************************************************************/ @@ -145,19 +145,13 @@ CgGenerateAmlOutput (void) DbgPrint (ASL_DEBUG_OUTPUT, "\nWriting AML\n\n"); + /* Generate the AML output file */ + FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0); Gbl_SourceLine = 0; - LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename); Gbl_NextError = Gbl_ErrorLog; TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, CgAmlWriteWalk, NULL, NULL); - - if (Gbl_ListingFlag) - { - LsFinishSourceListing (); - FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n\nTable header with final checksum:\n\n"); - } - CgCloseTable (); } @@ -168,7 +162,7 @@ CgGenerateAmlOutput (void) * * PARAMETERS: ASL_WALK_CALLBACK * - * RETURN: None + * RETURN: Status * * DESCRIPTION: Parse tree walk to generate the AML code. * @@ -181,7 +175,9 @@ CgAmlWriteWalk ( void *Context) { - + /* + * Debug output + */ DbgPrint (ASL_TREE_OUTPUT, "%5.5d [%d]", Node->LogicalLineNumber, Level); UtPrintFormattedName (Node->ParseOpcode, Level); @@ -216,8 +212,9 @@ CgAmlWriteWalk ( Node->Column, Node->LineNumber); - - LsWriteNodeToListing (Node); + /* + * Generate the AML for this node + */ CgWriteNode (Node); return (AE_OK); } @@ -238,6 +235,7 @@ CgAmlWriteWalk ( void CgLocalWriteAmlData ( + ASL_PARSE_NODE *Node, void *Buffer, UINT32 Length) { @@ -247,9 +245,12 @@ CgLocalWriteAmlData ( FlWriteFile (ASL_FILE_AML_OUTPUT, Buffer, Length); - /* Write the hex bytes to the listing file (if requested) */ + /* Update the final AML length for this node (used for listings) */ - LsWriteListingHexBytes (Buffer, Length); + if (Node) + { + Node->FinalAmlLength += Length; + } } @@ -334,10 +335,10 @@ CgWriteAmlOpcode ( { /* Write the high byte first */ - CgLocalWriteAmlData (&Aml.OpcodeBytes[1], 1); + CgLocalWriteAmlData (Node, &Aml.OpcodeBytes[1], 1); } - CgLocalWriteAmlData (&Aml.OpcodeBytes[0], 1); + CgLocalWriteAmlData (Node, &Aml.OpcodeBytes[0], 1); /* Subtreelength doesn't include length of package length bytes */ @@ -345,7 +346,6 @@ CgWriteAmlOpcode ( break; } - /* Does this opcode have an associated "PackageLength" field? */ if (Node->Flags & NODE_AML_PACKAGE) @@ -354,9 +354,8 @@ CgWriteAmlOpcode ( { /* Simplest case -- no bytes to follow, just write the count */ - CgLocalWriteAmlData(&PkgLen.LenBytes[0], 1); + CgLocalWriteAmlData (Node, &PkgLen.LenBytes[0], 1); } - else { /* @@ -366,7 +365,7 @@ CgWriteAmlOpcode ( PkgLenFirstByte = (UINT8) (((Node->AmlPkgLenBytes - 1) << 6) | (PkgLen.LenBytes[0] & 0x0F)); - CgLocalWriteAmlData (&PkgLenFirstByte, 1); + CgLocalWriteAmlData (Node, &PkgLenFirstByte, 1); /* Shift the length over by the 4 bits we just stuffed in the first byte */ @@ -376,7 +375,7 @@ CgWriteAmlOpcode ( for (i = 0; i < (UINT32) (Node->AmlPkgLenBytes - 1); i++) { - CgLocalWriteAmlData (&PkgLen.LenBytes[i], 1); + CgLocalWriteAmlData (Node, &PkgLen.LenBytes[i], 1); } } } @@ -384,23 +383,29 @@ CgWriteAmlOpcode ( switch (Aml.Opcode) { case AML_BYTE_OP: - CgLocalWriteAmlData (&Node->Value.Integer8, 1); + + CgLocalWriteAmlData (Node, &Node->Value.Integer8, 1); break; case AML_WORD_OP: - CgLocalWriteAmlData (&Node->Value.Integer16, 2); + + CgLocalWriteAmlData (Node, &Node->Value.Integer16, 2); break; case AML_DWORD_OP: - CgLocalWriteAmlData (&Node->Value.Integer32, 4); + + CgLocalWriteAmlData (Node, &Node->Value.Integer32, 4); break; case AML_QWORD_OP: - CgLocalWriteAmlData (&Node->Value.Integer64, 8); + + CgLocalWriteAmlData (Node, &Node->Value.Integer64, 8); break; case AML_STRING_OP: - CgLocalWriteAmlData (Node->Value.String, Node->AmlLength); + + CgLocalWriteAmlData (Node, Node->Value.String, Node->AmlLength); + break; } } @@ -428,7 +433,6 @@ CgWriteTableHeader ( Child = Node->Child; - /* Signature */ Child = Child->Peer; @@ -467,7 +471,7 @@ CgWriteTableHeader ( TableHeader.Length = Gbl_TableLength; TableHeader.Checksum = 0; - CgLocalWriteAmlData (&TableHeader, sizeof (ACPI_TABLE_HEADER)); + CgLocalWriteAmlData (Node, &TableHeader, sizeof (ACPI_TABLE_HEADER)); } @@ -491,11 +495,11 @@ CgCloseTable (void) UINT8 FileByte; - /* Calculate the checksum over the entire file */ - 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); @@ -506,7 +510,7 @@ CgCloseTable (void) TableHeader.Checksum = (UINT8) (0 - Sum); FlSeekFile (ASL_FILE_AML_OUTPUT, 0); - CgLocalWriteAmlData (&TableHeader, sizeof (ACPI_TABLE_HEADER)); + CgLocalWriteAmlData (NULL, &TableHeader, sizeof (ACPI_TABLE_HEADER)); } @@ -529,6 +533,8 @@ CgWriteNode ( ASL_RESOURCE_NODE *Rnode; + Node->FinalAmlLength = 0; + /* Always check for DEFAULT_ARG and other "Noop" nodes */ /* TBD: this may not be the best place for this check */ @@ -547,13 +553,13 @@ CgWriteNode ( case AML_RAW_DATA_DWORD: case AML_RAW_DATA_QWORD: - CgLocalWriteAmlData (&Node->Value.Integer, Node->AmlLength); + CgLocalWriteAmlData (Node, &Node->Value.Integer, Node->AmlLength); return; case AML_RAW_DATA_BUFFER: - CgLocalWriteAmlData (Node->Value.Pointer, Node->AmlLength); + CgLocalWriteAmlData (Node, Node->Value.Pointer, Node->AmlLength); return; @@ -562,7 +568,7 @@ CgWriteNode ( Rnode = Node->Value.Pointer; while (Rnode) { - CgLocalWriteAmlData (Rnode->Buffer, Rnode->BufferLength); + CgLocalWriteAmlData (Node, Rnode->Buffer, Rnode->BufferLength); Rnode = Rnode->Next; } return; @@ -571,19 +577,23 @@ CgWriteNode ( switch (Node->ParseOpcode) { case DEFAULT_ARG: + break; case DEFINITIONBLOCK: + CgWriteTableHeader (Node); break; case NAMESEG: case NAMESTRING: case METHODCALL: - CgLocalWriteAmlData (Node->Value.String, Node->AmlLength); + + CgLocalWriteAmlData (Node, Node->Value.String, Node->AmlLength); break; default: + CgWriteAmlOpcode (Node); break; } diff --git a/source/compiler/aslcompile.c b/source/compiler/aslcompile.c index 978cb360c..6e00868a6 100644 --- a/source/compiler/aslcompile.c +++ b/source/compiler/aslcompile.c @@ -2,7 +2,7 @@ /****************************************************************************** * * Module Name: aslcompile - top level compile module - * $Revision: 1.42 $ + * $Revision: 1.45 $ * *****************************************************************************/ @@ -180,7 +180,7 @@ AcpiExDumpOperand ( * * FUNCTION: AslCompilerSignon * - * PARAMETERS: None + * PARAMETERS: FileId - ID of the output file * * RETURN: None * @@ -195,19 +195,39 @@ AslCompilerSignon ( char *Prefix = ""; + /* + * Set line prefix depending on the destination file type + */ switch (FileId) { case ASL_FILE_ASM_SOURCE_OUTPUT: + Prefix = "; "; break; case ASL_FILE_HEX_OUTPUT: + + if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) + { + Prefix = "; "; + } + else if (Gbl_HexOutputFlag == HEX_OUTPUT_C) + { + FlPrintFile (ASL_FILE_HEX_OUTPUT, "/*\n"); + Prefix = " * "; + } + break; + + case ASL_FILE_C_SOURCE_OUTPUT: + Prefix = " * "; break; - } + } + + /* Compiler signon with copyright */ FlPrintFile (FileId, - "%s\n%s%s %s [%s]\n%sACPI CA Subsystem version %X\n%s%s\n%sSupports ACPI Specification Revision 2.0\n%s\n", + "%s\n%s%s %s [%s]\n%sIncludes ACPI CA Subsystem version %X\n%s%s\n%sSupports ACPI Specification Revision 2.0\n%s\n", Prefix, Prefix, CompilerId, CompilerVersion, __DATE__, Prefix, ACPI_CA_VERSION, @@ -221,7 +241,7 @@ AslCompilerSignon ( * * FUNCTION: AslCompilerFileHeader * - * PARAMETERS: None + * PARAMETERS: FileId - ID of the output file * * RETURN: None * @@ -238,17 +258,36 @@ AslCompilerFileHeader ( char *Prefix = ""; + /* + * Set line prefix depending on the destination file type + */ switch (FileId) { case ASL_FILE_ASM_SOURCE_OUTPUT: + Prefix = "; "; break; case ASL_FILE_HEX_OUTPUT: + + if (Gbl_HexOutputFlag == HEX_OUTPUT_ASM) + { + Prefix = "; "; + } + else if (Gbl_HexOutputFlag == HEX_OUTPUT_C) + { + Prefix = " * "; + } + break; + + case ASL_FILE_C_SOURCE_OUTPUT: + Prefix = " * "; break; } + /* Compilation header with timestamp */ + time (&Aclock); NewTime = localtime (&Aclock); @@ -281,7 +320,6 @@ CmDoCompile (void) UtBeginEvent (12, "Total Compile time"); UtBeginEvent (i, "Initialize"); - /* Open the required input and output files */ Status = FlOpenInputFile (Gbl_Files[ASL_FILE_INPUT].Filename); @@ -298,7 +336,6 @@ CmDoCompile (void) return -1; } - /* ACPI CA subsystem initialization */ AcpiUtInitGlobals (); @@ -306,7 +343,6 @@ CmDoCompile (void) AcpiNsRootInitialize (); UtEndEvent (i++); - /* Build the parse tree */ UtBeginEvent (i, "Parse source code and build parse tree"); @@ -325,7 +361,6 @@ CmDoCompile (void) TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, OpcAmlOpcodeWalk, NULL); UtEndEvent (i++); - /* Calculate all AML package lengths */ UtBeginEvent (i, "Generate AML package lengths"); @@ -333,7 +368,6 @@ CmDoCompile (void) TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, LnPackageLengthWalk, NULL); UtEndEvent (i++); - if (Gbl_ParseOnlyFlag) { AePrintErrorLog (ASL_FILE_STDOUT); @@ -348,7 +382,6 @@ CmDoCompile (void) return 0; } - /* * Create an internal namespace and use it as a symbol table */ @@ -359,14 +392,12 @@ CmDoCompile (void) LdLoadNamespace (); UtEndEvent (i++); - /* Namespace lookup */ UtBeginEvent (i, "Cross reference parse tree and Namespace"); LkCrossReferenceNamespace (); UtEndEvent (i++); - /* * Semantic analysis. This can happen only after the * namespace has been loaded and cross-referenced. @@ -381,7 +412,6 @@ CmDoCompile (void) AnMethodAnalysisWalkEnd, &AnalysisWalkInfo); UtEndEvent (i++); - /* Semantic error checking part two - typing of method returns */ UtBeginEvent (i, "Determine object types returned by methods"); @@ -414,7 +444,6 @@ CmDoCompile (void) TrWalkParseTree (RootNode, ASL_WALK_VISIT_UPWARD, NULL, LnPackageLengthWalk, NULL); UtEndEvent (i++); - /* * 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 @@ -433,20 +462,18 @@ CmDoCompile (void) CgGenerateAmlOutput (); UtEndEvent (i++); - UtBeginEvent (i, "Write optional output files"); - /* Dump the AML as hex if requested */ + /* Create listings and hex files */ + LsDoListings (); LsDoHexOutput (); - LsDoAsmOutput (); /* Dump the namespace to the .nsp file if requested */ LsDisplayNamespace (); UtEndEvent (i++); - UtEndEvent (13); CmCleanupAndExit (); return 0; @@ -523,21 +550,6 @@ CmCleanupAndExit (void) Gbl_NsLookupCount); } - if (Gbl_ListingFlag) - { - /* Flush any final AML in the buffer */ - - LsFlushListingBuffer (); - - /* Print a summary of the compile exceptions */ - - FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n\nSummary of errors and warnings\n\n"); - AePrintErrorLog (ASL_FILE_LISTING_OUTPUT); - FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n\n"); - UtDisplaySummary (ASL_FILE_LISTING_OUTPUT); - FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n\n"); - } - /* Close all open files */ for (i = 2; i < ASL_MAX_FILE; i++)