2 /******************************************************************************
4 * Module Name: asllisting - Listing file generation
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #include <contrib/dev/acpica/compiler/aslcompiler.h>
47 #include "aslcompiler.y.h"
48 #include <contrib/dev/acpica/include/amlcode.h>
49 #include <contrib/dev/acpica/include/acparser.h>
50 #include <contrib/dev/acpica/include/acnamesp.h>
52 #define _COMPONENT ACPI_COMPILER
53 ACPI_MODULE_NAME ("aslisting")
55 /* Local prototypes */
64 LsDumpAsciiInComment (
71 ACPI_PARSE_OBJECT *Op,
83 static ASL_LISTING_NODE *
93 LsFlushListingBuffer (
97 LsWriteListingHexBytes (
103 LsWriteOneSourceLine (
107 LsFinishSourceListing (
113 UINT32 ToLogicalLineNumber,
117 LsWriteNodeToListing (
118 ACPI_PARSE_OBJECT *Op,
135 ACPI_PARSE_OBJECT *Op,
140 /*******************************************************************************
142 * FUNCTION: LsTreeWriteWalk
144 * PARAMETERS: ASL_WALK_CALLBACK
149 * DESCRIPTION: Dump entire parse tree, for compiler debug only
151 ******************************************************************************/
155 ACPI_PARSE_OBJECT *Op,
162 DbgPrint (ASL_TREE_OUTPUT,
163 "%5.5d [%2d]", Op->Asl.LogicalLineNumber, Level);
164 UtPrintFormattedName (Op->Asl.ParseOpcode, Level);
167 DbgPrint (ASL_TREE_OUTPUT, "\n");
182 DbgPrint (ASL_TREE_OUTPUT, "\nOriginal parse tree from parser:\n\n");
183 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD,
184 LsTreeWriteWalk, NULL, NULL);
188 /*******************************************************************************
190 * FUNCTION: LsDumpAscii
192 * PARAMETERS: FileId - ID of current listing file
193 * Count - Number of bytes to convert
194 * Buffer - Buffer of bytes to convert
198 * DESCRIPTION: Convert hex bytes to ascii
200 ******************************************************************************/
212 FlPrintFile (FileId, " \"");
213 for (i = 0; i < Count; i++)
216 if (isprint (BufChar))
218 FlPrintFile (FileId, "%c", BufChar);
222 /* Not a printable character, just put out a dot */
224 FlPrintFile (FileId, ".");
227 FlPrintFile (FileId, "\"");
231 /*******************************************************************************
233 * FUNCTION: LsDumpAsciiInComment
235 * PARAMETERS: FileId - ID of current listing file
236 * Count - Number of bytes to convert
237 * Buffer - Buffer of bytes to convert
241 * DESCRIPTION: Convert hex bytes to ascii
243 ******************************************************************************/
246 LsDumpAsciiInComment (
256 FlPrintFile (FileId, " \"");
257 for (i = 0; i < Count; i++)
262 if (isprint (BufChar))
264 /* Handle embedded C comment sequences */
266 if (((LastChar == '*') && (BufChar == '/')) ||
267 ((LastChar == '/') && (BufChar == '*')))
269 /* Insert a space to break the sequence */
271 FlPrintFile (FileId, ".", BufChar);
274 FlPrintFile (FileId, "%c", BufChar);
278 /* Not a printable character, just put out a dot */
280 FlPrintFile (FileId, ".");
283 FlPrintFile (FileId, "\"");
287 /*******************************************************************************
289 * FUNCTION: LsAmlListingWalk
291 * PARAMETERS: ASL_WALK_CALLBACK
295 * DESCRIPTION: Process one node during a listing file generation.
297 ******************************************************************************/
301 ACPI_PARSE_OBJECT *Op,
307 UINT32 FileId = (UINT32) ACPI_TO_INTEGER (Context);
310 LsWriteNodeToListing (Op, FileId);
312 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DATA)
314 /* Buffer is a resource template, don't dump the data all at once */
319 /* Write the hex bytes to the listing file(s) (if requested) */
321 for (i = 0; i < Op->Asl.FinalAmlLength; i++)
323 if (ACPI_FAILURE (FlReadFile (ASL_FILE_AML_OUTPUT, &FileByte, 1)))
325 FlFileError (ASL_FILE_AML_OUTPUT, ASL_MSG_READ);
328 LsWriteListingHexBytes (&FileByte, 1, FileId);
335 /*******************************************************************************
337 * FUNCTION: LsGenerateListing
339 * PARAMETERS: FileId - ID of listing file
343 * DESCRIPTION: Generate a listing file. This can be one of the several types
344 * of "listings" supported.
346 ******************************************************************************/
353 /* Start at the beginning of both the source and AML files */
355 FlSeekFile (ASL_FILE_SOURCE_OUTPUT, 0);
356 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
358 Gbl_CurrentHexColumn = 0;
359 LsPushNode (Gbl_Files[ASL_FILE_INPUT].Filename);
361 /* Process all parse nodes */
363 TrWalkParseTree (RootNode, ASL_WALK_VISIT_DOWNWARD, LsAmlListingWalk,
364 NULL, (void *) ACPI_TO_POINTER (FileId));
366 /* Final processing */
368 LsFinishSourceListing (FileId);
372 /*******************************************************************************
374 * FUNCTION: LsDoListings
380 * DESCRIPTION: Generate all requested listing files.
382 ******************************************************************************/
389 if (Gbl_C_OutputFlag)
391 LsGenerateListing (ASL_FILE_C_SOURCE_OUTPUT);
396 LsGenerateListing (ASL_FILE_LISTING_OUTPUT);
399 if (Gbl_AsmOutputFlag)
401 LsGenerateListing (ASL_FILE_ASM_SOURCE_OUTPUT);
404 if (Gbl_C_IncludeOutputFlag)
406 LsGenerateListing (ASL_FILE_C_INCLUDE_OUTPUT);
409 if (Gbl_AsmIncludeOutputFlag)
411 LsGenerateListing (ASL_FILE_ASM_INCLUDE_OUTPUT);
416 /*******************************************************************************
418 * FUNCTION: LsPushNode
420 * PARAMETERS: Filename - Pointer to the include filename
424 * DESCRIPTION: Push a listing node on the listing/include file stack. This
425 * stack enables tracking of include files (infinitely nested)
426 * and resumption of the listing of the parent file when the
427 * include file is finished.
429 ******************************************************************************/
435 ASL_LISTING_NODE *Lnode;
438 /* Create a new node */
440 Lnode = UtLocalCalloc (sizeof (ASL_LISTING_NODE));
444 Lnode->Filename = Filename;
445 Lnode->LineNumber = 0;
449 Lnode->Next = Gbl_ListingNode;
450 Gbl_ListingNode = Lnode;
454 /*******************************************************************************
456 * FUNCTION: LsPopNode
460 * RETURN: List head after current head is popped off
462 * DESCRIPTION: Pop the current head of the list, free it, and return the
463 * next node on the stack (the new current node).
465 ******************************************************************************/
467 static ASL_LISTING_NODE *
471 ASL_LISTING_NODE *Lnode;
474 /* Just grab the node at the head of the list */
476 Lnode = Gbl_ListingNode;
480 AslError (ASL_ERROR, ASL_MSG_COMPILER_INTERNAL, NULL,
481 "Could not pop empty listing stack");
482 return Gbl_ListingNode;
485 Gbl_ListingNode = Lnode->Next;
488 /* New "Current" node is the new head */
490 return (Gbl_ListingNode);
494 /*******************************************************************************
496 * FUNCTION: LsCheckException
498 * PARAMETERS: LineNumber - Current logical (cumulative) line #
499 * FileId - ID of output listing file
503 * DESCRIPTION: Check if there is an exception for this line, and if there is,
504 * put it in the listing immediately. Handles multiple errors
505 * per line. Gbl_NextError points to the next error in the
506 * sorted (by line #) list of compile errors/warnings.
508 ******************************************************************************/
516 if ((!Gbl_NextError) ||
517 (LineNumber < Gbl_NextError->LogicalLineNumber ))
522 /* Handle multiple errors per line */
524 if (FileId == ASL_FILE_LISTING_OUTPUT)
526 while (Gbl_NextError &&
527 (LineNumber >= Gbl_NextError->LogicalLineNumber))
529 AePrintException (FileId, Gbl_NextError, "\n[****iasl****]\n");
531 Gbl_NextError = Gbl_NextError->Next;
534 FlPrintFile (FileId, "\n");
539 /*******************************************************************************
541 * FUNCTION: LsFlushListingBuffer
543 * PARAMETERS: FileId - ID of the listing file
547 * DESCRIPTION: Flush out the current contents of the 16-byte hex AML code
548 * buffer. Usually called at the termination of a single line
549 * of source code or when the buffer is full.
551 ******************************************************************************/
554 LsFlushListingBuffer (
560 if (Gbl_CurrentHexColumn == 0)
565 /* Write the hex bytes */
569 case ASL_FILE_LISTING_OUTPUT:
571 for (i = 0; i < Gbl_CurrentHexColumn; i++)
573 FlPrintFile (FileId, "%2.2X ", Gbl_AmlBuffer[i]);
576 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 3); i++)
578 FlWriteFile (FileId, ".", 1);
581 /* Write the ASCII character associated with each of the bytes */
583 LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
587 case ASL_FILE_ASM_SOURCE_OUTPUT:
589 for (i = 0; i < Gbl_CurrentHexColumn; i++)
593 FlPrintFile (FileId, ",");
595 FlPrintFile (FileId, "0%2.2Xh", Gbl_AmlBuffer[i]);
598 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
600 FlWriteFile (FileId, " ", 1);
603 FlPrintFile (FileId, " ;%8.8X",
604 Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
606 /* Write the ASCII character associated with each of the bytes */
608 LsDumpAscii (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
612 case ASL_FILE_C_SOURCE_OUTPUT:
614 for (i = 0; i < Gbl_CurrentHexColumn; i++)
616 FlPrintFile (FileId, "0x%2.2X,", Gbl_AmlBuffer[i]);
619 for (i = 0; i < ((HEX_LISTING_LINE_SIZE - Gbl_CurrentHexColumn) * 5); i++)
621 FlWriteFile (FileId, " ", 1);
624 FlPrintFile (FileId, " /* %8.8X",
625 Gbl_CurrentAmlOffset - HEX_LISTING_LINE_SIZE);
627 /* Write the ASCII character associated with each of the bytes */
629 LsDumpAsciiInComment (FileId, Gbl_CurrentHexColumn, Gbl_AmlBuffer);
630 FlPrintFile (FileId, " */");
634 /* No other types supported */
638 FlPrintFile (FileId, "\n");
640 Gbl_CurrentHexColumn = 0;
641 Gbl_HexBytesWereWritten = TRUE;
645 /*******************************************************************************
647 * FUNCTION: LsWriteListingHexBytes
649 * PARAMETERS: Buffer - AML code buffer
650 * Length - Number of AML bytes to write
651 * FileId - ID of current listing file.
655 * DESCRIPTION: Write the contents of the AML buffer to the listing file via
656 * the listing buffer. The listing buffer is flushed every 16
659 ******************************************************************************/
662 LsWriteListingHexBytes (
670 /* Transfer all requested bytes */
672 for (i = 0; i < Length; i++)
674 /* Print line header when buffer is empty */
676 if (Gbl_CurrentHexColumn == 0)
678 if (Gbl_HasIncludeFiles)
680 FlPrintFile (FileId, "%*s", 10, " ");
685 case ASL_FILE_LISTING_OUTPUT:
687 FlPrintFile (FileId, "%8.8X....", Gbl_CurrentAmlOffset);
690 case ASL_FILE_ASM_SOURCE_OUTPUT:
692 FlPrintFile (FileId, " db ");
695 case ASL_FILE_C_SOURCE_OUTPUT:
697 FlPrintFile (FileId, " ");
701 /* No other types supported */
706 /* Transfer AML byte and update counts */
708 Gbl_AmlBuffer[Gbl_CurrentHexColumn] = Buffer[i];
710 Gbl_CurrentHexColumn++;
711 Gbl_CurrentAmlOffset++;
713 /* Flush buffer when it is full */
715 if (Gbl_CurrentHexColumn >= HEX_LISTING_LINE_SIZE)
717 LsFlushListingBuffer (FileId);
723 /*******************************************************************************
725 * FUNCTION: LsWriteOneSourceLine
727 * PARAMETERS: FileID - ID of current listing file
729 * RETURN: FALSE on EOF (input source file), TRUE otherwise
731 * DESCRIPTION: Read one line from the input source file and echo it to the
732 * listing file, prefixed with the line number, and if the source
733 * file contains include files, prefixed with the current filename
735 ******************************************************************************/
738 LsWriteOneSourceLine (
745 Gbl_ListingNode->LineNumber++;
747 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
749 FlPrintFile (FileId, " *");
751 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
753 FlPrintFile (FileId, "; ");
756 if (Gbl_HasIncludeFiles)
759 * This file contains "include" statements, print the current
760 * filename and line number within the current file
762 FlPrintFile (FileId, "%12s %5d....",
763 Gbl_ListingNode->Filename, Gbl_ListingNode->LineNumber);
767 /* No include files, just print the line number */
769 FlPrintFile (FileId, "%8d....", Gbl_SourceLine);
772 /* Read one line (up to a newline or EOF) */
774 while (FlReadFile (ASL_FILE_SOURCE_OUTPUT, &FileByte, 1) == AE_OK)
776 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
784 FlWriteFile (FileId, &FileByte, 1);
785 if (FileByte == '\n')
788 * Check if an error occurred on this source line during the compile.
789 * If so, we print the error message after the source line.
791 LsCheckException (Gbl_SourceLine, FileId);
796 /* EOF on the input file was reached */
802 /*******************************************************************************
804 * FUNCTION: LsFinishSourceListing
806 * PARAMETERS: FileId - ID of current listing file.
810 * DESCRIPTION: Cleanup routine for the listing file. Flush the hex AML
811 * listing buffer, and flush out any remaining lines in the
814 ******************************************************************************/
817 LsFinishSourceListing (
821 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
822 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
827 LsFlushListingBuffer (FileId);
828 Gbl_CurrentAmlOffset = 0;
830 /* Flush any remaining text in the source file */
832 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
834 FlPrintFile (FileId, " /*\n");
837 while (LsWriteOneSourceLine (FileId))
840 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
842 FlPrintFile (FileId, "\n */\n };\n");
845 FlPrintFile (FileId, "\n");
847 if (FileId == ASL_FILE_LISTING_OUTPUT)
849 /* Print a summary of the compile exceptions */
851 FlPrintFile (FileId, "\n\nSummary of errors and warnings\n\n");
852 AePrintErrorLog (FileId);
853 FlPrintFile (FileId, "\n\n");
854 UtDisplaySummary (FileId);
855 FlPrintFile (FileId, "\n\n");
860 /*******************************************************************************
862 * FUNCTION: LsWriteSourceLines
864 * PARAMETERS: ToLineNumber -
865 * ToLogicalLineNumber - Write up to this source line number
866 * FileId - ID of current listing file
870 * DESCRIPTION: Read then write source lines to the listing file until we have
871 * reached the specified logical (cumulative) line number. This
872 * automatically echos out comment blocks and other non-AML
873 * generating text until we get to the actual AML-generating line
874 * of ASL code specified by the logical line number.
876 ******************************************************************************/
881 UINT32 ToLogicalLineNumber,
885 if ((FileId == ASL_FILE_ASM_INCLUDE_OUTPUT) ||
886 (FileId == ASL_FILE_C_INCLUDE_OUTPUT))
891 Gbl_CurrentLine = ToLogicalLineNumber;
893 /* Flush any hex bytes remaining from the last opcode */
895 LsFlushListingBuffer (FileId);
897 /* Read lines and write them as long as we are not caught up */
899 if (Gbl_SourceLine < Gbl_CurrentLine)
902 * If we just completed writing some AML hex bytes, output a linefeed
903 * to add some whitespace for readability.
905 if (Gbl_HexBytesWereWritten)
907 FlPrintFile (FileId, "\n");
908 Gbl_HexBytesWereWritten = FALSE;
911 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
913 FlPrintFile (FileId, " /*\n");
916 /* Write one line at a time until we have reached the target line # */
918 while ((Gbl_SourceLine < Gbl_CurrentLine) &&
919 LsWriteOneSourceLine (FileId))
922 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
924 FlPrintFile (FileId, " */");
926 FlPrintFile (FileId, "\n");
931 /*******************************************************************************
933 * FUNCTION: LsWriteNodeToListing
935 * PARAMETERS: Op - Parse node to write to the listing file.
936 * FileId - ID of current listing file
940 * DESCRIPTION: Write "a node" to the listing file. This means to
941 * 1) Write out all of the source text associated with the node
942 * 2) Write out all of the AML bytes associated with the node
943 * 3) Write any compiler exceptions associated with the node
945 ******************************************************************************/
948 LsWriteNodeToListing (
949 ACPI_PARSE_OBJECT *Op,
952 const ACPI_OPCODE_INFO *OpInfo;
959 OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
960 OpClass = OpInfo->Class;
962 /* TBD: clean this up with a single flag that says:
963 * I start a named output block
965 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
967 switch (Op->Asl.ParseOpcode)
969 case PARSEOP_DEFINITIONBLOCK:
970 case PARSEOP_METHODCALL:
971 case PARSEOP_INCLUDE:
972 case PARSEOP_INCLUDE_END:
973 case PARSEOP_DEFAULT_ARG:
980 case AML_CLASS_NAMED_OBJECT:
981 switch (Op->Asl.AmlOpcode)
988 if (Op->Asl.ExternalName)
990 LsFlushListingBuffer (FileId);
991 FlPrintFile (FileId, " };\n");
998 /* Don't care about other objects */
1005 /* These cases do not have a corresponding AML opcode */
1007 switch (Op->Asl.ParseOpcode)
1009 case PARSEOP_DEFINITIONBLOCK:
1011 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine, FileId);
1013 /* Use the table Signature and TableId to build a unique name */
1015 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1017 FlPrintFile (FileId,
1018 "%s_%s_Header \\\n",
1019 Gbl_TableSignature, Gbl_TableId);
1021 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1023 FlPrintFile (FileId,
1024 " unsigned char %s_%s_Header [] =\n {\n",
1025 Gbl_TableSignature, Gbl_TableId);
1027 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1029 FlPrintFile (FileId,
1030 "extrn %s_%s_Header : byte\n",
1031 Gbl_TableSignature, Gbl_TableId);
1033 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1035 FlPrintFile (FileId,
1036 "extern unsigned char %s_%s_Header [];\n",
1037 Gbl_TableSignature, Gbl_TableId);
1042 case PARSEOP_METHODCALL:
1044 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1049 case PARSEOP_INCLUDE:
1051 /* Flush everything up to and including the include source line */
1053 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1056 /* Create a new listing node and push it */
1058 LsPushNode (Op->Asl.Child->Asl.Value.String);
1062 case PARSEOP_INCLUDE_END:
1064 /* Flush out the rest of the include file */
1066 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1069 /* Pop off this listing node and go back to the parent file */
1071 (void) LsPopNode ();
1075 case PARSEOP_DEFAULT_ARG:
1077 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1079 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.EndLogicalLine,
1086 /* All other opcodes have an AML opcode */
1091 * Otherwise, we look at the AML opcode because we can
1092 * switch on the opcode type, getting an entire class
1097 case AML_CLASS_ARGUMENT: /* argument type only */
1098 case AML_CLASS_INTERNAL:
1103 case AML_CLASS_NAMED_OBJECT:
1105 switch (Op->Asl.AmlOpcode)
1108 case AML_INDEX_FIELD_OP:
1109 case AML_BANK_FIELD_OP:
1112 * For fields, we want to dump all the AML after the
1115 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1121 if (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC)
1123 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1129 * For fields, we want to dump all the AML after the
1132 LsWriteSourceLines (Op->Asl.EndLine, Op->Asl.EndLogicalLine,
1138 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1143 switch (Op->Asl.AmlOpcode)
1148 /* These opcodes do not declare a new object, ignore them */
1154 /* All other named object opcodes come here */
1158 case ASL_FILE_ASM_SOURCE_OUTPUT:
1159 case ASL_FILE_C_SOURCE_OUTPUT:
1160 case ASL_FILE_ASM_INCLUDE_OUTPUT:
1161 case ASL_FILE_C_INCLUDE_OUTPUT:
1164 * For named objects, we will create a valid symbol so that the
1165 * AML code can be referenced from C or ASM
1167 if (Op->Asl.ExternalName)
1169 /* Get the full pathname associated with this node */
1171 Pathname = AcpiNsGetExternalPathname (Op->Asl.Node);
1172 Length = strlen (Pathname);
1175 /* Convert all dots in the path to underscores */
1177 for (i = 0; i < Length; i++)
1179 if (Pathname[i] == '.')
1185 /* Create the appropriate symbol in the output file */
1187 if (FileId == ASL_FILE_ASM_SOURCE_OUTPUT)
1189 FlPrintFile (FileId,
1191 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1193 if (FileId == ASL_FILE_C_SOURCE_OUTPUT)
1195 FlPrintFile (FileId,
1196 " unsigned char %s_%s_%s [] =\n {\n",
1197 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1199 if (FileId == ASL_FILE_ASM_INCLUDE_OUTPUT)
1201 FlPrintFile (FileId,
1202 "extrn %s_%s_%s : byte\n",
1203 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1205 if (FileId == ASL_FILE_C_INCLUDE_OUTPUT)
1207 FlPrintFile (FileId,
1208 "extern unsigned char %s_%s_%s [];\n",
1209 Gbl_TableSignature, Gbl_TableId, &Pathname[1]);
1212 ACPI_FREE (Pathname);
1217 /* Nothing to do for listing file */
1223 case AML_CLASS_EXECUTE:
1224 case AML_CLASS_CREATE:
1227 if ((Op->Asl.ParseOpcode == PARSEOP_BUFFER) &&
1228 (Op->Asl.CompileFlags & NODE_IS_RESOURCE_DESC))
1233 LsWriteSourceLines (Op->Asl.LineNumber, Op->Asl.LogicalLineNumber,
1237 case AML_CLASS_UNKNOWN:
1243 /*******************************************************************************
1245 * FUNCTION: LsDoHexOutput
1251 * DESCRIPTION: Create the hex output file.
1253 ******************************************************************************/
1260 switch (Gbl_HexOutputFlag)
1267 case HEX_OUTPUT_ASM:
1269 LsDoHexOutputAsm ();
1272 case HEX_OUTPUT_ASL:
1274 LsDoHexOutputAsl ();
1278 /* No other output types supported */
1284 /*******************************************************************************
1286 * FUNCTION: LsDoHexOutputC
1292 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1293 * output file, but formatted into hex/ascii bytes suitable for
1294 * inclusion into a C source file.
1296 ******************************************************************************/
1302 UINT8 FileData[HEX_TABLE_LINE_SIZE];
1309 /* Get AML size, seek back to start */
1311 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1313 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * C source code output\n");
1314 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
1316 FlPrintFile (ASL_FILE_HEX_OUTPUT, "unsigned char AmlCode[] =\n{\n");
1318 while (Offset < AmlFileSize)
1320 /* Read enough bytes needed for one output line */
1322 LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1323 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1329 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1331 for (i = 0; i < LineLength; i++)
1334 * Print each hex byte.
1335 * Add a comma until the very last byte of the AML file
1336 * (Some C compilers complain about a trailing comma)
1338 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
1339 if ((Offset + i + 1) < AmlFileSize)
1341 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1345 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1349 /* Add fill spaces if needed for last line */
1351 if (LineLength < HEX_TABLE_LINE_SIZE)
1353 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1354 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1357 /* Emit the offset and ascii dump for the entire line */
1359 FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
1360 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1361 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
1362 HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
1364 Offset += LineLength;
1367 FlPrintFile (ASL_FILE_HEX_OUTPUT, "};\n");
1368 FlCloseFile (ASL_FILE_HEX_OUTPUT);
1372 /*******************************************************************************
1374 * FUNCTION: LsDoHexOutputAsl
1380 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1381 * output file, but formatted into hex/ascii bytes suitable for
1382 * inclusion into a C source file.
1384 ******************************************************************************/
1390 UINT8 FileData[HEX_TABLE_LINE_SIZE];
1397 /* Get AML size, seek back to start */
1399 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1401 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * ASL source code output\n");
1402 FlPrintFile (ASL_FILE_HEX_OUTPUT, " * AML code block contains 0x%X bytes\n *\n */\n",
1404 FlPrintFile (ASL_FILE_HEX_OUTPUT, " Name (BUF1, Buffer()\n {\n");
1406 while (Offset < AmlFileSize)
1408 /* Read enough bytes needed for one output line */
1410 LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1411 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1417 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1419 for (i = 0; i < LineLength; i++)
1422 * Print each hex byte.
1423 * Add a comma until the very last byte of the AML file
1424 * (Some C compilers complain about a trailing comma)
1426 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0x%2.2X", FileData[i]);
1427 if ((Offset + i + 1) < AmlFileSize)
1429 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1433 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1437 /* Add fill spaces if needed for last line */
1439 if (LineLength < HEX_TABLE_LINE_SIZE)
1441 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1442 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1445 /* Emit the offset and ascii dump for the entire line */
1447 FlPrintFile (ASL_FILE_HEX_OUTPUT, " /* %8.8X", Offset);
1448 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1449 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s*/\n",
1450 HEX_TABLE_LINE_SIZE - LineLength + 1, " ");
1452 Offset += LineLength;
1455 FlPrintFile (ASL_FILE_HEX_OUTPUT, " })\n");
1456 FlCloseFile (ASL_FILE_HEX_OUTPUT);
1460 /*******************************************************************************
1462 * FUNCTION: LsDoHexOutputAsm
1468 * DESCRIPTION: Create the hex output file. This is the same data as the AML
1469 * output file, but formatted into hex/ascii bytes suitable for
1470 * inclusion into a ASM source file.
1472 ******************************************************************************/
1478 UINT8 FileData[HEX_TABLE_LINE_SIZE];
1485 /* Get AML size, seek back to start */
1487 AmlFileSize = FlGetFileSize (ASL_FILE_AML_OUTPUT);
1489 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; Assembly code source output\n");
1490 FlPrintFile (ASL_FILE_HEX_OUTPUT, "; AML code block contains 0x%X bytes\n;\n",
1493 while (Offset < AmlFileSize)
1495 /* Read enough bytes needed for one output line */
1497 LineLength = fread (FileData, 1, HEX_TABLE_LINE_SIZE,
1498 Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
1504 FlPrintFile (ASL_FILE_HEX_OUTPUT, " db ");
1506 for (i = 0; i < LineLength; i++)
1509 * Print each hex byte.
1510 * Add a comma until the last byte of the line
1512 FlPrintFile (ASL_FILE_HEX_OUTPUT, "0%2.2Xh", FileData[i]);
1513 if ((i + 1) < LineLength)
1515 FlPrintFile (ASL_FILE_HEX_OUTPUT, ",");
1519 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ");
1521 /* Add fill spaces if needed for last line */
1523 if (LineLength < HEX_TABLE_LINE_SIZE)
1525 FlPrintFile (ASL_FILE_HEX_OUTPUT, "%*s",
1526 5 * (HEX_TABLE_LINE_SIZE - LineLength), " ");
1529 /* Emit the offset and ascii dump for the entire line */
1531 FlPrintFile (ASL_FILE_HEX_OUTPUT, " ; %8.8X", Offset);
1532 LsDumpAsciiInComment (ASL_FILE_HEX_OUTPUT, LineLength, FileData);
1533 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1535 Offset += LineLength;
1538 FlPrintFile (ASL_FILE_HEX_OUTPUT, "\n");
1539 FlCloseFile (ASL_FILE_HEX_OUTPUT);