1 /******************************************************************************
3 * Module Name: asllisting - Listing file generation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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 <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/amlcode.h>
47 #include <contrib/dev/acpica/include/acparser.h>
48 #include <contrib/dev/acpica/include/acnamesp.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 Gbl_CurrentAmlOffset = 0;
162 /* Offset table file has a special header and footer */
164 LsDoOffsetTableHeader (FileId);
166 TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
167 LsAmlOffsetWalk, NULL, (void *) ACPI_TO_POINTER (FileId));
168 LsDoOffsetTableFooter (FileId);
172 /* Process all parse nodes */
174 TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
175 LsAmlListingWalk, NULL, (void *) ACPI_TO_POINTER (FileId));
177 /* Final processing */
179 LsFinishSourceListing (FileId);
183 /*******************************************************************************
185 * FUNCTION: LsAmlListingWalk
187 * PARAMETERS: ASL_WALK_CALLBACK
191 * DESCRIPTION: Process one node during a listing file generation.
193 ******************************************************************************/
197 ACPI_PARSE_OBJECT *Op,
203 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
206 LsWriteNodeToListing (Op, FileId);
208 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
210 /* Buffer is a resource template, don't dump the data all at once */
215 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
216 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
221 /* Write the hex bytes to the listing file(s) (if requested) */
223 for (i = 0; i < Op->Asl.FinalAmlLength; i++)
225 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
227 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
231 LsWriteListingHexBytes (&FileByte, 1, FileId);
238 /*******************************************************************************
240 * FUNCTION: LsDumpParseTree, LsTreeWriteWalk
246 * DESCRIPTION: Dump entire parse tree, for compiler debug only
248 ******************************************************************************/
260 DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
261 DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_HEADER1);
263 TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_DOWNWARD,
264 LsTreeWriteWalk, NULL, NULL);
266 DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_HEADER1);
272 ACPI_PARSE_OBJECT *Op,
277 /* Dump ParseOp name and possible value */
279 switch (Op->Asl.ParseOpcode)
281 case PARSEOP_NAMESEG:
282 case PARSEOP_NAMESTRING:
283 case PARSEOP_METHODCALL:
284 case PARSEOP_STRING_LITERAL:
286 UtDumpStringOp (Op, Level);
289 case PARSEOP_BYTECONST:
291 UtDumpIntegerOp (Op, Level, 2);
294 case PARSEOP_WORDCONST:
295 case PARSEOP_PACKAGE_LENGTH:
297 UtDumpIntegerOp (Op, Level, 4);
300 case PARSEOP_DWORDCONST:
303 UtDumpIntegerOp (Op, Level, 8);
306 case PARSEOP_QWORDCONST:
307 case PARSEOP_INTEGER:
312 UtDumpIntegerOp (Op, Level, 16);
315 case PARSEOP_INCLUDE:
317 DbgPrint (ASL_TREE_OUTPUT,
318 "Open: %s\n", Op->Asl.Value.String);
321 case PARSEOP_INCLUDE_END:
323 DbgPrint (ASL_TREE_OUTPUT,
324 "Close: %s\n", Op->Asl.Filename);
329 UtDumpBasicOp (Op, Level);
333 /* Dump the remaining data */
335 DbgPrint (ASL_TREE_OUTPUT, ASL_PARSE_TREE_DEBUG1,
336 Op->Asl.ParseOpcode, Op->Asl.CompileFlags,
337 Op->Asl.LineNumber, Op->Asl.EndLine,
338 Op->Asl.LogicalLineNumber, Op->Asl.EndLogicalLine);
340 TrPrintNodeCompileFlags (Op->Asl.CompileFlags);
341 DbgPrint (ASL_TREE_OUTPUT, "\n");
346 /*******************************************************************************
348 * FUNCTION: LsWriteNodeToListing
350 * PARAMETERS: Op - Parse node to write to the listing file.
351 * FileId - ID of current listing file
355 * DESCRIPTION: Write "a node" to the listing file. This means to
356 * 1) Write out all of the source text associated with the node
357 * 2) Write out all of the AML bytes associated with the node
358 * 3) Write any compiler exceptions associated with the node
360 ******************************************************************************/
363 LsWriteNodeToListing (
364 ACPI_PARSE_OBJECT *Op,
367 const ACPI_OPCODE_INFO *OpInfo;
374 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
375 OpClass = OpInfo->Class;
377 /* TBD: clean this up with a single flag that says:
378 * I start a named output block
380 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
382 switch (Op->Asl.ParseOpcode)
384 case PARSEOP_DEFINITION_BLOCK:
385 case PARSEOP_METHODCALL:
386 case PARSEOP_INCLUDE:
387 case PARSEOP_INCLUDE_END:
388 case PARSEOP_DEFAULT_ARG:
396 case AML_CLASS_NAMED_OBJECT:
398 switch (Op->Asl.AmlOpcode)
407 if (Op->Asl.ExternalName)
409 LsFlushListingBuffer (FileId);
410 FlPrintFile (FileId, " };\n");
418 /* Don't care about other objects */
426 /* These cases do not have a corresponding AML opcode */
428 switch (Op->Asl.ParseOpcode)
430 case PARSEOP_DEFINITION_BLOCK:
432 /* Always start a definition block at AML offset zero */
434 Gbl_CurrentAmlOffset = 0;
435 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
437 /* Use the table Signature and TableId to build a unique name */
441 case ASL_FILE_ASM_SOURCE_OUTPUT:
445 Gbl_TableSignature, Gbl_TableId);
448 case ASL_FILE_C_SOURCE_OUTPUT:
451 " unsigned char %s_%s_Header [] =\n {\n",
452 Gbl_TableSignature, Gbl_TableId);
455 case ASL_FILE_ASM_INCLUDE_OUTPUT:
458 "extrn %s_%s_Header : byte\n",
459 Gbl_TableSignature, Gbl_TableId);
462 case ASL_FILE_C_INCLUDE_OUTPUT:
465 "extern unsigned char %s_%s_Header [];\n",
466 Gbl_TableSignature, Gbl_TableId);
476 case PARSEOP_METHODCALL:
478 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
483 case PARSEOP_INCLUDE:
485 /* Flush everything up to and including the include source line */
487 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
490 /* Create a new listing node and push it */
492 LsPushNode (Op->Asl.Value.String);
496 case PARSEOP_INCLUDE_END:
498 /* Flush out the rest of the include file */
500 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
503 /* Pop off this listing node and go back to the parent file */
509 case PARSEOP_DEFAULT_ARG:
511 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
513 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
521 /* All other opcodes have an AML opcode */
527 * Otherwise, we look at the AML opcode because we can
528 * switch on the opcode type, getting an entire class
533 case AML_CLASS_ARGUMENT: /* argument type only */
534 case AML_CLASS_INTERNAL:
538 case AML_CLASS_NAMED_OBJECT:
540 switch (Op->Asl.AmlOpcode)
543 case AML_INDEX_FIELD_OP:
544 case AML_BANK_FIELD_OP:
546 * For fields, we want to dump all the AML after the
549 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
555 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
557 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
563 * For fields, we want to dump all the AML after the
566 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
573 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
578 switch (Op->Asl.AmlOpcode)
583 /* These opcodes do not declare a new object, ignore them */
589 /* All other named object opcodes come here */
593 case ASL_FILE_ASM_SOURCE_OUTPUT:
594 case ASL_FILE_C_SOURCE_OUTPUT:
595 case ASL_FILE_ASM_INCLUDE_OUTPUT:
596 case ASL_FILE_C_INCLUDE_OUTPUT:
598 * For named objects, we will create a valid symbol so that the
599 * AML code can be referenced from C or ASM
601 if (Op->Asl.ExternalName)
603 /* Get the full pathname associated with this node */
605 Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
606 Length = strlen (Pathname);
609 /* Convert all dots in the path to underscores */
611 for (i = 0; i < Length; i++)
613 if (Pathname[i] == '.')
619 /* Create the appropriate symbol in the output file */
623 case ASL_FILE_ASM_SOURCE_OUTPUT:
627 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
630 case ASL_FILE_C_SOURCE_OUTPUT:
633 " unsigned char %s_%s_%s [] =\n {\n",
634 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
637 case ASL_FILE_ASM_INCLUDE_OUTPUT:
640 "extrn %s_%s_%s : byte\n",
641 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
644 case ASL_FILE_C_INCLUDE_OUTPUT:
647 "extern unsigned char %s_%s_%s [];\n",
648 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
656 ACPI_FREE (Pathname);
662 /* Nothing to do for listing file */
669 case AML_CLASS_EXECUTE:
670 case AML_CLASS_CREATE:
673 if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
674 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
679 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
683 case AML_CLASS_UNKNOWN:
690 /*******************************************************************************
692 * FUNCTION: LsFinishSourceListing
694 * PARAMETERS: FileId - ID of current listing file.
698 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
699 * listing buffer, and flush out any remaining lines in the
702 ******************************************************************************/
705 LsFinishSourceListing (
709 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
710 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
715 LsFlushListingBuffer (FileId);
716 Gbl_CurrentAmlOffset = 0;
718 /* Flush any remaining text in the source file */
720 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
722 FlPrintFile (FileId, " /*\n");
725 while (LsWriteOneSourceLine (FileId))
728 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
730 FlPrintFile (FileId, "\n */\n };\n");
733 FlPrintFile (FileId, "\n");
735 if (FileId == ASL_FILE_LISTING_OUTPUT)
737 /* Print a summary of the compile exceptions */
739 FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
740 AePrintErrorLog (FileId);
741 FlPrintFile (FileId, "\n");
742 UtDisplaySummary (FileId);
743 FlPrintFile (FileId, "\n");