1 /******************************************************************************
3 * Module Name: asllisting - Listing file generation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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 (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlOffsetWalk,
167 NULL, (void *) ACPI_TO_POINTER (FileId));
168 LsDoOffsetTableFooter (FileId);
172 /* Process all parse nodes */
174 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
175 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 /* Write the hex bytes to the listing file(s) (if requested) */
217 for (i = 0; i < Op->Asl.FinalAmlLength; i++)
219 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
221 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
224 LsWriteListingHexBytes (&FileByte, 1, FileId);
231 /*******************************************************************************
233 * FUNCTION: LsDumpParseTree, LsTreeWriteWalk
239 * DESCRIPTION: Dump entire parse tree, for compiler debug only
241 ******************************************************************************/
253 DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
254 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
255 LsTreeWriteWalk, NULL, NULL);
261 ACPI_PARSE_OBJECT *Op,
268 DbgPrint (ASL_TREE_OUTPUT,
269 "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
271 UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
273 DbgPrint (ASL_TREE_OUTPUT, " (%.4X) Flags %8.8X",
274 Op->Asl.ParseOpcode, Op->Asl.CompileFlags);
275 TrPrintNodeCompileFlags (Op->Asl.CompileFlags);
276 DbgPrint (ASL_TREE_OUTPUT, "\n");
281 /*******************************************************************************
283 * FUNCTION: LsWriteNodeToListing
285 * PARAMETERS: Op - Parse node to write to the listing file.
286 * FileId - ID of current listing file
290 * DESCRIPTION: Write "a node" to the listing file. This means to
291 * 1) Write out all of the source text associated with the node
292 * 2) Write out all of the AML bytes associated with the node
293 * 3) Write any compiler exceptions associated with the node
295 ******************************************************************************/
298 LsWriteNodeToListing (
299 ACPI_PARSE_OBJECT *Op,
302 const ACPI_OPCODE_INFO *OpInfo;
309 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
310 OpClass = OpInfo->Class;
312 /* TBD: clean this up with a single flag that says:
313 * I start a named output block
315 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
317 switch (Op->Asl.ParseOpcode)
319 case PARSEOP_DEFINITIONBLOCK:
320 case PARSEOP_METHODCALL:
321 case PARSEOP_INCLUDE:
322 case PARSEOP_INCLUDE_END:
323 case PARSEOP_DEFAULT_ARG:
331 case AML_CLASS_NAMED_OBJECT:
333 switch (Op->Asl.AmlOpcode)
342 if (Op->Asl.ExternalName)
344 LsFlushListingBuffer (FileId);
345 FlPrintFile (FileId, " };\n");
353 /* Don't care about other objects */
361 /* These cases do not have a corresponding AML opcode */
363 switch (Op->Asl.ParseOpcode)
365 case PARSEOP_DEFINITIONBLOCK:
367 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
369 /* Use the table Signature and TableId to build a unique name */
371 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
375 Gbl_TableSignature, Gbl_TableId);
377 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
380 " unsigned char %s_%s_Header [] =\n {\n",
381 Gbl_TableSignature, Gbl_TableId);
383 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
386 "extrn %s_%s_Header : byte\n",
387 Gbl_TableSignature, Gbl_TableId);
389 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
392 "extern unsigned char %s_%s_Header [];\n",
393 Gbl_TableSignature, Gbl_TableId);
398 case PARSEOP_METHODCALL:
400 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
405 case PARSEOP_INCLUDE:
407 /* Flush everything up to and including the include source line */
409 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
412 /* Create a new listing node and push it */
414 LsPushNode (Op->Asl.Child->Asl.Value.String);
418 case PARSEOP_INCLUDE_END:
420 /* Flush out the rest of the include file */
422 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
425 /* Pop off this listing node and go back to the parent file */
431 case PARSEOP_DEFAULT_ARG:
433 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
435 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
443 /* All other opcodes have an AML opcode */
449 * Otherwise, we look at the AML opcode because we can
450 * switch on the opcode type, getting an entire class
455 case AML_CLASS_ARGUMENT: /* argument type only */
456 case AML_CLASS_INTERNAL:
460 case AML_CLASS_NAMED_OBJECT:
462 switch (Op->Asl.AmlOpcode)
465 case AML_INDEX_FIELD_OP:
466 case AML_BANK_FIELD_OP:
468 * For fields, we want to dump all the AML after the
471 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
477 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
479 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
485 * For fields, we want to dump all the AML after the
488 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
495 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
500 switch (Op->Asl.AmlOpcode)
505 /* These opcodes do not declare a new object, ignore them */
511 /* All other named object opcodes come here */
515 case ASL_FILE_ASM_SOURCE_OUTPUT:
516 case ASL_FILE_C_SOURCE_OUTPUT:
517 case ASL_FILE_ASM_INCLUDE_OUTPUT:
518 case ASL_FILE_C_INCLUDE_OUTPUT:
520 * For named objects, we will create a valid symbol so that the
521 * AML code can be referenced from C or ASM
523 if (Op->Asl.ExternalName)
525 /* Get the full pathname associated with this node */
527 Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
528 Length = strlen (Pathname);
531 /* Convert all dots in the path to underscores */
533 for (i = 0; i < Length; i++)
535 if (Pathname[i] == '.')
541 /* Create the appropriate symbol in the output file */
543 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
547 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
549 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
552 " unsigned char %s_%s_%s [] =\n {\n",
553 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
555 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
558 "extrn %s_%s_%s : byte\n",
559 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
561 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
564 "extern unsigned char %s_%s_%s [];\n",
565 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
568 ACPI_FREE (Pathname);
574 /* Nothing to do for listing file */
581 case AML_CLASS_EXECUTE:
582 case AML_CLASS_CREATE:
585 if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
586 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
591 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
595 case AML_CLASS_UNKNOWN:
602 /*******************************************************************************
604 * FUNCTION: LsFinishSourceListing
606 * PARAMETERS: FileId - ID of current listing file.
610 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
611 * listing buffer, and flush out any remaining lines in the
614 ******************************************************************************/
617 LsFinishSourceListing (
621 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
622 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
627 LsFlushListingBuffer (FileId);
628 Gbl_CurrentAmlOffset = 0;
630 /* Flush any remaining text in the source file */
632 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
634 FlPrintFile (FileId, " /*\n");
637 while (LsWriteOneSourceLine (FileId))
640 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
642 FlPrintFile (FileId, "\n */\n };\n");
645 FlPrintFile (FileId, "\n");
647 if (FileId == ASL_FILE_LISTING_OUTPUT)
649 /* Print a summary of the compile exceptions */
651 FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
652 AePrintErrorLog (FileId);
653 FlPrintFile (FileId, "\n");
654 UtDisplaySummary (FileId);
655 FlPrintFile (FileId, "\n");