1 /******************************************************************************
3 * Module Name: asllisting - Listing file generation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include "aslcompiler.h"
45 #include "aslcompiler.y.h"
51 #define _COMPONENT ACPI_COMPILER
52 ACPI_MODULE_NAME ("asllisting")
55 /* Local prototypes */
63 ACPI_PARSE_OBJECT *Op,
69 ACPI_PARSE_OBJECT *Op,
74 LsWriteNodeToListing (
75 ACPI_PARSE_OBJECT *Op,
79 LsFinishSourceListing (
83 /*******************************************************************************
85 * FUNCTION: LsDoListings
87 * PARAMETERS: None. Examines the various output file global flags.
91 * DESCRIPTION: Generate all requested listing files.
93 ******************************************************************************/
100 if (Gbl_C_OutputFlag)
102 LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
107 LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
110 if (Gbl_AsmOutputFlag)
112 LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
115 if (Gbl_C_IncludeOutputFlag)
117 LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
120 if (Gbl_AsmIncludeOutputFlag)
122 LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
125 if (Gbl_C_OffsetTableFlag)
127 LsGenerateListing (ASL_FILE_C_OFFSET_OUTPUT);
132 /*******************************************************************************
134 * FUNCTION: LsGenerateListing
136 * PARAMETERS: FileId - ID of listing file
140 * DESCRIPTION: Generate a listing file. This can be one of the several types
141 * of "listings" supported.
143 ******************************************************************************/
150 /* Start at the beginning of both the source and AML files */
152 FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
153 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
155 Gbl_CurrentHexColumn = 0;
156 LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
158 if (FileId == ASL_FILE_C_OFFSET_OUTPUT)
160 /* Offset table file has a special header and footer */
162 LsDoOffsetTableHeader (FileId);
164 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlOffsetWalk,
165 NULL, (void *) ACPI_TO_POINTER (FileId));
166 LsDoOffsetTableFooter (FileId);
170 /* Process all parse nodes */
172 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
173 NULL, (void *) ACPI_TO_POINTER (FileId));
175 /* Final processing */
177 LsFinishSourceListing (FileId);
181 /*******************************************************************************
183 * FUNCTION: LsAmlListingWalk
185 * PARAMETERS: ASL_WALK_CALLBACK
189 * DESCRIPTION: Process one node during a listing file generation.
191 ******************************************************************************/
195 ACPI_PARSE_OBJECT *Op,
201 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
204 LsWriteNodeToListing (Op, FileId);
206 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
208 /* Buffer is a resource template, don't dump the data all at once */
213 /* Write the hex bytes to the listing file(s) (if requested) */
215 for (i = 0; i < Op->Asl.FinalAmlLength; i++)
217 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
219 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
222 LsWriteListingHexBytes (&FileByte, 1, FileId);
229 /*******************************************************************************
231 * FUNCTION: LsDumpParseTree, LsTreeWriteWalk
237 * DESCRIPTION: Dump entire parse tree, for compiler debug only
239 ******************************************************************************/
251 DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
252 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
253 LsTreeWriteWalk, NULL, NULL);
259 ACPI_PARSE_OBJECT *Op,
266 DbgPrint (ASL_TREE_OUTPUT,
267 "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
268 UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
270 DbgPrint (ASL_TREE_OUTPUT, "\n");
275 /*******************************************************************************
277 * FUNCTION: LsWriteNodeToListing
279 * PARAMETERS: Op - Parse node to write to the listing file.
280 * FileId - ID of current listing file
284 * DESCRIPTION: Write "a node" to the listing file. This means to
285 * 1) Write out all of the source text associated with the node
286 * 2) Write out all of the AML bytes associated with the node
287 * 3) Write any compiler exceptions associated with the node
289 ******************************************************************************/
292 LsWriteNodeToListing (
293 ACPI_PARSE_OBJECT *Op,
296 const ACPI_OPCODE_INFO *OpInfo;
303 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
304 OpClass = OpInfo->Class;
306 /* TBD: clean this up with a single flag that says:
307 * I start a named output block
309 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
311 switch (Op->Asl.ParseOpcode)
313 case PARSEOP_DEFINITIONBLOCK:
314 case PARSEOP_METHODCALL:
315 case PARSEOP_INCLUDE:
316 case PARSEOP_INCLUDE_END:
317 case PARSEOP_DEFAULT_ARG:
324 case AML_CLASS_NAMED_OBJECT:
325 switch (Op->Asl.AmlOpcode)
332 if (Op->Asl.ExternalName)
334 LsFlushListingBuffer (FileId);
335 FlPrintFile (FileId, " };\n");
342 /* Don't care about other objects */
349 /* These cases do not have a corresponding AML opcode */
351 switch (Op->Asl.ParseOpcode)
353 case PARSEOP_DEFINITIONBLOCK:
355 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
357 /* Use the table Signature and TableId to build a unique name */
359 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
363 Gbl_TableSignature, Gbl_TableId);
365 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
368 " unsigned char %s_%s_Header [] =\n {\n",
369 Gbl_TableSignature, Gbl_TableId);
371 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
374 "extrn %s_%s_Header : byte\n",
375 Gbl_TableSignature, Gbl_TableId);
377 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
380 "extern unsigned char %s_%s_Header [];\n",
381 Gbl_TableSignature, Gbl_TableId);
386 case PARSEOP_METHODCALL:
388 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
393 case PARSEOP_INCLUDE:
395 /* Flush everything up to and including the include source line */
397 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
400 /* Create a new listing node and push it */
402 LsPushNode (Op->Asl.Child->Asl.Value.String);
406 case PARSEOP_INCLUDE_END:
408 /* Flush out the rest of the include file */
410 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
413 /* Pop off this listing node and go back to the parent file */
419 case PARSEOP_DEFAULT_ARG:
421 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
423 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
430 /* All other opcodes have an AML opcode */
435 * Otherwise, we look at the AML opcode because we can
436 * switch on the opcode type, getting an entire class
441 case AML_CLASS_ARGUMENT: /* argument type only */
442 case AML_CLASS_INTERNAL:
447 case AML_CLASS_NAMED_OBJECT:
449 switch (Op->Asl.AmlOpcode)
452 case AML_INDEX_FIELD_OP:
453 case AML_BANK_FIELD_OP:
456 * For fields, we want to dump all the AML after the
459 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
465 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
467 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
473 * For fields, we want to dump all the AML after the
476 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
482 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
487 switch (Op->Asl.AmlOpcode)
492 /* These opcodes do not declare a new object, ignore them */
498 /* All other named object opcodes come here */
502 case ASL_FILE_ASM_SOURCE_OUTPUT:
503 case ASL_FILE_C_SOURCE_OUTPUT:
504 case ASL_FILE_ASM_INCLUDE_OUTPUT:
505 case ASL_FILE_C_INCLUDE_OUTPUT:
508 * For named objects, we will create a valid symbol so that the
509 * AML code can be referenced from C or ASM
511 if (Op->Asl.ExternalName)
513 /* Get the full pathname associated with this node */
515 Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
516 Length = strlen (Pathname);
519 /* Convert all dots in the path to underscores */
521 for (i = 0; i < Length; i++)
523 if (Pathname[i] == '.')
529 /* Create the appropriate symbol in the output file */
531 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
535 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
537 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
540 " unsigned char %s_%s_%s [] =\n {\n",
541 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
543 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
546 "extrn %s_%s_%s : byte\n",
547 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
549 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
552 "extern unsigned char %s_%s_%s [];\n",
553 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
556 ACPI_FREE (Pathname);
561 /* Nothing to do for listing file */
567 case AML_CLASS_EXECUTE:
568 case AML_CLASS_CREATE:
571 if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
572 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
577 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
581 case AML_CLASS_UNKNOWN:
587 /*******************************************************************************
589 * FUNCTION: LsFinishSourceListing
591 * PARAMETERS: FileId - ID of current listing file.
595 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
596 * listing buffer, and flush out any remaining lines in the
599 ******************************************************************************/
602 LsFinishSourceListing (
606 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
607 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
612 LsFlushListingBuffer (FileId);
613 Gbl_CurrentAmlOffset = 0;
615 /* Flush any remaining text in the source file */
617 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
619 FlPrintFile (FileId, " /*\n");
622 while (LsWriteOneSourceLine (FileId))
625 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
627 FlPrintFile (FileId, "\n */\n };\n");
630 FlPrintFile (FileId, "\n");
632 if (FileId == ASL_FILE_LISTING_OUTPUT)
634 /* Print a summary of the compile exceptions */
636 FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
637 AePrintErrorLog (FileId);
638 FlPrintFile (FileId, "\n");
639 UtDisplaySummary (FileId);
640 FlPrintFile (FileId, "\n");