No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / compiler / asllisting.c
blobf229d5fb78190abc67094ab5aeb715706df7ec99
2 /******************************************************************************
4 * Module Name: asllisting - Listing file generation
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
13 * All rights reserved.
15 * 2. License
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
20 * property rights.
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
39 * conditions are met:
41 * 3. Conditions
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
65 * make.
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
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
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
89 * PARTICULAR PURPOSE.
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
98 * LIMITED REMEDY.
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 "aslcompiler.h"
119 #include "aslcompiler.y.h"
120 #include "amlcode.h"
121 #include "acparser.h"
122 #include "acnamesp.h"
124 #define _COMPONENT ACPI_COMPILER
125 ACPI_MODULE_NAME ("aslisting")
127 /* Local prototypes */
129 static void
130 LsDumpAscii (
131 UINT32 FileId,
132 UINT32 Count,
133 UINT8 *Buffer);
135 static void
136 LsDumpAsciiInComment (
137 UINT32 FileId,
138 UINT32 Count,
139 UINT8 *Buffer);
141 static ACPI_STATUS
142 LsAmlListingWalk (
143 ACPI_PARSE_OBJECT *Op,
144 UINT32 Level,
145 void *Context);
147 static void
148 LsGenerateListing (
149 UINT32 FileId);
151 static void
152 LsPushNode (
153 char *Filename);
155 static ASL_LISTING_NODE *
156 LsPopNode (
157 void);
159 static void
160 LsCheckException (
161 UINT32 LineNumber,
162 UINT32 FileId);
164 static void
165 LsFlushListingBuffer (
166 UINT32 FileId);
168 static void
169 LsWriteListingHexBytes (
170 UINT8 *Buffer,
171 UINT32 Length,
172 UINT32 FileId);
174 static UINT32
175 LsWriteOneSourceLine (
176 UINT32 FileId);
178 static void
179 LsFinishSourceListing (
180 UINT32 FileId);
182 static void
183 LsWriteSourceLines (
184 UINT32 ToLineNumber,
185 UINT32 ToLogicalLineNumber,
186 UINT32 FileId);
188 static void
189 LsWriteNodeToListing (
190 ACPI_PARSE_OBJECT *Op,
191 UINT32 FileId);
193 static void
194 LsDoHexOutputC (
195 void);
197 static void
198 LsDoHexOutputAsm (
199 void);
201 ACPI_STATUS
202 LsTreeWriteWalk (
203 ACPI_PARSE_OBJECT *Op,
204 UINT32 Level,
205 void *Context);
208 /*******************************************************************************
210 * FUNCTION: LsTreeWriteWalk
212 * PARAMETERS: ASL_WALK_CALLBACK
215 * RETURN: None.
217 * DESCRIPTION: Dump entire parse tree, for compiler debug only
219 ******************************************************************************/
221 ACPI_STATUS
222 LsTreeWriteWalk (
223 ACPI_PARSE_OBJECT *Op,
224 UINT32 Level,
225 void *Context)
228 /* Debug output */
230 DbgPrint (ASL_TREE_OUTPUT,
231 "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
232 UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
235 DbgPrint (ASL_TREE_OUTPUT, "\n");
236 return (AE_OK);
240 void
241 LsDumpParseTree (
242 void)
245 if (!Gbl_DebugFlag)
247 return;
250 DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
251 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
252 LsTreeWriteWalk, NULL, NULL);
256 /*******************************************************************************
258 * FUNCTION: LsDumpAscii
260 * PARAMETERS: FileId - ID of current listing file
261 * Count - Number of bytes to convert
262 * Buffer - Buffer of bytes to convert
264 * RETURN: None.
266 * DESCRIPTION: Convert hex bytes to ascii
268 ******************************************************************************/
270 static void
271 LsDumpAscii (
272 UINT32 FileId,
273 UINT32 Count,
274 UINT8 *Buffer)
276 UINT8 BufChar;
277 UINT32 i;
280 FlPrintFile (FileId, " \"");
281 for (i = 0; i < Count; i++)
283 BufChar = Buffer[i];
284 if (isprint (BufChar))
286 FlPrintFile (FileId, "%c", BufChar);
288 else
290 /* Not a printable character, just put out a dot */
292 FlPrintFile (FileId, ".");
295 FlPrintFile (FileId, "\"");
299 /*******************************************************************************
301 * FUNCTION: LsDumpAsciiInComment
303 * PARAMETERS: FileId - ID of current listing file
304 * Count - Number of bytes to convert
305 * Buffer - Buffer of bytes to convert
307 * RETURN: None.
309 * DESCRIPTION: Convert hex bytes to ascii
311 ******************************************************************************/
313 static void
314 LsDumpAsciiInComment (
315 UINT32 FileId,
316 UINT32 Count,
317 UINT8 *Buffer)
319 UINT8 BufChar = 0;
320 UINT8 LastChar;
321 UINT32 i;
324 FlPrintFile (FileId, " \"");
325 for (i = 0; i < Count; i++)
327 LastChar = BufChar;
328 BufChar = Buffer[i];
330 if (isprint (BufChar))
332 /* Handle embedded C comment sequences */
334 if (((LastChar == '*') && (BufChar == '/')) ||
335 ((LastChar == '/') && (BufChar == '*')))
337 /* Insert a space to break the sequence */
339 FlPrintFile (FileId, ".", BufChar);
342 FlPrintFile (FileId, "%c", BufChar);
344 else
346 /* Not a printable character, just put out a dot */
348 FlPrintFile (FileId, ".");
351 FlPrintFile (FileId, "\"");
355 /*******************************************************************************
357 * FUNCTION: LsAmlListingWalk
359 * PARAMETERS: ASL_WALK_CALLBACK
361 * RETURN: Status
363 * DESCRIPTION: Process one node during a listing file generation.
365 ******************************************************************************/
367 static ACPI_STATUS
368 LsAmlListingWalk (
369 ACPI_PARSE_OBJECT *Op,
370 UINT32 Level,
371 void *Context)
373 UINT8 FileByte;
374 UINT32 i;
375 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
378 LsWriteNodeToListing (Op, FileId);
380 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
382 /* Buffer is a resource template, don't dump the data all at once */
384 return (AE_OK);
387 /* Write the hex bytes to the listing file(s) (if requested) */
389 for (i = 0; i < Op->Asl.FinalAmlLength; i++)
391 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
393 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
394 AslAbort ();
396 LsWriteListingHexBytes (&FileByte, 1, FileId);
399 return (AE_OK);
403 /*******************************************************************************
405 * FUNCTION: LsGenerateListing
407 * PARAMETERS: FileId - ID of listing file
409 * RETURN: None
411 * DESCRIPTION: Generate a listing file. This can be one of the several types
412 * of "listings" supported.
414 ******************************************************************************/
416 static void
417 LsGenerateListing (
418 UINT32 FileId)
421 /* Start at the beginning of both the source and AML files */
423 FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
424 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
425 Gbl_SourceLine = 0;
426 Gbl_CurrentHexColumn = 0;
427 LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
429 /* Process all parse nodes */
431 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
432 NULL, (void *) ACPI_TO_POINTER (FileId));
434 /* Final processing */
436 LsFinishSourceListing (FileId);
440 /*******************************************************************************
442 * FUNCTION: LsDoListings
444 * PARAMETERS: None.
446 * RETURN: None
448 * DESCRIPTION: Generate all requested listing files.
450 ******************************************************************************/
452 void
453 LsDoListings (
454 void)
457 if (Gbl_C_OutputFlag)
459 LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
462 if (Gbl_ListingFlag)
464 LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
467 if (Gbl_AsmOutputFlag)
469 LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
472 if (Gbl_C_IncludeOutputFlag)
474 LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
477 if (Gbl_AsmIncludeOutputFlag)
479 LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
484 /*******************************************************************************
486 * FUNCTION: LsPushNode
488 * PARAMETERS: Filename - Pointer to the include filename
490 * RETURN: None
492 * DESCRIPTION: Push a listing node on the listing/include file stack. This
493 * stack enables tracking of include files (infinitely nested)
494 * and resumption of the listing of the parent file when the
495 * include file is finished.
497 ******************************************************************************/
499 static void
500 LsPushNode (
501 char *Filename)
503 ASL_LISTING_NODE *Lnode;
506 /* Create a new node */
508 Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE));
510 /* Initialize */
512 Lnode->Filename = Filename;
513 Lnode->LineNumber = 0;
515 /* Link (push) */
517 Lnode->Next = Gbl_ListingNode;
518 Gbl_ListingNode = Lnode;
522 /*******************************************************************************
524 * FUNCTION: LsPopNode
526 * PARAMETERS: None
528 * RETURN: List head after current head is popped off
530 * DESCRIPTION: Pop the current head of the list, free it, and return the
531 * next node on the stack (the new current node).
533 ******************************************************************************/
535 static ASL_LISTING_NODE *
536 LsPopNode (
537 void)
539 ASL_LISTING_NODE *Lnode;
542 /* Just grab the node at the head of the list */
544 Lnode = Gbl_ListingNode;
545 if ((!Lnode) ||
546 (!Lnode->Next))
548 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,
549 "Could not pop empty listing stack");
550 return Gbl_ListingNode;
553 Gbl_ListingNode = Lnode->Next;
554 ACPI_FREE (Lnode);
556 /* New "Current" node is the new head */
558 return (Gbl_ListingNode);
562 /*******************************************************************************
564 * FUNCTION: LsCheckException
566 * PARAMETERS: LineNumber - Current logical (cumulative) line #
567 * FileId - ID of output listing file
569 * RETURN: None
571 * DESCRIPTION: Check if there is an exception for this line, and if there is,
572 * put it in the listing immediately. Handles multiple errors
573 * per line. Gbl_NextError points to the next error in the
574 * sorted (by line #) list of compile errors/warnings.
576 ******************************************************************************/
578 static void
579 LsCheckException (
580 UINT32 LineNumber,
581 UINT32 FileId)
584 if ((!Gbl_NextError) ||
585 (LineNumber < Gbl_NextError->LogicalLineNumber ))
587 return;
590 /* Handle multiple errors per line */
592 if (FileId == ASL_FILE_LISTING_OUTPUT)
594 while (Gbl_NextError &&
595 (LineNumber >= Gbl_NextError->LogicalLineNumber))
597 AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n");
599 Gbl_NextError = Gbl_NextError->Next;
602 FlPrintFile (FileId, "\n");
607 /*******************************************************************************
609 * FUNCTION: LsFlushListingBuffer
611 * PARAMETERS: FileId - ID of the listing file
613 * RETURN: None
615 * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code
616 * buffer. Usually called at the termination of a single line
617 * of source code or when the buffer is full.
619 ******************************************************************************/
621 static void
622 LsFlushListingBuffer (
623 UINT32 FileId)
625 UINT32 i;
628 if (Gbl_CurrentHexColumn == 0)
630 return;
633 /* Write the hex bytes */
635 switch (FileId)
637 case ASL_FILE_LISTING_OUTPUT:
639 for (i = 0; i < Gbl_CurrentHexColumn; i++)
641 FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]);
644 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++)
646 FlWriteFile (FileId, ".", 1);
649 /* Write the ASCII character associated with each of the bytes */
651 LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
652 break;
655 case ASL_FILE_ASM_SOURCE_OUTPUT:
657 for (i = 0; i < Gbl_CurrentHexColumn; i++)
659 if (i > 0)
661 FlPrintFile (FileId, ",");
663 FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]);
666 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
668 FlWriteFile (FileId, " ", 1);
671 FlPrintFile (FileId, " ;%8.8X",
672 Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
674 /* Write the ASCII character associated with each of the bytes */
676 LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
677 break;
680 case ASL_FILE_C_SOURCE_OUTPUT:
682 for (i = 0; i < Gbl_CurrentHexColumn; i++)
684 FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]);
687 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
689 FlWriteFile (FileId, " ", 1);
692 FlPrintFile (FileId, " /* %8.8X",
693 Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
695 /* Write the ASCII character associated with each of the bytes */
697 LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
698 FlPrintFile (FileId, " */");
699 break;
701 default:
702 /* No other types supported */
703 return;
706 FlPrintFile (FileId, "\n");
708 Gbl_CurrentHexColumn = 0;
709 Gbl_HexBytesWereWritten = TRUE;
713 /*******************************************************************************
715 * FUNCTION: LsWriteListingHexBytes
717 * PARAMETERS: Buffer - AML code buffer
718 * Length - Number of AML bytes to write
719 * FileId - ID of current listing file.
721 * RETURN: None
723 * DESCRIPTION: Write the contents of the AML buffer to the listing file via
724 * the listing buffer. The listing buffer is flushed every 16
725 * AML bytes.
727 ******************************************************************************/
729 static void
730 LsWriteListingHexBytes (
731 UINT8 *Buffer,
732 UINT32 Length,
733 UINT32 FileId)
735 UINT32 i;
738 /* Transfer all requested bytes */
740 for (i = 0; i < Length; i++)
742 /* Print line header when buffer is empty */
744 if (Gbl_CurrentHexColumn == 0)
746 if (Gbl_HasIncludeFiles)
748 FlPrintFile (FileId, "%*s", 10, " ");
751 switch (FileId)
753 case ASL_FILE_LISTING_OUTPUT:
755 FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset);
756 break;
758 case ASL_FILE_ASM_SOURCE_OUTPUT:
760 FlPrintFile (FileId, " db ");
761 break;
763 case ASL_FILE_C_SOURCE_OUTPUT:
765 FlPrintFile (FileId, " ");
766 break;
768 default:
769 /* No other types supported */
770 return;
774 /* Transfer AML byte and update counts */
776 Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i];
778 Gbl_CurrentHexColumn++;
779 Gbl_CurrentAmlOffset++;
781 /* Flush buffer when it is full */
783 if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE)
785 LsFlushListingBuffer (FileId);
791 /*******************************************************************************
793 * FUNCTION: LsWriteOneSourceLine
795 * PARAMETERS: FileID - ID of current listing file
797 * RETURN: FALSE on EOF (input source file), TRUE otherwise
799 * DESCRIPTION: Read one line from the input source file and echo it to the
800 * listing file, prefixed with the line number, and if the source
801 * file contains include files, prefixed with the current filename
803 ******************************************************************************/
805 static UINT32
806 LsWriteOneSourceLine (
807 UINT32 FileId)
809 UINT8 FileByte;
812 Gbl_SourceLine++;
813 Gbl_ListingNode->LineNumber++;
815 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
817 FlPrintFile (FileId, " *");
819 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
821 FlPrintFile (FileId, "; ");
824 if (Gbl_HasIncludeFiles)
827 * This file contains "include" statements, print the current
828 * filename and line number within the current file
830 FlPrintFile (FileId, "%12s %5d....",
831 Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber);
833 else
835 /* No include files, just print the line number */
837 FlPrintFile (FileId, "%8d....", Gbl_SourceLine);
840 /* Read one line (up to a newline or EOF) */
842 while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK)
844 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
846 if (FileByte == '/')
848 FileByte = '*';
852 FlWriteFile (FileId, &FileByte, 1);
853 if (FileByte == '\n')
856 * Check if an error occurred on this source line during the compile.
857 * If so, we print the error message after the source line.
859 LsCheckException (Gbl_SourceLine, FileId);
860 return (1);
864 /* EOF on the input file was reached */
866 return (0);
870 /*******************************************************************************
872 * FUNCTION: LsFinishSourceListing
874 * PARAMETERS: FileId - ID of current listing file.
876 * RETURN: None
878 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
879 * listing buffer, and flush out any remaining lines in the
880 * source input file.
882 ******************************************************************************/
884 static void
885 LsFinishSourceListing (
886 UINT32 FileId)
889 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
890 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
892 return;
895 LsFlushListingBuffer (FileId);
896 Gbl_CurrentAmlOffset = 0;
898 /* Flush any remaining text in the source file */
900 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
902 FlPrintFile (FileId, " /*\n");
905 while (LsWriteOneSourceLine (FileId))
906 { ; }
908 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
910 FlPrintFile (FileId, "\n */\n };\n");
913 FlPrintFile (FileId, "\n");
915 if (FileId == ASL_FILE_LISTING_OUTPUT)
917 /* Print a summary of the compile exceptions */
919 FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
920 AePrintErrorLog (FileId);
921 FlPrintFile (FileId, "\n\n");
922 UtDisplaySummary (FileId);
923 FlPrintFile (FileId, "\n\n");
928 /*******************************************************************************
930 * FUNCTION: LsWriteSourceLines
932 * PARAMETERS: ToLineNumber -
933 * ToLogicalLineNumber - Write up to this source line number
934 * FileId - ID of current listing file
936 * RETURN: None
938 * DESCRIPTION: Read then write source lines to the listing file until we have
939 * reached the specified logical (cumulative) line number. This
940 * automatically echos out comment blocks and other non-AML
941 * generating text until we get to the actual AML-generating line
942 * of ASL code specified by the logical line number.
944 ******************************************************************************/
946 static void
947 LsWriteSourceLines (
948 UINT32 ToLineNumber,
949 UINT32 ToLogicalLineNumber,
950 UINT32 FileId)
953 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
954 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
956 return;
959 Gbl_CurrentLine = ToLogicalLineNumber;
961 /* Flush any hex bytes remaining from the last opcode */
963 LsFlushListingBuffer (FileId);
965 /* Read lines and write them as long as we are not caught up */
967 if (Gbl_SourceLine < Gbl_CurrentLine)
970 * If we just completed writing some AML hex bytes, output a linefeed
971 * to add some whitespace for readability.
973 if (Gbl_HexBytesWereWritten)
975 FlPrintFile (FileId, "\n");
976 Gbl_HexBytesWereWritten = FALSE;
979 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
981 FlPrintFile (FileId, " /*\n");
984 /* Write one line at a time until we have reached the target line # */
986 while ((Gbl_SourceLine < Gbl_CurrentLine) &&
987 LsWriteOneSourceLine (FileId))
988 { ; }
990 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
992 FlPrintFile (FileId, " */");
994 FlPrintFile (FileId, "\n");
999 /*******************************************************************************
1001 * FUNCTION: LsWriteNodeToListing
1003 * PARAMETERS: Op - Parse node to write to the listing file.
1004 * FileId - ID of current listing file
1006 * RETURN: None.
1008 * DESCRIPTION: Write "a node" to the listing file. This means to
1009 * 1) Write out all of the source text associated with the node
1010 * 2) Write out all of the AML bytes associated with the node
1011 * 3) Write any compiler exceptions associated with the node
1013 ******************************************************************************/
1015 static void
1016 LsWriteNodeToListing (
1017 ACPI_PARSE_OBJECT *Op,
1018 UINT32 FileId)
1020 const ACPI_OPCODE_INFO *OpInfo;
1021 UINT32 OpClass;
1022 char *Pathname;
1023 UINT32 Length;
1024 UINT32 i;
1027 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
1028 OpClass = OpInfo->Class;
1030 /* TBD: clean this up with a single flag that says:
1031 * I start a named output block
1033 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1035 switch (Op->Asl.ParseOpcode)
1037 case PARSEOP_DEFINITIONBLOCK:
1038 case PARSEOP_METHODCALL:
1039 case PARSEOP_INCLUDE:
1040 case PARSEOP_INCLUDE_END:
1041 case PARSEOP_DEFAULT_ARG:
1043 break;
1045 default:
1046 switch (OpClass)
1048 case AML_CLASS_NAMED_OBJECT:
1049 switch (Op->Asl.AmlOpcode)
1051 case AML_SCOPE_OP:
1052 case AML_ALIAS_OP:
1053 break;
1055 default:
1056 if (Op->Asl.ExternalName)
1058 LsFlushListingBuffer (FileId);
1059 FlPrintFile (FileId, " };\n");
1061 break;
1063 break;
1065 default:
1066 /* Don't care about other objects */
1067 break;
1069 break;
1073 /* These cases do not have a corresponding AML opcode */
1075 switch (Op->Asl.ParseOpcode)
1077 case PARSEOP_DEFINITIONBLOCK:
1079 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
1081 /* Use the table Signature and TableId to build a unique name */
1083 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1085 FlPrintFile (FileId,
1086 "%s_%s_Header \\\n",
1087 Gbl_TableSignature, Gbl_TableId);
1089 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1091 FlPrintFile (FileId,
1092 " unsigned char %s_%s_Header [] =\n {\n",
1093 Gbl_TableSignature, Gbl_TableId);
1095 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1097 FlPrintFile (FileId,
1098 "extrn %s_%s_Header : byte\n",
1099 Gbl_TableSignature, Gbl_TableId);
1101 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1103 FlPrintFile (FileId,
1104 "extern unsigned char %s_%s_Header [];\n",
1105 Gbl_TableSignature, Gbl_TableId);
1107 return;
1110 case PARSEOP_METHODCALL:
1112 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1113 FileId);
1114 return;
1117 case PARSEOP_INCLUDE:
1119 /* Flush everything up to and including the include source line */
1121 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1122 FileId);
1124 /* Create a new listing node and push it */
1126 LsPushNode (Op->Asl.Child->Asl.Value.String);
1127 return;
1130 case PARSEOP_INCLUDE_END:
1132 /* Flush out the rest of the include file */
1134 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1135 FileId);
1137 /* Pop off this listing node and go back to the parent file */
1139 (void) LsPopNode ();
1140 return;
1143 case PARSEOP_DEFAULT_ARG:
1145 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1147 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
1148 FileId);
1150 return;
1153 default:
1154 /* All other opcodes have an AML opcode */
1155 break;
1159 * Otherwise, we look at the AML opcode because we can
1160 * switch on the opcode type, getting an entire class
1161 * at once
1163 switch (OpClass)
1165 case AML_CLASS_ARGUMENT: /* argument type only */
1166 case AML_CLASS_INTERNAL:
1168 break;
1171 case AML_CLASS_NAMED_OBJECT:
1173 switch (Op->Asl.AmlOpcode)
1175 case AML_FIELD_OP:
1176 case AML_INDEX_FIELD_OP:
1177 case AML_BANK_FIELD_OP:
1180 * For fields, we want to dump all the AML after the
1181 * entire definition
1183 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1184 FileId);
1185 break;
1187 case AML_NAME_OP:
1189 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1191 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1192 FileId);
1194 else
1197 * For fields, we want to dump all the AML after the
1198 * entire definition
1200 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1201 FileId);
1203 break;
1205 default:
1206 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1207 FileId);
1208 break;
1211 switch (Op->Asl.AmlOpcode)
1213 case AML_SCOPE_OP:
1214 case AML_ALIAS_OP:
1216 /* These opcodes do not declare a new object, ignore them */
1218 break;
1220 default:
1222 /* All other named object opcodes come here */
1224 switch (FileId)
1226 case ASL_FILE_ASM_SOURCE_OUTPUT:
1227 case ASL_FILE_C_SOURCE_OUTPUT:
1228 case ASL_FILE_ASM_INCLUDE_OUTPUT:
1229 case ASL_FILE_C_INCLUDE_OUTPUT:
1232 * For named objects, we will create a valid symbol so that the
1233 * AML code can be referenced from C or ASM
1235 if (Op->Asl.ExternalName)
1237 /* Get the full pathname associated with this node */
1239 Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
1240 Length = strlen (Pathname);
1241 if (Length >= 4)
1243 /* Convert all dots in the path to underscores */
1245 for (i = 0; i < Length; i++)
1247 if (Pathname[i] == '.')
1249 Pathname[i] = '_';
1253 /* Create the appropriate symbol in the output file */
1255 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1257 FlPrintFile (FileId,
1258 "%s_%s_%s \\\n",
1259 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1261 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1263 FlPrintFile (FileId,
1264 " unsigned char %s_%s_%s [] =\n {\n",
1265 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1267 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1269 FlPrintFile (FileId,
1270 "extrn %s_%s_%s : byte\n",
1271 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1273 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1275 FlPrintFile (FileId,
1276 "extern unsigned char %s_%s_%s [];\n",
1277 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1280 ACPI_FREE (Pathname);
1282 break;
1284 default:
1285 /* Nothing to do for listing file */
1286 break;
1289 break;
1291 case AML_CLASS_EXECUTE:
1292 case AML_CLASS_CREATE:
1293 default:
1295 if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
1296 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
1298 return;
1301 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1302 FileId);
1303 break;
1305 case AML_CLASS_UNKNOWN:
1306 break;
1311 /*******************************************************************************
1313 * FUNCTION: LsDoHexOutput
1315 * PARAMETERS: None
1317 * RETURN: None.
1319 * DESCRIPTION: Create the hex output file.
1321 ******************************************************************************/
1323 void
1324 LsDoHexOutput (
1325 void)
1328 switch (Gbl_HexOutputFlag)
1330 case HEX_OUTPUT_C:
1332 LsDoHexOutputC ();
1333 break;
1335 case HEX_OUTPUT_ASM:
1337 LsDoHexOutputAsm ();
1338 break;
1340 default:
1341 /* No other output types supported */
1342 break;
1347 /*******************************************************************************
1349 * FUNCTION: LsDoHexOutputC
1351 * PARAMETERS: None
1353 * RETURN: None.
1355 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1356 * output file, but formatted into hex/ascii bytes suitable for
1357 * inclusion into a C source file.
1359 ******************************************************************************/
1361 static void
1362 LsDoHexOutputC (
1363 void)
1365 UINT32 j;
1366 UINT8 FileByte[HEX_TABLE_LINE_SIZE];
1367 UINT8 Buffer[4];
1368 UINT32 Offset = 0;
1371 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n *\n */\n");
1372 FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
1374 /* Start at the beginning of the AML file */
1376 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1378 /* Process all AML bytes in the AML file */
1380 j = 0;
1381 while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte[j], 1) == AE_OK)
1383 if (j == 0)
1385 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1388 /* Convert each AML byte to hex */
1390 UtConvertByteToHex (FileByte[j], Buffer);
1391 FlWriteFile (ASL_FILE_HEX_OUTPUT, Buffer, 4);
1392 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1394 /* An occasional linefeed improves readability */
1396 Offset++;
1397 j++;
1399 if (j >= HEX_TABLE_LINE_SIZE)
1401 /* End of line, emit the ascii dump of the entire line */
1403 FlPrintFile (ASL_FILE_HEX_OUTPUT,
1404 " /* %8.8X", Offset - HEX_TABLE_LINE_SIZE);
1406 /* Write the ASCII character associated with each of the bytes */
1408 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT,
1409 HEX_TABLE_LINE_SIZE, FileByte);
1410 FlPrintFile (ASL_FILE_HEX_OUTPUT, " */\n");
1412 /* Start new line */
1414 j = 0;
1418 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n};\n");
1419 FlCloseFile (ASL_FILE_HEX_OUTPUT);
1423 /*******************************************************************************
1425 * FUNCTION: LsDoHexOutputAsm
1427 * PARAMETERS: None
1429 * RETURN: None.
1431 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1432 * output file, but formatted into hex/ascii bytes suitable for
1433 * inclusion into a ASM source file.
1435 ******************************************************************************/
1437 static void
1438 LsDoHexOutputAsm (
1439 void)
1441 UINT32 j;
1442 UINT8 FileByte[HEX_TABLE_LINE_SIZE];
1443 UINT8 Buffer[4];
1444 UINT32 Offset = 0;
1445 BOOLEAN DoComma = FALSE;
1448 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n;\n");
1450 /* Start at the beginning of the AML file */
1452 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1454 /* Process all AML bytes in the AML file */
1456 j = 0;
1457 while (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte[j], 1) == AE_OK)
1459 if (j == 0)
1461 FlPrintFile (ASL_FILE_HEX_OUTPUT, " db ");
1463 else if (DoComma)
1465 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1466 DoComma = FALSE;
1469 /* Convert each AML byte to hex */
1471 UtConvertByteToAsmHex (FileByte[j], Buffer);
1472 FlWriteFile (ASL_FILE_HEX_OUTPUT, Buffer, 4);
1474 /* An occasional linefeed improves readability */
1476 Offset++;
1477 j++;
1478 if (j >= HEX_TABLE_LINE_SIZE)
1480 FlPrintFile (ASL_FILE_HEX_OUTPUT,
1481 " ;%8.8X", Offset - HEX_TABLE_LINE_SIZE);
1483 /* Write the ASCII character associated with each of the bytes */
1485 LsDumpAscii (ASL_FILE_HEX_OUTPUT, HEX_TABLE_LINE_SIZE, FileByte);
1486 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1487 j = 0;
1489 else
1491 DoComma = TRUE;
1495 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1496 FlCloseFile (ASL_FILE_HEX_OUTPUT);