2 /******************************************************************************
4 * Module Name: asllisting - Listing file generation
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #include <contrib/dev/acpica/compiler/aslcompiler.h>
119 #include "aslcompiler.y.h"
120 #include <contrib/dev/acpica/include/amlcode.h>
121 #include <contrib/dev/acpica/include/acparser.h>
122 #include <contrib/dev/acpica/include/acnamesp.h>
124 #define _COMPONENT ACPI_COMPILER
125 ACPI_MODULE_NAME ("aslisting")
127 /* Local prototypes */
136 LsDumpAsciiInComment (
143 ACPI_PARSE_OBJECT *Op,
155 static ASL_LISTING_NODE *
165 LsFlushListingBuffer (
169 LsWriteListingHexBytes (
175 LsWriteOneSourceLine (
179 LsFinishSourceListing (
185 UINT32 ToLogicalLineNumber,
189 LsWriteNodeToListing (
190 ACPI_PARSE_OBJECT *Op,
207 ACPI_PARSE_OBJECT *Op,
212 /*******************************************************************************
214 * FUNCTION: LsTreeWriteWalk
216 * PARAMETERS: ASL_WALK_CALLBACK
221 * DESCRIPTION: Dump entire parse tree, for compiler debug only
223 ******************************************************************************/
227 ACPI_PARSE_OBJECT *Op,
234 DbgPrint (ASL_TREE_OUTPUT,
235 "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
236 UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
239 DbgPrint (ASL_TREE_OUTPUT, "\n");
254 DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
255 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
256 LsTreeWriteWalk, NULL, NULL);
260 /*******************************************************************************
262 * FUNCTION: LsDumpAscii
264 * PARAMETERS: FileId - ID of current listing file
265 * Count - Number of bytes to convert
266 * Buffer - Buffer of bytes to convert
270 * DESCRIPTION: Convert hex bytes to ascii
272 ******************************************************************************/
284 FlPrintFile (FileId, " \"");
285 for (i = 0; i < Count; i++)
288 if (isprint (BufChar))
290 FlPrintFile (FileId, "%c", BufChar);
294 /* Not a printable character, just put out a dot */
296 FlPrintFile (FileId, ".");
299 FlPrintFile (FileId, "\"");
303 /*******************************************************************************
305 * FUNCTION: LsDumpAsciiInComment
307 * PARAMETERS: FileId - ID of current listing file
308 * Count - Number of bytes to convert
309 * Buffer - Buffer of bytes to convert
313 * DESCRIPTION: Convert hex bytes to ascii
315 ******************************************************************************/
318 LsDumpAsciiInComment (
328 FlPrintFile (FileId, " \"");
329 for (i = 0; i < Count; i++)
334 if (isprint (BufChar))
336 /* Handle embedded C comment sequences */
338 if (((LastChar == '*') && (BufChar == '/')) ||
339 ((LastChar == '/') && (BufChar == '*')))
341 /* Insert a space to break the sequence */
343 FlPrintFile (FileId, ".", BufChar);
346 FlPrintFile (FileId, "%c", BufChar);
350 /* Not a printable character, just put out a dot */
352 FlPrintFile (FileId, ".");
355 FlPrintFile (FileId, "\"");
359 /*******************************************************************************
361 * FUNCTION: LsAmlListingWalk
363 * PARAMETERS: ASL_WALK_CALLBACK
367 * DESCRIPTION: Process one node during a listing file generation.
369 ******************************************************************************/
373 ACPI_PARSE_OBJECT *Op,
379 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
382 LsWriteNodeToListing (Op, FileId);
384 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
386 /* Buffer is a resource template, don't dump the data all at once */
391 /* Write the hex bytes to the listing file(s) (if requested) */
393 for (i = 0; i < Op->Asl.FinalAmlLength; i++)
395 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
397 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
400 LsWriteListingHexBytes (&FileByte, 1, FileId);
407 /*******************************************************************************
409 * FUNCTION: LsGenerateListing
411 * PARAMETERS: FileId - ID of listing file
415 * DESCRIPTION: Generate a listing file. This can be one of the several types
416 * of "listings" supported.
418 ******************************************************************************/
425 /* Start at the beginning of both the source and AML files */
427 FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
428 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
430 Gbl_CurrentHexColumn = 0;
431 LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
433 /* Process all parse nodes */
435 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
436 NULL, (void *) ACPI_TO_POINTER (FileId));
438 /* Final processing */
440 LsFinishSourceListing (FileId);
444 /*******************************************************************************
446 * FUNCTION: LsDoListings
452 * DESCRIPTION: Generate all requested listing files.
454 ******************************************************************************/
461 if (Gbl_C_OutputFlag)
463 LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
468 LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
471 if (Gbl_AsmOutputFlag)
473 LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
476 if (Gbl_C_IncludeOutputFlag)
478 LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
481 if (Gbl_AsmIncludeOutputFlag)
483 LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
488 /*******************************************************************************
490 * FUNCTION: LsPushNode
492 * PARAMETERS: Filename - Pointer to the include filename
496 * DESCRIPTION: Push a listing node on the listing/include file stack. This
497 * stack enables tracking of include files (infinitely nested)
498 * and resumption of the listing of the parent file when the
499 * include file is finished.
501 ******************************************************************************/
507 ASL_LISTING_NODE *Lnode;
510 /* Create a new node */
512 Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE));
516 Lnode->Filename = Filename;
517 Lnode->LineNumber = 0;
521 Lnode->Next = Gbl_ListingNode;
522 Gbl_ListingNode = Lnode;
526 /*******************************************************************************
528 * FUNCTION: LsPopNode
532 * RETURN: List head after current head is popped off
534 * DESCRIPTION: Pop the current head of the list, free it, and return the
535 * next node on the stack (the new current node).
537 ******************************************************************************/
539 static ASL_LISTING_NODE *
543 ASL_LISTING_NODE *Lnode;
546 /* Just grab the node at the head of the list */
548 Lnode = Gbl_ListingNode;
552 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,
553 "Could not pop empty listing stack");
554 return Gbl_ListingNode;
557 Gbl_ListingNode = Lnode->Next;
560 /* New "Current" node is the new head */
562 return (Gbl_ListingNode);
566 /*******************************************************************************
568 * FUNCTION: LsCheckException
570 * PARAMETERS: LineNumber - Current logical (cumulative) line #
571 * FileId - ID of output listing file
575 * DESCRIPTION: Check if there is an exception for this line, and if there is,
576 * put it in the listing immediately. Handles multiple errors
577 * per line. Gbl_NextError points to the next error in the
578 * sorted (by line #) list of compile errors/warnings.
580 ******************************************************************************/
588 if ((!Gbl_NextError) ||
589 (LineNumber < Gbl_NextError->LogicalLineNumber ))
594 /* Handle multiple errors per line */
596 if (FileId == ASL_FILE_LISTING_OUTPUT)
598 while (Gbl_NextError &&
599 (LineNumber >= Gbl_NextError->LogicalLineNumber))
601 AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n");
603 Gbl_NextError = Gbl_NextError->Next;
606 FlPrintFile (FileId, "\n");
611 /*******************************************************************************
613 * FUNCTION: LsFlushListingBuffer
615 * PARAMETERS: FileId - ID of the listing file
619 * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code
620 * buffer. Usually called at the termination of a single line
621 * of source code or when the buffer is full.
623 ******************************************************************************/
626 LsFlushListingBuffer (
632 if (Gbl_CurrentHexColumn == 0)
637 /* Write the hex bytes */
641 case ASL_FILE_LISTING_OUTPUT:
643 for (i = 0; i < Gbl_CurrentHexColumn; i++)
645 FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]);
648 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++)
650 FlWriteFile (FileId, ".", 1);
653 /* Write the ASCII character associated with each of the bytes */
655 LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
659 case ASL_FILE_ASM_SOURCE_OUTPUT:
661 for (i = 0; i < Gbl_CurrentHexColumn; i++)
665 FlPrintFile (FileId, ",");
667 FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]);
670 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
672 FlWriteFile (FileId, " ", 1);
675 FlPrintFile (FileId, " ;%8.8X",
676 Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
678 /* Write the ASCII character associated with each of the bytes */
680 LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
684 case ASL_FILE_C_SOURCE_OUTPUT:
686 for (i = 0; i < Gbl_CurrentHexColumn; i++)
688 FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]);
691 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
693 FlWriteFile (FileId, " ", 1);
696 FlPrintFile (FileId, " /* %8.8X",
697 Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
699 /* Write the ASCII character associated with each of the bytes */
701 LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
702 FlPrintFile (FileId, " */");
706 /* No other types supported */
710 FlPrintFile (FileId, "\n");
712 Gbl_CurrentHexColumn = 0;
713 Gbl_HexBytesWereWritten = TRUE;
717 /*******************************************************************************
719 * FUNCTION: LsWriteListingHexBytes
721 * PARAMETERS: Buffer - AML code buffer
722 * Length - Number of AML bytes to write
723 * FileId - ID of current listing file.
727 * DESCRIPTION: Write the contents of the AML buffer to the listing file via
728 * the listing buffer. The listing buffer is flushed every 16
731 ******************************************************************************/
734 LsWriteListingHexBytes (
742 /* Transfer all requested bytes */
744 for (i = 0; i < Length; i++)
746 /* Print line header when buffer is empty */
748 if (Gbl_CurrentHexColumn == 0)
750 if (Gbl_HasIncludeFiles)
752 FlPrintFile (FileId, "%*s", 10, " ");
757 case ASL_FILE_LISTING_OUTPUT:
759 FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset);
762 case ASL_FILE_ASM_SOURCE_OUTPUT:
764 FlPrintFile (FileId, " db ");
767 case ASL_FILE_C_SOURCE_OUTPUT:
769 FlPrintFile (FileId, " ");
773 /* No other types supported */
778 /* Transfer AML byte and update counts */
780 Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i];
782 Gbl_CurrentHexColumn++;
783 Gbl_CurrentAmlOffset++;
785 /* Flush buffer when it is full */
787 if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE)
789 LsFlushListingBuffer (FileId);
795 /*******************************************************************************
797 * FUNCTION: LsWriteOneSourceLine
799 * PARAMETERS: FileID - ID of current listing file
801 * RETURN: FALSE on EOF (input source file), TRUE otherwise
803 * DESCRIPTION: Read one line from the input source file and echo it to the
804 * listing file, prefixed with the line number, and if the source
805 * file contains include files, prefixed with the current filename
807 ******************************************************************************/
810 LsWriteOneSourceLine (
817 Gbl_ListingNode->LineNumber++;
819 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
821 FlPrintFile (FileId, " *");
823 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
825 FlPrintFile (FileId, "; ");
828 if (Gbl_HasIncludeFiles)
831 * This file contains "include" statements, print the current
832 * filename and line number within the current file
834 FlPrintFile (FileId, "%12s %5d....",
835 Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber);
839 /* No include files, just print the line number */
841 FlPrintFile (FileId, "%8d....", Gbl_SourceLine);
844 /* Read one line (up to a newline or EOF) */
846 while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK)
848 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
856 FlWriteFile (FileId, &FileByte, 1);
857 if (FileByte == '\n')
860 * Check if an error occurred on this source line during the compile.
861 * If so, we print the error message after the source line.
863 LsCheckException (Gbl_SourceLine, FileId);
868 /* EOF on the input file was reached */
874 /*******************************************************************************
876 * FUNCTION: LsFinishSourceListing
878 * PARAMETERS: FileId - ID of current listing file.
882 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
883 * listing buffer, and flush out any remaining lines in the
886 ******************************************************************************/
889 LsFinishSourceListing (
893 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
894 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
899 LsFlushListingBuffer (FileId);
900 Gbl_CurrentAmlOffset = 0;
902 /* Flush any remaining text in the source file */
904 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
906 FlPrintFile (FileId, " /*\n");
909 while (LsWriteOneSourceLine (FileId))
912 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
914 FlPrintFile (FileId, "\n */\n };\n");
917 FlPrintFile (FileId, "\n");
919 if (FileId == ASL_FILE_LISTING_OUTPUT)
921 /* Print a summary of the compile exceptions */
923 FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
924 AePrintErrorLog (FileId);
925 FlPrintFile (FileId, "\n\n");
926 UtDisplaySummary (FileId);
927 FlPrintFile (FileId, "\n\n");
932 /*******************************************************************************
934 * FUNCTION: LsWriteSourceLines
936 * PARAMETERS: ToLineNumber -
937 * ToLogicalLineNumber - Write up to this source line number
938 * FileId - ID of current listing file
942 * DESCRIPTION: Read then write source lines to the listing file until we have
943 * reached the specified logical (cumulative) line number. This
944 * automatically echos out comment blocks and other non-AML
945 * generating text until we get to the actual AML-generating line
946 * of ASL code specified by the logical line number.
948 ******************************************************************************/
953 UINT32 ToLogicalLineNumber,
957 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
958 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
963 Gbl_CurrentLine = ToLogicalLineNumber;
965 /* Flush any hex bytes remaining from the last opcode */
967 LsFlushListingBuffer (FileId);
969 /* Read lines and write them as long as we are not caught up */
971 if (Gbl_SourceLine < Gbl_CurrentLine)
974 * If we just completed writing some AML hex bytes, output a linefeed
975 * to add some whitespace for readability.
977 if (Gbl_HexBytesWereWritten)
979 FlPrintFile (FileId, "\n");
980 Gbl_HexBytesWereWritten = FALSE;
983 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
985 FlPrintFile (FileId, " /*\n");
988 /* Write one line at a time until we have reached the target line # */
990 while ((Gbl_SourceLine < Gbl_CurrentLine) &&
991 LsWriteOneSourceLine (FileId))
994 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
996 FlPrintFile (FileId, " */");
998 FlPrintFile (FileId, "\n");
1003 /*******************************************************************************
1005 * FUNCTION: LsWriteNodeToListing
1007 * PARAMETERS: Op - Parse node to write to the listing file.
1008 * FileId - ID of current listing file
1012 * DESCRIPTION: Write "a node" to the listing file. This means to
1013 * 1) Write out all of the source text associated with the node
1014 * 2) Write out all of the AML bytes associated with the node
1015 * 3) Write any compiler exceptions associated with the node
1017 ******************************************************************************/
1020 LsWriteNodeToListing (
1021 ACPI_PARSE_OBJECT *Op,
1024 const ACPI_OPCODE_INFO *OpInfo;
1031 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1032 OpClass = OpInfo->Class;
1034 /* TBD: clean this up with a single flag that says:
1035 * I start a named output block
1037 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1039 switch (Op->Asl.ParseOpcode)
1041 case PARSEOP_DEFINITIONBLOCK:
1042 case PARSEOP_METHODCALL:
1043 case PARSEOP_INCLUDE:
1044 case PARSEOP_INCLUDE_END:
1045 case PARSEOP_DEFAULT_ARG:
1052 case AML_CLASS_NAMED_OBJECT:
1053 switch (Op->Asl.AmlOpcode)
1060 if (Op->Asl.ExternalName)
1062 LsFlushListingBuffer (FileId);
1063 FlPrintFile (FileId, " };\n");
1070 /* Don't care about other objects */
1077 /* These cases do not have a corresponding AML opcode */
1079 switch (Op->Asl.ParseOpcode)
1081 case PARSEOP_DEFINITIONBLOCK:
1083 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
1085 /* Use the table Signature and TableId to build a unique name */
1087 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1089 FlPrintFile (FileId,
1090 "%s_%s_Header \\\n",
1091 Gbl_TableSignature, Gbl_TableId);
1093 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1095 FlPrintFile (FileId,
1096 " unsigned char %s_%s_Header [] =\n {\n",
1097 Gbl_TableSignature, Gbl_TableId);
1099 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1101 FlPrintFile (FileId,
1102 "extrn %s_%s_Header : byte\n",
1103 Gbl_TableSignature, Gbl_TableId);
1105 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1107 FlPrintFile (FileId,
1108 "extern unsigned char %s_%s_Header [];\n",
1109 Gbl_TableSignature, Gbl_TableId);
1114 case PARSEOP_METHODCALL:
1116 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1121 case PARSEOP_INCLUDE:
1123 /* Flush everything up to and including the include source line */
1125 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1128 /* Create a new listing node and push it */
1130 LsPushNode (Op->Asl.Child->Asl.Value.String);
1134 case PARSEOP_INCLUDE_END:
1136 /* Flush out the rest of the include file */
1138 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1141 /* Pop off this listing node and go back to the parent file */
1143 (void) LsPopNode ();
1147 case PARSEOP_DEFAULT_ARG:
1149 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1151 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
1158 /* All other opcodes have an AML opcode */
1163 * Otherwise, we look at the AML opcode because we can
1164 * switch on the opcode type, getting an entire class
1169 case AML_CLASS_ARGUMENT: /* argument type only */
1170 case AML_CLASS_INTERNAL:
1175 case AML_CLASS_NAMED_OBJECT:
1177 switch (Op->Asl.AmlOpcode)
1180 case AML_INDEX_FIELD_OP:
1181 case AML_BANK_FIELD_OP:
1184 * For fields, we want to dump all the AML after the
1187 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1193 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1195 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1201 * For fields, we want to dump all the AML after the
1204 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1210 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1215 switch (Op->Asl.AmlOpcode)
1220 /* These opcodes do not declare a new object, ignore them */
1226 /* All other named object opcodes come here */
1230 case ASL_FILE_ASM_SOURCE_OUTPUT:
1231 case ASL_FILE_C_SOURCE_OUTPUT:
1232 case ASL_FILE_ASM_INCLUDE_OUTPUT:
1233 case ASL_FILE_C_INCLUDE_OUTPUT:
1236 * For named objects, we will create a valid symbol so that the
1237 * AML code can be referenced from C or ASM
1239 if (Op->Asl.ExternalName)
1241 /* Get the full pathname associated with this node */
1243 Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
1244 Length = strlen (Pathname);
1247 /* Convert all dots in the path to underscores */
1249 for (i = 0; i < Length; i++)
1251 if (Pathname[i] == '.')
1257 /* Create the appropriate symbol in the output file */
1259 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1261 FlPrintFile (FileId,
1263 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1265 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1267 FlPrintFile (FileId,
1268 " unsigned char %s_%s_%s [] =\n {\n",
1269 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1271 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1273 FlPrintFile (FileId,
1274 "extrn %s_%s_%s : byte\n",
1275 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1277 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1279 FlPrintFile (FileId,
1280 "extern unsigned char %s_%s_%s [];\n",
1281 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1284 ACPI_FREE (Pathname);
1289 /* Nothing to do for listing file */
1295 case AML_CLASS_EXECUTE:
1296 case AML_CLASS_CREATE:
1299 if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
1300 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
1305 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1309 case AML_CLASS_UNKNOWN:
1315 /*******************************************************************************
1317 * FUNCTION: LsDoHexOutput
1323 * DESCRIPTION: Create the hex output file.
1325 ******************************************************************************/
1332 switch (Gbl_HexOutputFlag)
1339 case HEX_OUTPUT_ASM:
1341 LsDoHexOutputAsm ();
1344 case HEX_OUTPUT_ASL:
1346 LsDoHexOutputAsl ();
1350 /* No other output types supported */
1356 /*******************************************************************************
1358 * FUNCTION: LsDoHexOutputC
1364 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1365 * output file, but formatted into hex/ascii bytes suitable for
1366 * inclusion into a C source file.
1368 ******************************************************************************/
1374 UINT8 FileData[HEX_TABLE_LINE_SIZE];
1381 /* Get AML size, seek back to start */
1383 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1385 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
1386 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
1388 FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
1390 while (Offset < AmlFileSize)
1392 /* Read enough bytes needed for one output line */
1394 LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1395 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1401 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1403 for (i = 0; i < LineLength; i++)
1406 * Print each hex byte.
1407 * Add a comma until the very last byte of the AML file
1408 * (Some C compilers complain about a trailing comma)
1410 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
1411 if ((Offset + i + 1) < AmlFileSize)
1413 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1417 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1421 /* Add fill spaces if needed for last line */
1423 if (LineLength < HEX_TABLE_LINE_SIZE)
1425 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1426 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1429 /* Emit the offset and ascii dump for the entire line */
1431 FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
1432 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1433 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
1434 HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
1436 Offset += LineLength;
1439 FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
1440 FlCloseFile (ASL_FILE_HEX_OUTPUT);
1444 /*******************************************************************************
1446 * FUNCTION: LsDoHexOutputAsl
1452 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1453 * output file, but formatted into hex/ascii bytes suitable for
1454 * inclusion into a C source file.
1456 ******************************************************************************/
1462 UINT8 FileData[HEX_TABLE_LINE_SIZE];
1469 /* Get AML size, seek back to start */
1471 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1473 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n");
1474 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
1476 FlPrintFile (ASL_FILE_HEX_OUTPUT, " Name (BUF1, Buffer()\n {\n");
1478 while (Offset < AmlFileSize)
1480 /* Read enough bytes needed for one output line */
1482 LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1483 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1489 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1491 for (i = 0; i < LineLength; i++)
1494 * Print each hex byte.
1495 * Add a comma until the very last byte of the AML file
1496 * (Some C compilers complain about a trailing comma)
1498 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
1499 if ((Offset + i + 1) < AmlFileSize)
1501 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1505 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1509 /* Add fill spaces if needed for last line */
1511 if (LineLength < HEX_TABLE_LINE_SIZE)
1513 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1514 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1517 /* Emit the offset and ascii dump for the entire line */
1519 FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
1520 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1521 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
1522 HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
1524 Offset += LineLength;
1527 FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n");
1528 FlCloseFile (ASL_FILE_HEX_OUTPUT);
1532 /*******************************************************************************
1534 * FUNCTION: LsDoHexOutputAsm
1540 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1541 * output file, but formatted into hex/ascii bytes suitable for
1542 * inclusion into a ASM source file.
1544 ******************************************************************************/
1550 UINT8 FileData[HEX_TABLE_LINE_SIZE];
1557 /* Get AML size, seek back to start */
1559 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1561 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
1562 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
1565 while (Offset < AmlFileSize)
1567 /* Read enough bytes needed for one output line */
1569 LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1570 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1576 FlPrintFile (ASL_FILE_HEX_OUTPUT, " db ");
1578 for (i = 0; i < LineLength; i++)
1581 * Print each hex byte.
1582 * Add a comma until the last byte of the line
1584 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
1585 if ((i + 1) < LineLength)
1587 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1591 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1593 /* Add fill spaces if needed for last line */
1595 if (LineLength < HEX_TABLE_LINE_SIZE)
1597 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1598 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1601 /* Emit the offset and ascii dump for the entire line */
1603 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset);
1604 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1605 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1607 Offset += LineLength;
1610 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1611 FlCloseFile (ASL_FILE_HEX_OUTPUT);