1 /******************************************************************************
3 * Module Name: asllisting - Listing file generation
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "aslcompiler.h"
153 #include "aslcompiler.y.h"
155 #include "acparser.h"
156 #include "acnamesp.h"
159 #define _COMPONENT ACPI_COMPILER
160 ACPI_MODULE_NAME ("asllisting")
163 /* Local prototypes */
171 ACPI_PARSE_OBJECT
*Op
,
177 ACPI_PARSE_OBJECT
*Op
,
182 LsWriteNodeToListing (
183 ACPI_PARSE_OBJECT
*Op
,
187 LsFinishSourceListing (
191 /*******************************************************************************
193 * FUNCTION: LsDoListings
195 * PARAMETERS: None. Examines the various output file global flags.
199 * DESCRIPTION: Generate all requested listing files.
201 ******************************************************************************/
208 if (AslGbl_C_OutputFlag
)
210 LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT
);
213 if (AslGbl_ListingFlag
)
215 LsGenerateListing (ASL_FILE_LISTING_OUTPUT
);
218 if (AslGbl_AsmOutputFlag
)
220 LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT
);
223 if (AslGbl_C_IncludeOutputFlag
)
225 LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT
);
228 if (AslGbl_AsmIncludeOutputFlag
)
230 LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT
);
233 if (AslGbl_C_OffsetTableFlag
)
235 LsGenerateListing (ASL_FILE_C_OFFSET_OUTPUT
);
240 /*******************************************************************************
242 * FUNCTION: LsGenerateListing
244 * PARAMETERS: FileId - ID of listing file
248 * DESCRIPTION: Generate a listing file. This can be one of the several types
249 * of "listings" supported.
251 ******************************************************************************/
258 /* Start at the beginning of both the source and AML files */
260 FlSeekFile (ASL_FILE_SOURCE_OUTPUT
, 0);
261 FlSeekFile (ASL_FILE_AML_OUTPUT
, 0);
262 AslGbl_SourceLine
= 0;
263 AslGbl_CurrentHexColumn
= 0;
264 LsPushNode (AslGbl_Files
[ASL_FILE_INPUT
].Filename
);
266 if (FileId
== ASL_FILE_C_OFFSET_OUTPUT
)
268 AslGbl_CurrentAmlOffset
= 0;
270 /* Offset table file has a special header and footer */
272 LsDoOffsetTableHeader (FileId
);
274 TrWalkParseTree (AslGbl_ParseTreeRoot
, ASL_WALK_VISIT_DOWNWARD
,
275 LsAmlOffsetWalk
, NULL
, (void *) ACPI_TO_POINTER (FileId
));
276 LsDoOffsetTableFooter (FileId
);
280 /* Process all parse nodes */
282 TrWalkParseTree (AslGbl_ParseTreeRoot
, ASL_WALK_VISIT_DOWNWARD
,
283 LsAmlListingWalk
, NULL
, (void *) ACPI_TO_POINTER (FileId
));
285 /* Final processing */
287 LsFinishSourceListing (FileId
);
291 /*******************************************************************************
293 * FUNCTION: LsAmlListingWalk
295 * PARAMETERS: ASL_WALK_CALLBACK
299 * DESCRIPTION: Process one node during a listing file generation.
301 ******************************************************************************/
305 ACPI_PARSE_OBJECT
*Op
,
311 UINT32 FileId
= (UINT32
) ACPI_TO_INTEGER (Context
);
314 LsWriteNodeToListing (Op
, FileId
);
316 if (Op
->Asl
.CompileFlags
& OP_IS_RESOURCE_DATA
)
318 /* Buffer is a resource template, don't dump the data all at once */
323 if ((FileId
== ASL_FILE_ASM_INCLUDE_OUTPUT
) ||
324 (FileId
== ASL_FILE_C_INCLUDE_OUTPUT
))
329 /* Write the hex bytes to the listing file(s) (if requested) */
331 for (i
= 0; i
< Op
->Asl
.FinalAmlLength
; i
++)
333 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT
, &FileByte
, 1)))
335 FlFileError (ASL_FILE_AML_OUTPUT
, ASL_MSG_READ
);
339 LsWriteListingHexBytes (&FileByte
, 1, FileId
);
346 /*******************************************************************************
348 * FUNCTION: LsDumpParseTree, LsTreeWriteWalk
354 * DESCRIPTION: Dump entire parse tree, for compiler debug only
356 ******************************************************************************/
363 if (!AslGbl_DebugFlag
)
368 DbgPrint (ASL_TREE_OUTPUT
, "\nOriginal parse tree from parser:\n\n");
369 DbgPrint (ASL_TREE_OUTPUT
, ASL_PARSE_TREE_HEADER1
);
371 TrWalkParseTree (AslGbl_ParseTreeRoot
, ASL_WALK_VISIT_DOWNWARD
,
372 LsTreeWriteWalk
, NULL
, NULL
);
374 DbgPrint (ASL_TREE_OUTPUT
, ASL_PARSE_TREE_HEADER1
);
380 ACPI_PARSE_OBJECT
*Op
,
385 /* Dump ParseOp name and possible value */
387 switch (Op
->Asl
.ParseOpcode
)
389 case PARSEOP_NAMESEG
:
390 case PARSEOP_NAMESTRING
:
391 case PARSEOP_METHODCALL
:
392 case PARSEOP_STRING_LITERAL
:
394 UtDumpStringOp (Op
, Level
);
397 case PARSEOP_BYTECONST
:
399 UtDumpIntegerOp (Op
, Level
, 2);
402 case PARSEOP_WORDCONST
:
403 case PARSEOP_PACKAGE_LENGTH
:
405 UtDumpIntegerOp (Op
, Level
, 4);
408 case PARSEOP_DWORDCONST
:
411 UtDumpIntegerOp (Op
, Level
, 8);
414 case PARSEOP_QWORDCONST
:
415 case PARSEOP_INTEGER
:
420 UtDumpIntegerOp (Op
, Level
, 16);
423 case PARSEOP_INCLUDE
:
425 DbgPrint (ASL_TREE_OUTPUT
,
426 "Open: %s\n", Op
->Asl
.Value
.String
);
429 case PARSEOP_INCLUDE_END
:
431 DbgPrint (ASL_TREE_OUTPUT
,
432 "Close: %s\n", Op
->Asl
.Filename
);
437 UtDumpBasicOp (Op
, Level
);
441 /* Dump the remaining data */
443 DbgPrint (ASL_TREE_OUTPUT
, ASL_PARSE_TREE_DEBUG1
,
444 Op
->Asl
.ParseOpcode
, Op
->Asl
.CompileFlags
,
445 Op
->Asl
.LineNumber
, Op
->Asl
.EndLine
,
446 Op
->Asl
.LogicalLineNumber
, Op
->Asl
.EndLogicalLine
);
448 TrPrintOpFlags (Op
->Asl
.CompileFlags
, ASL_TREE_OUTPUT
);
449 DbgPrint (ASL_TREE_OUTPUT
, "\n");
454 /*******************************************************************************
456 * FUNCTION: LsWriteNodeToListing
458 * PARAMETERS: Op - Parse node to write to the listing file.
459 * FileId - ID of current listing file
463 * DESCRIPTION: Write "a node" to the listing file. This means to
464 * 1) Write out all of the source text associated with the node
465 * 2) Write out all of the AML bytes associated with the node
466 * 3) Write any compiler exceptions associated with the node
468 ******************************************************************************/
471 LsWriteNodeToListing (
472 ACPI_PARSE_OBJECT
*Op
,
475 const ACPI_OPCODE_INFO
*OpInfo
;
482 OpInfo
= AcpiPsGetOpcodeInfo (Op
->Asl
.AmlOpcode
);
483 OpClass
= OpInfo
->Class
;
485 /* TBD: clean this up with a single flag that says:
486 * I start a named output block
488 if (FileId
== ASL_FILE_C_SOURCE_OUTPUT
)
490 switch (Op
->Asl
.ParseOpcode
)
492 case PARSEOP_DEFINITION_BLOCK
:
493 case PARSEOP_METHODCALL
:
494 case PARSEOP_INCLUDE
:
495 case PARSEOP_INCLUDE_END
:
496 case PARSEOP_DEFAULT_ARG
:
504 case AML_CLASS_NAMED_OBJECT
:
506 switch (Op
->Asl
.AmlOpcode
)
515 if (Op
->Asl
.ExternalName
)
517 LsFlushListingBuffer (FileId
);
518 FlPrintFile (FileId
, " };\n");
526 /* Don't care about other objects */
534 /* These cases do not have a corresponding AML opcode */
536 switch (Op
->Asl
.ParseOpcode
)
538 case PARSEOP_DEFINITION_BLOCK
:
540 /* Always start a definition block at AML offset zero */
542 AslGbl_CurrentAmlOffset
= 0;
543 LsWriteSourceLines (Op
->Asl
.EndLine
, Op
->Asl
.EndLogicalLine
, FileId
);
545 /* Use the table Signature and TableId to build a unique name */
549 case ASL_FILE_ASM_SOURCE_OUTPUT
:
553 AslGbl_TableSignature
, AslGbl_TableId
);
556 case ASL_FILE_C_SOURCE_OUTPUT
:
559 " unsigned char %s_%s_Header [] =\n {\n",
560 AslGbl_TableSignature
, AslGbl_TableId
);
563 case ASL_FILE_ASM_INCLUDE_OUTPUT
:
566 "extrn %s_%s_Header : byte\n",
567 AslGbl_TableSignature
, AslGbl_TableId
);
570 case ASL_FILE_C_INCLUDE_OUTPUT
:
573 "extern unsigned char %s_%s_Header [];\n",
574 AslGbl_TableSignature
, AslGbl_TableId
);
584 case PARSEOP_METHODCALL
:
586 LsWriteSourceLines (Op
->Asl
.LineNumber
, Op
->Asl
.LogicalLineNumber
,
591 case PARSEOP_INCLUDE
:
593 /* Flush everything up to and including the include source line */
595 LsWriteSourceLines (Op
->Asl
.LineNumber
, Op
->Asl
.LogicalLineNumber
,
598 /* Create a new listing node and push it */
600 LsPushNode (Op
->Asl
.Value
.String
);
604 case PARSEOP_INCLUDE_END
:
606 /* Flush out the rest of the include file */
608 LsWriteSourceLines (Op
->Asl
.LineNumber
, Op
->Asl
.LogicalLineNumber
,
611 /* Pop off this listing node and go back to the parent file */
617 case PARSEOP_DEFAULT_ARG
:
619 if (Op
->Asl
.CompileFlags
& OP_IS_RESOURCE_DESC
)
621 LsWriteSourceLines (Op
->Asl
.LineNumber
, Op
->Asl
.EndLogicalLine
,
629 /* All other opcodes have an AML opcode */
635 * Otherwise, we look at the AML opcode because we can
636 * switch on the opcode type, getting an entire class
641 case AML_CLASS_ARGUMENT
: /* argument type only */
642 case AML_CLASS_INTERNAL
:
646 case AML_CLASS_NAMED_OBJECT
:
648 switch (Op
->Asl
.AmlOpcode
)
651 case AML_INDEX_FIELD_OP
:
652 case AML_BANK_FIELD_OP
:
654 * For fields, we want to dump all the AML after the
657 LsWriteSourceLines (Op
->Asl
.EndLine
, Op
->Asl
.EndLogicalLine
,
663 if (Op
->Asl
.CompileFlags
& OP_IS_RESOURCE_DESC
)
665 LsWriteSourceLines (Op
->Asl
.LineNumber
, Op
->Asl
.LogicalLineNumber
,
671 * For fields, we want to dump all the AML after the
674 LsWriteSourceLines (Op
->Asl
.EndLine
, Op
->Asl
.EndLogicalLine
,
681 LsWriteSourceLines (Op
->Asl
.LineNumber
, Op
->Asl
.LogicalLineNumber
,
686 switch (Op
->Asl
.AmlOpcode
)
691 /* These opcodes do not declare a new object, ignore them */
697 /* All other named object opcodes come here */
701 case ASL_FILE_ASM_SOURCE_OUTPUT
:
702 case ASL_FILE_C_SOURCE_OUTPUT
:
703 case ASL_FILE_ASM_INCLUDE_OUTPUT
:
704 case ASL_FILE_C_INCLUDE_OUTPUT
:
706 * For named objects, we will create a valid symbol so that the
707 * AML code can be referenced from C or ASM
709 if (Op
->Asl
.ExternalName
)
711 /* Get the full pathname associated with this node */
713 Pathname
= AcpiNsGetExternalPathname (Op
->Asl
.Node
);
714 Length
= strlen (Pathname
);
717 /* Convert all dots in the path to underscores */
719 for (i
= 0; i
< Length
; i
++)
721 if (Pathname
[i
] == '.')
727 /* Create the appropriate symbol in the output file */
731 case ASL_FILE_ASM_SOURCE_OUTPUT
:
735 AslGbl_TableSignature
, AslGbl_TableId
, &Pathname
[1]);
738 case ASL_FILE_C_SOURCE_OUTPUT
:
741 " unsigned char %s_%s_%s [] =\n {\n",
742 AslGbl_TableSignature
, AslGbl_TableId
, &Pathname
[1]);
745 case ASL_FILE_ASM_INCLUDE_OUTPUT
:
748 "extrn %s_%s_%s : byte\n",
749 AslGbl_TableSignature
, AslGbl_TableId
, &Pathname
[1]);
752 case ASL_FILE_C_INCLUDE_OUTPUT
:
755 "extern unsigned char %s_%s_%s [];\n",
756 AslGbl_TableSignature
, AslGbl_TableId
, &Pathname
[1]);
764 ACPI_FREE (Pathname
);
770 /* Nothing to do for listing file */
777 case AML_CLASS_EXECUTE
:
778 case AML_CLASS_CREATE
:
781 if ((Op
->Asl
.ParseOpcode
== PARSEOP_BUFFER
) &&
782 (Op
->Asl
.CompileFlags
& OP_IS_RESOURCE_DESC
))
787 LsWriteSourceLines (Op
->Asl
.LineNumber
, Op
->Asl
.LogicalLineNumber
,
791 case AML_CLASS_UNKNOWN
:
798 /*******************************************************************************
800 * FUNCTION: LsFinishSourceListing
802 * PARAMETERS: FileId - ID of current listing file.
806 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
807 * listing buffer, and flush out any remaining lines in the
810 ******************************************************************************/
813 LsFinishSourceListing (
817 if ((FileId
== ASL_FILE_ASM_INCLUDE_OUTPUT
) ||
818 (FileId
== ASL_FILE_C_INCLUDE_OUTPUT
))
823 LsFlushListingBuffer (FileId
);
824 AslGbl_CurrentAmlOffset
= 0;
826 /* Flush any remaining text in the source file */
828 if (FileId
== ASL_FILE_C_SOURCE_OUTPUT
)
830 FlPrintFile (FileId
, " /*\n");
833 while (LsWriteOneSourceLine (FileId
))
836 if (FileId
== ASL_FILE_C_SOURCE_OUTPUT
)
838 FlPrintFile (FileId
, "\n */\n };\n");
841 FlPrintFile (FileId
, "\n");
843 if (FileId
== ASL_FILE_LISTING_OUTPUT
)
845 /* Print a summary of the compile exceptions */
847 FlPrintFile (FileId
, "\n\nSummary of errors and warnings\n\n");
848 AePrintErrorLog (FileId
);
849 FlPrintFile (FileId
, "\n");
850 UtDisplaySummary (FileId
);
851 FlPrintFile (FileId
, "\n");