Sync ACPICA with Intel's version 20180508 (from previously 20170831).
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / dtio.c
blob0ba15b421a2b3f26c83e386e08fb73634b223b10
1 /******************************************************************************
3 * Module Name: dtio.c - File I/O support for data table compiler
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "aslcompiler.h"
153 #include "acapps.h"
155 #define _COMPONENT DT_COMPILER
156 ACPI_MODULE_NAME ("dtio")
159 /* Local prototypes */
161 static char *
162 DtTrim (
163 char *String);
165 static void
166 DtLinkField (
167 DT_FIELD *Field);
169 static ACPI_STATUS
170 DtParseLine (
171 char *LineBuffer,
172 UINT32 Line,
173 UINT32 Offset);
175 static void
176 DtWriteBinary (
177 DT_SUBTABLE *Subtable,
178 void *Context,
179 void *ReturnValue);
181 static void
182 DtDumpBuffer (
183 UINT32 FileId,
184 UINT8 *Buffer,
185 UINT32 Offset,
186 UINT32 Length);
188 static void
189 DtDumpSubtableInfo (
190 DT_SUBTABLE *Subtable,
191 void *Context,
192 void *ReturnValue);
194 static void
195 DtDumpSubtableTree (
196 DT_SUBTABLE *Subtable,
197 void *Context,
198 void *ReturnValue);
201 /* States for DtGetNextLine */
203 #define DT_NORMAL_TEXT 0
204 #define DT_START_QUOTED_STRING 1
205 #define DT_START_COMMENT 2
206 #define DT_SLASH_ASTERISK_COMMENT 3
207 #define DT_SLASH_SLASH_COMMENT 4
208 #define DT_END_COMMENT 5
209 #define DT_MERGE_LINES 6
210 #define DT_ESCAPE_SEQUENCE 7
212 static UINT32 Gbl_NextLineOffset;
215 /******************************************************************************
217 * FUNCTION: DtTrim
219 * PARAMETERS: String - Current source code line to trim
221 * RETURN: Trimmed line. Must be freed by caller.
223 * DESCRIPTION: Trim left and right spaces
225 *****************************************************************************/
227 static char *
228 DtTrim (
229 char *String)
231 char *Start;
232 char *End;
233 char *ReturnString;
234 ACPI_SIZE Length;
237 /* Skip lines that start with a space */
239 if (!strcmp (String, " "))
241 ReturnString = UtLocalCacheCalloc (1);
242 return (ReturnString);
245 /* Setup pointers to start and end of input string */
247 Start = String;
248 End = String + strlen (String) - 1;
250 /* Find first non-whitespace character */
252 while ((Start <= End) && ((*Start == ' ') || (*Start == '\t')))
254 Start++;
257 /* Find last non-space character */
259 while (End >= Start)
261 if (*End == '\r' || *End == '\n')
263 End--;
264 continue;
267 if (*End != ' ')
269 break;
272 End--;
275 /* Remove any quotes around the string */
277 if (*Start == '\"')
279 Start++;
281 if (*End == '\"')
283 End--;
286 /* Create the trimmed return string */
288 Length = ACPI_PTR_DIFF (End, Start) + 1;
289 ReturnString = UtLocalCacheCalloc (Length + 1);
290 if (strlen (Start))
292 strncpy (ReturnString, Start, Length);
295 ReturnString[Length] = 0;
296 return (ReturnString);
300 /******************************************************************************
302 * FUNCTION: DtLinkField
304 * PARAMETERS: Field - New field object to link
306 * RETURN: None
308 * DESCRIPTION: Link one field name and value to the list
310 *****************************************************************************/
312 static void
313 DtLinkField (
314 DT_FIELD *Field)
316 DT_FIELD *Prev;
317 DT_FIELD *Next;
320 Prev = Next = Gbl_FieldList;
322 while (Next)
324 Prev = Next;
325 Next = Next->Next;
328 if (Prev)
330 Prev->Next = Field;
332 else
334 Gbl_FieldList = Field;
339 /******************************************************************************
341 * FUNCTION: DtParseLine
343 * PARAMETERS: LineBuffer - Current source code line
344 * Line - Current line number in the source
345 * Offset - Current byte offset of the line
347 * RETURN: Status
349 * DESCRIPTION: Parse one source line
351 *****************************************************************************/
353 static ACPI_STATUS
354 DtParseLine (
355 char *LineBuffer,
356 UINT32 Line,
357 UINT32 Offset)
359 char *Start;
360 char *End;
361 char *TmpName;
362 char *TmpValue;
363 char *Name;
364 char *Value;
365 char *Colon;
366 UINT32 Length;
367 DT_FIELD *Field;
368 UINT32 Column;
369 UINT32 NameColumn;
370 BOOLEAN IsNullString = FALSE;
373 if (!LineBuffer)
375 return (AE_OK);
378 /* All lines after "Raw Table Data" are ingored */
380 if (strstr (LineBuffer, ACPI_RAW_TABLE_DATA_HEADER))
382 return (AE_NOT_FOUND);
385 Colon = strchr (LineBuffer, ':');
386 if (!Colon)
388 return (AE_OK);
391 Start = LineBuffer;
392 End = Colon;
394 while (Start < Colon)
396 if (*Start == '[')
398 /* Found left bracket, go to the right bracket */
400 while (Start < Colon && *Start != ']')
402 Start++;
405 else if (*Start != ' ')
407 break;
410 Start++;
414 * There are two column values. One for the field name,
415 * and one for the field value.
417 Column = ACPI_PTR_DIFF (Colon, LineBuffer) + 3;
418 NameColumn = ACPI_PTR_DIFF (Start, LineBuffer) + 1;
420 Length = ACPI_PTR_DIFF (End, Start);
422 TmpName = UtLocalCalloc (Length + 1);
423 strncpy (TmpName, Start, Length);
424 Name = DtTrim (TmpName);
425 ACPI_FREE (TmpName);
427 Start = End = (Colon + 1);
428 while (*End)
430 /* Found left quotation, go to the right quotation and break */
432 if (*End == '"')
434 End++;
436 /* Check for an explicit null string */
438 if (*End == '"')
440 IsNullString = TRUE;
442 while (*End && (*End != '"'))
444 End++;
447 End++;
448 break;
452 * Special "comment" fields at line end, ignore them.
453 * Note: normal slash-slash and slash-asterisk comments are
454 * stripped already by the DtGetNextLine parser.
456 * TBD: Perhaps DtGetNextLine should parse the following type
457 * of comments also.
459 if (*End == '[')
461 End--;
462 break;
465 End++;
468 Length = ACPI_PTR_DIFF (End, Start);
469 TmpValue = UtLocalCalloc (Length + 1);
471 strncpy (TmpValue, Start, Length);
472 Value = DtTrim (TmpValue);
473 ACPI_FREE (TmpValue);
475 /* Create a new field object only if we have a valid value field */
477 if ((Value && *Value) || IsNullString)
479 Field = UtFieldCacheCalloc ();
480 Field->Name = Name;
481 Field->Value = Value;
482 Field->Line = Line;
483 Field->ByteOffset = Offset;
484 Field->NameColumn = NameColumn;
485 Field->Column = Column;
486 Field->StringLength = Length;
488 DtLinkField (Field);
490 /* Else -- Ignore this field, it has no valid data */
492 return (AE_OK);
496 /******************************************************************************
498 * FUNCTION: DtGetNextLine
500 * PARAMETERS: Handle - Open file handle for the source file
502 * RETURN: Filled line buffer and offset of start-of-line (ASL_EOF on EOF)
504 * DESCRIPTION: Get the next valid source line. Removes all comments.
505 * Ignores empty lines.
507 * Handles both slash-asterisk and slash-slash comments.
508 * Also, quoted strings, but no escapes within.
510 * Line is returned in Gbl_CurrentLineBuffer.
511 * Line number in original file is returned in Gbl_CurrentLineNumber.
513 *****************************************************************************/
515 UINT32
516 DtGetNextLine (
517 FILE *Handle,
518 UINT32 Flags)
520 BOOLEAN LineNotAllBlanks = FALSE;
521 UINT32 State = DT_NORMAL_TEXT;
522 UINT32 CurrentLineOffset;
523 UINT32 i;
524 int c;
527 memset (Gbl_CurrentLineBuffer, 0, Gbl_LineBufferSize);
528 for (i = 0; ;)
531 * If line is too long, expand the line buffers. Also increases
532 * Gbl_LineBufferSize.
534 if (i >= Gbl_LineBufferSize)
536 UtExpandLineBuffers ();
539 c = getc (Handle);
540 if (c == EOF)
542 switch (State)
544 case DT_START_QUOTED_STRING:
545 case DT_SLASH_ASTERISK_COMMENT:
547 AcpiOsPrintf ("**** EOF within comment/string %u\n", State);
548 break;
550 default:
552 break;
555 /* Standalone EOF is OK */
557 if (i == 0)
559 return (ASL_EOF);
563 * Received an EOF in the middle of a line. Terminate the
564 * line with a newline. The next call to this function will
565 * return a standalone EOF. Thus, the upper parsing software
566 * never has to deal with an EOF within a valid line (or
567 * the last line does not get tossed on the floor.)
569 c = '\n';
570 State = DT_NORMAL_TEXT;
573 switch (State)
575 case DT_NORMAL_TEXT:
577 /* Normal text, insert char into line buffer */
579 Gbl_CurrentLineBuffer[i] = (char) c;
580 switch (c)
582 case '/':
584 State = DT_START_COMMENT;
585 break;
587 case '"':
589 State = DT_START_QUOTED_STRING;
590 LineNotAllBlanks = TRUE;
591 i++;
592 break;
594 case '\\':
596 * The continuation char MUST be last char on this line.
597 * Otherwise, it will be assumed to be a valid ASL char.
599 State = DT_MERGE_LINES;
600 break;
602 case '\n':
604 CurrentLineOffset = Gbl_NextLineOffset;
605 Gbl_NextLineOffset = (UINT32) ftell (Handle);
606 Gbl_CurrentLineNumber++;
609 * Exit if line is complete. Ignore empty lines (only \n)
610 * or lines that contain nothing but blanks.
612 if ((i != 0) && LineNotAllBlanks)
614 if ((i + 1) >= Gbl_LineBufferSize)
616 UtExpandLineBuffers ();
619 Gbl_CurrentLineBuffer[i+1] = 0; /* Terminate string */
620 return (CurrentLineOffset);
623 /* Toss this line and start a new one */
625 i = 0;
626 LineNotAllBlanks = FALSE;
627 break;
629 default:
631 if (c != ' ')
633 LineNotAllBlanks = TRUE;
636 i++;
637 break;
639 break;
641 case DT_START_QUOTED_STRING:
643 /* Insert raw chars until end of quoted string */
645 Gbl_CurrentLineBuffer[i] = (char) c;
646 i++;
648 switch (c)
650 case '"':
652 State = DT_NORMAL_TEXT;
653 break;
655 case '\\':
657 State = DT_ESCAPE_SEQUENCE;
658 break;
660 case '\n':
662 if (!(Flags & DT_ALLOW_MULTILINE_QUOTES))
664 AcpiOsPrintf (
665 "ERROR at line %u: Unterminated quoted string\n",
666 Gbl_CurrentLineNumber++);
667 State = DT_NORMAL_TEXT;
669 break;
671 default: /* Get next character */
673 break;
675 break;
677 case DT_ESCAPE_SEQUENCE:
679 /* Just copy the escaped character. TBD: sufficient for table compiler? */
681 Gbl_CurrentLineBuffer[i] = (char) c;
682 i++;
683 State = DT_START_QUOTED_STRING;
684 break;
686 case DT_START_COMMENT:
688 /* Open comment if this character is an asterisk or slash */
690 switch (c)
692 case '*':
694 State = DT_SLASH_ASTERISK_COMMENT;
695 break;
697 case '/':
699 State = DT_SLASH_SLASH_COMMENT;
700 break;
702 default: /* Not a comment */
704 i++; /* Save the preceding slash */
705 if (i >= Gbl_LineBufferSize)
707 UtExpandLineBuffers ();
710 Gbl_CurrentLineBuffer[i] = (char) c;
711 i++;
712 State = DT_NORMAL_TEXT;
713 break;
715 break;
717 case DT_SLASH_ASTERISK_COMMENT:
719 /* Ignore chars until an asterisk-slash is found */
721 switch (c)
723 case '\n':
725 Gbl_NextLineOffset = (UINT32) ftell (Handle);
726 Gbl_CurrentLineNumber++;
727 break;
729 case '*':
731 State = DT_END_COMMENT;
732 break;
734 default:
736 break;
738 break;
740 case DT_SLASH_SLASH_COMMENT:
742 /* Ignore chars until end-of-line */
744 if (c == '\n')
746 /* We will exit via the NORMAL_TEXT path */
748 ungetc (c, Handle);
749 State = DT_NORMAL_TEXT;
751 break;
753 case DT_END_COMMENT:
755 /* End comment if this char is a slash */
757 switch (c)
759 case '/':
761 State = DT_NORMAL_TEXT;
762 break;
764 case '\n':
766 CurrentLineOffset = Gbl_NextLineOffset;
767 Gbl_NextLineOffset = (UINT32) ftell (Handle);
768 Gbl_CurrentLineNumber++;
769 break;
771 case '*':
773 /* Consume all adjacent asterisks */
774 break;
776 default:
778 State = DT_SLASH_ASTERISK_COMMENT;
779 break;
781 break;
783 case DT_MERGE_LINES:
785 if (c != '\n')
788 * This is not a continuation backslash, it is a normal
789 * normal ASL backslash - for example: Scope(\_SB_)
791 i++; /* Keep the backslash that is already in the buffer */
793 ungetc (c, Handle);
794 State = DT_NORMAL_TEXT;
796 else
799 * This is a continuation line -- a backlash followed
800 * immediately by a newline. Insert a space between the
801 * lines (overwrite the backslash)
803 Gbl_CurrentLineBuffer[i] = ' ';
804 i++;
806 /* Ignore newline, this will merge the lines */
808 CurrentLineOffset = Gbl_NextLineOffset;
809 Gbl_NextLineOffset = (UINT32) ftell (Handle);
810 Gbl_CurrentLineNumber++;
811 State = DT_NORMAL_TEXT;
813 break;
815 default:
817 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, "Unknown input state");
818 return (ASL_EOF);
824 /******************************************************************************
826 * FUNCTION: DtScanFile
828 * PARAMETERS: Handle - Open file handle for the source file
830 * RETURN: Pointer to start of the constructed parse tree.
832 * DESCRIPTION: Scan source file, link all field names and values
833 * to the global parse tree: Gbl_FieldList
835 *****************************************************************************/
837 DT_FIELD *
838 DtScanFile (
839 FILE *Handle)
841 ACPI_STATUS Status;
842 UINT32 Offset;
845 ACPI_FUNCTION_NAME (DtScanFile);
848 /* Get the file size */
850 Gbl_InputByteCount = CmGetFileSize (Handle);
851 if (Gbl_InputByteCount == ACPI_UINT32_MAX)
853 AslAbort ();
856 Gbl_CurrentLineNumber = 0;
857 Gbl_CurrentLineOffset = 0;
858 Gbl_NextLineOffset = 0;
860 /* Scan line-by-line */
862 while ((Offset = DtGetNextLine (Handle, 0)) != ASL_EOF)
864 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s",
865 Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer));
867 Status = DtParseLine (Gbl_CurrentLineBuffer,
868 Gbl_CurrentLineNumber, Offset);
869 if (Status == AE_NOT_FOUND)
871 break;
875 /* Dump the parse tree if debug enabled */
877 DtDumpFieldList (Gbl_FieldList);
878 return (Gbl_FieldList);
883 * Output functions
886 /******************************************************************************
888 * FUNCTION: DtWriteBinary
890 * PARAMETERS: DT_WALK_CALLBACK
892 * RETURN: Status
894 * DESCRIPTION: Write one subtable of a binary ACPI table
896 *****************************************************************************/
898 static void
899 DtWriteBinary (
900 DT_SUBTABLE *Subtable,
901 void *Context,
902 void *ReturnValue)
905 FlWriteFile (ASL_FILE_AML_OUTPUT, Subtable->Buffer, Subtable->Length);
909 /******************************************************************************
911 * FUNCTION: DtOutputBinary
913 * PARAMETERS:
915 * RETURN: Status
917 * DESCRIPTION: Write entire binary ACPI table (result of compilation)
919 *****************************************************************************/
921 void
922 DtOutputBinary (
923 DT_SUBTABLE *RootTable)
926 if (!RootTable)
928 return;
931 /* Walk the entire parse tree, emitting the binary data */
933 DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL);
935 Gbl_TableLength = CmGetFileSize (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
936 if (Gbl_TableLength == ACPI_UINT32_MAX)
938 AslAbort ();
944 * Listing support
947 /******************************************************************************
949 * FUNCTION: DtDumpBuffer
951 * PARAMETERS: FileID - Where to write buffer data
952 * Buffer - Buffer to dump
953 * Offset - Offset in current table
954 * Length - Buffer Length
956 * RETURN: None
958 * DESCRIPTION: Another copy of DumpBuffer routine (unfortunately).
960 * TBD: merge dump buffer routines
962 *****************************************************************************/
964 static void
965 DtDumpBuffer (
966 UINT32 FileId,
967 UINT8 *Buffer,
968 UINT32 Offset,
969 UINT32 Length)
971 UINT32 i;
972 UINT32 j;
973 UINT8 BufChar;
976 FlPrintFile (FileId, "Output: [%3.3Xh %4.4d %3d] ",
977 Offset, Offset, Length);
979 i = 0;
980 while (i < Length)
982 if (i >= 16)
984 FlPrintFile (FileId, "%24s", "");
987 /* Print 16 hex chars */
989 for (j = 0; j < 16;)
991 if (i + j >= Length)
993 /* Dump fill spaces */
995 FlPrintFile (FileId, " ");
996 j++;
997 continue;
1000 FlPrintFile (FileId, "%02X ", Buffer[i+j]);
1001 j++;
1004 FlPrintFile (FileId, " ");
1005 for (j = 0; j < 16; j++)
1007 if (i + j >= Length)
1009 FlPrintFile (FileId, "\n\n");
1010 return;
1013 BufChar = Buffer[(ACPI_SIZE) i + j];
1014 if (isprint (BufChar))
1016 FlPrintFile (FileId, "%c", BufChar);
1018 else
1020 FlPrintFile (FileId, ".");
1024 /* Done with that line. */
1026 FlPrintFile (FileId, "\n");
1027 i += 16;
1030 FlPrintFile (FileId, "\n\n");
1034 /******************************************************************************
1036 * FUNCTION: DtDumpFieldList
1038 * PARAMETERS: Field - Root field
1040 * RETURN: None
1042 * DESCRIPTION: Dump the entire field list
1044 *****************************************************************************/
1046 void
1047 DtDumpFieldList (
1048 DT_FIELD *Field)
1051 if (!Gbl_DebugFlag || !Field)
1053 return;
1056 DbgPrint (ASL_DEBUG_OUTPUT, "\nField List:\n"
1057 "LineNo ByteOff NameCol Column TableOff "
1058 "Flags %32s : %s\n\n", "Name", "Value");
1060 while (Field)
1062 DbgPrint (ASL_DEBUG_OUTPUT,
1063 "%.08X %.08X %.08X %.08X %.08X %2.2X %32s : %s\n",
1064 Field->Line, Field->ByteOffset, Field->NameColumn,
1065 Field->Column, Field->TableOffset, Field->Flags,
1066 Field->Name, Field->Value);
1068 Field = Field->Next;
1071 DbgPrint (ASL_DEBUG_OUTPUT, "\n\n");
1075 /******************************************************************************
1077 * FUNCTION: DtDumpSubtableInfo, DtDumpSubtableTree
1079 * PARAMETERS: DT_WALK_CALLBACK
1081 * RETURN: None
1083 * DESCRIPTION: Info - dump a subtable tree entry with extra information.
1084 * Tree - dump a subtable tree formatted by depth indentation.
1086 *****************************************************************************/
1088 static void
1089 DtDumpSubtableInfo (
1090 DT_SUBTABLE *Subtable,
1091 void *Context,
1092 void *ReturnValue)
1095 DbgPrint (ASL_DEBUG_OUTPUT,
1096 "[%.04X] %24s %.08X %.08X %.08X %.08X %.08X %p %p %p\n",
1097 Subtable->Depth, Subtable->Name, Subtable->Length, Subtable->TotalLength,
1098 Subtable->SizeOfLengthField, Subtable->Flags, Subtable,
1099 Subtable->Parent, Subtable->Child, Subtable->Peer);
1102 static void
1103 DtDumpSubtableTree (
1104 DT_SUBTABLE *Subtable,
1105 void *Context,
1106 void *ReturnValue)
1109 DbgPrint (ASL_DEBUG_OUTPUT,
1110 "[%.04X] %24s %*s%08X (%.02X) - (%.02X)\n",
1111 Subtable->Depth, Subtable->Name, (4 * Subtable->Depth), " ",
1112 Subtable, Subtable->Length, Subtable->TotalLength);
1116 /******************************************************************************
1118 * FUNCTION: DtDumpSubtableList
1120 * PARAMETERS: None
1122 * RETURN: None
1124 * DESCRIPTION: Dump the raw list of subtables with information, and also
1125 * dump the subtable list in formatted tree format. Assists with
1126 * the development of new table code.
1128 *****************************************************************************/
1130 void
1131 DtDumpSubtableList (
1132 void)
1135 if (!Gbl_DebugFlag || !Gbl_RootTable)
1137 return;
1140 DbgPrint (ASL_DEBUG_OUTPUT,
1141 "Subtable Info:\n"
1142 "Depth Name Length TotalLen LenSize Flags "
1143 "This Parent Child Peer\n\n");
1144 DtWalkTableTree (Gbl_RootTable, DtDumpSubtableInfo, NULL, NULL);
1146 DbgPrint (ASL_DEBUG_OUTPUT,
1147 "\nSubtable Tree: (Depth, Name, Subtable, Length, TotalLength)\n\n");
1148 DtWalkTableTree (Gbl_RootTable, DtDumpSubtableTree, NULL, NULL);
1150 DbgPrint (ASL_DEBUG_OUTPUT, "\n");
1154 /******************************************************************************
1156 * FUNCTION: DtWriteFieldToListing
1158 * PARAMETERS: Buffer - Contains the compiled data
1159 * Field - Field node for the input line
1160 * Length - Length of the output data
1162 * RETURN: None
1164 * DESCRIPTION: Write one field to the listing file (if listing is enabled).
1166 *****************************************************************************/
1168 void
1169 DtWriteFieldToListing (
1170 UINT8 *Buffer,
1171 DT_FIELD *Field,
1172 UINT32 Length)
1174 UINT8 FileByte;
1177 if (!Gbl_ListingFlag || !Field)
1179 return;
1182 /* Dump the original source line */
1184 FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Input: ");
1185 FlSeekFile (ASL_FILE_INPUT, Field->ByteOffset);
1187 while (FlReadFile (ASL_FILE_INPUT, &FileByte, 1) == AE_OK)
1189 FlWriteFile (ASL_FILE_LISTING_OUTPUT, &FileByte, 1);
1190 if (FileByte == '\n')
1192 break;
1196 /* Dump the line as parsed and represented internally */
1198 FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Parsed: %*s : %.64s",
1199 Field->Column-4, Field->Name, Field->Value);
1201 if (strlen (Field->Value) > 64)
1203 FlPrintFile (ASL_FILE_LISTING_OUTPUT, "...Additional data, length 0x%X\n",
1204 strlen (Field->Value));
1207 FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n");
1209 /* Dump the hex data that will be output for this field */
1211 DtDumpBuffer (ASL_FILE_LISTING_OUTPUT, Buffer, Field->TableOffset, Length);
1215 /******************************************************************************
1217 * FUNCTION: DtWriteTableToListing
1219 * PARAMETERS: None
1221 * RETURN: None
1223 * DESCRIPTION: Write the entire compiled table to the listing file
1224 * in hex format
1226 *****************************************************************************/
1228 void
1229 DtWriteTableToListing (
1230 void)
1232 UINT8 *Buffer;
1235 if (!Gbl_ListingFlag)
1237 return;
1240 /* Read the entire table from the output file */
1242 Buffer = UtLocalCalloc (Gbl_TableLength);
1243 FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1244 FlReadFile (ASL_FILE_AML_OUTPUT, Buffer, Gbl_TableLength);
1246 /* Dump the raw table data */
1248 AcpiOsRedirectOutput (Gbl_Files[ASL_FILE_LISTING_OUTPUT].Handle);
1250 AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n",
1251 ACPI_RAW_TABLE_DATA_HEADER, Gbl_TableLength, Gbl_TableLength);
1252 AcpiUtDumpBuffer (Buffer, Gbl_TableLength, DB_BYTE_DISPLAY, 0);
1254 AcpiOsRedirectOutput (stdout);
1255 ACPI_FREE (Buffer);