Sync ACPICA with Intel's version 20150515.
[dragonfly.git] / sys / contrib / dev / acpica / source / compiler / dtio.c
1 /******************************************************************************
2  *
3  * Module Name: dtio.c - File I/O support for data table compiler
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include "aslcompiler.h"
45 #include "dtcompiler.h"
46 #include "acapps.h"
47
48 #define _COMPONENT          DT_COMPILER
49         ACPI_MODULE_NAME    ("dtio")
50
51
52 /* Local prototypes */
53
54 static char *
55 DtTrim (
56     char                    *String);
57
58 static void
59 DtLinkField (
60     DT_FIELD                *Field);
61
62 static ACPI_STATUS
63 DtParseLine (
64     char                    *LineBuffer,
65     UINT32                  Line,
66     UINT32                  Offset);
67
68 static void
69 DtWriteBinary (
70     DT_SUBTABLE             *Subtable,
71     void                    *Context,
72     void                    *ReturnValue);
73
74 static void
75 DtDumpBuffer (
76     UINT32                  FileId,
77     UINT8                   *Buffer,
78     UINT32                  Offset,
79     UINT32                  Length);
80
81 static void
82 DtDumpSubtableInfo (
83     DT_SUBTABLE             *Subtable,
84     void                    *Context,
85     void                    *ReturnValue);
86
87 static void
88 DtDumpSubtableTree (
89     DT_SUBTABLE             *Subtable,
90     void                    *Context,
91     void                    *ReturnValue);
92
93
94 /* States for DtGetNextLine */
95
96 #define DT_NORMAL_TEXT              0
97 #define DT_START_QUOTED_STRING      1
98 #define DT_START_COMMENT            2
99 #define DT_SLASH_ASTERISK_COMMENT   3
100 #define DT_SLASH_SLASH_COMMENT      4
101 #define DT_END_COMMENT              5
102 #define DT_MERGE_LINES              6
103 #define DT_ESCAPE_SEQUENCE          7
104
105 static UINT32  Gbl_NextLineOffset;
106
107
108 /******************************************************************************
109  *
110  * FUNCTION:    DtTrim
111  *
112  * PARAMETERS:  String              - Current source code line to trim
113  *
114  * RETURN:      Trimmed line. Must be freed by caller.
115  *
116  * DESCRIPTION: Trim left and right spaces
117  *
118  *****************************************************************************/
119
120 static char *
121 DtTrim (
122     char                    *String)
123 {
124     char                    *Start;
125     char                    *End;
126     char                    *ReturnString;
127     ACPI_SIZE               Length;
128
129
130     /* Skip lines that start with a space */
131
132     if (!ACPI_STRCMP (String, " "))
133     {
134         ReturnString = UtStringCacheCalloc (1);
135         return (ReturnString);
136     }
137
138     /* Setup pointers to start and end of input string */
139
140     Start = String;
141     End = String + ACPI_STRLEN (String) - 1;
142
143     /* Find first non-whitespace character */
144
145     while ((Start <= End) && ((*Start == ' ') || (*Start == '\t')))
146     {
147         Start++;
148     }
149
150     /* Find last non-space character */
151
152     while (End >= Start)
153     {
154         if (*End == '\r' || *End == '\n')
155         {
156             End--;
157             continue;
158         }
159
160         if (*End != ' ')
161         {
162             break;
163         }
164
165         End--;
166     }
167
168     /* Remove any quotes around the string */
169
170     if (*Start == '\"')
171     {
172         Start++;
173     }
174     if (*End == '\"')
175     {
176         End--;
177     }
178
179     /* Create the trimmed return string */
180
181     Length = ACPI_PTR_DIFF (End, Start) + 1;
182     ReturnString = UtStringCacheCalloc (Length + 1);
183     if (ACPI_STRLEN (Start))
184     {
185         ACPI_STRNCPY (ReturnString, Start, Length);
186     }
187
188     ReturnString[Length] = 0;
189     return (ReturnString);
190 }
191
192
193 /******************************************************************************
194  *
195  * FUNCTION:    DtLinkField
196  *
197  * PARAMETERS:  Field               - New field object to link
198  *
199  * RETURN:      None
200  *
201  * DESCRIPTION: Link one field name and value to the list
202  *
203  *****************************************************************************/
204
205 static void
206 DtLinkField (
207     DT_FIELD                *Field)
208 {
209     DT_FIELD                *Prev;
210     DT_FIELD                *Next;
211
212
213     Prev = Next = Gbl_FieldList;
214
215     while (Next)
216     {
217         Prev = Next;
218         Next = Next->Next;
219     }
220
221     if (Prev)
222     {
223         Prev->Next = Field;
224     }
225     else
226     {
227         Gbl_FieldList = Field;
228     }
229 }
230
231
232 /******************************************************************************
233  *
234  * FUNCTION:    DtParseLine
235  *
236  * PARAMETERS:  LineBuffer          - Current source code line
237  *              Line                - Current line number in the source
238  *              Offset              - Current byte offset of the line
239  *
240  * RETURN:      Status
241  *
242  * DESCRIPTION: Parse one source line
243  *
244  *****************************************************************************/
245
246 static ACPI_STATUS
247 DtParseLine (
248     char                    *LineBuffer,
249     UINT32                  Line,
250     UINT32                  Offset)
251 {
252     char                    *Start;
253     char                    *End;
254     char                    *TmpName;
255     char                    *TmpValue;
256     char                    *Name;
257     char                    *Value;
258     char                    *Colon;
259     UINT32                  Length;
260     DT_FIELD                *Field;
261     UINT32                  Column;
262     UINT32                  NameColumn;
263     BOOLEAN                 IsNullString = FALSE;
264
265
266     if (!LineBuffer)
267     {
268         return (AE_OK);
269     }
270
271     /* All lines after "Raw Table Data" are ingored */
272
273     if (strstr (LineBuffer, ACPI_RAW_TABLE_DATA_HEADER))
274     {
275         return (AE_NOT_FOUND);
276     }
277
278     Colon = strchr (LineBuffer, ':');
279     if (!Colon)
280     {
281         return (AE_OK);
282     }
283
284     Start = LineBuffer;
285     End = Colon;
286
287     while (Start < Colon)
288     {
289         if (*Start == '[')
290         {
291             /* Found left bracket, go to the right bracket */
292
293             while (Start < Colon && *Start != ']')
294             {
295                 Start++;
296             }
297         }
298         else if (*Start != ' ')
299         {
300             break;
301         }
302
303         Start++;
304     }
305
306     /*
307      * There are two column values. One for the field name,
308      * and one for the field value.
309      */
310     Column = ACPI_PTR_DIFF (Colon, LineBuffer) + 3;
311     NameColumn = ACPI_PTR_DIFF (Start, LineBuffer) + 1;
312
313     Length = ACPI_PTR_DIFF (End, Start);
314
315     TmpName = UtLocalCalloc (Length + 1);
316     ACPI_STRNCPY (TmpName, Start, Length);
317     Name = DtTrim (TmpName);
318     ACPI_FREE (TmpName);
319
320     Start = End = (Colon + 1);
321     while (*End)
322     {
323         /* Found left quotation, go to the right quotation and break */
324
325         if (*End == '"')
326         {
327             End++;
328
329             /* Check for an explicit null string */
330
331             if (*End == '"')
332             {
333                 IsNullString = TRUE;
334             }
335             while (*End && (*End != '"'))
336             {
337                 End++;
338             }
339
340             End++;
341             break;
342         }
343
344         /*
345          * Special "comment" fields at line end, ignore them.
346          * Note: normal slash-slash and slash-asterisk comments are
347          * stripped already by the DtGetNextLine parser.
348          *
349          * TBD: Perhaps DtGetNextLine should parse the following type
350          * of comments also.
351          */
352         if (*End == '[')
353         {
354             End--;
355             break;
356         }
357         End++;
358     }
359
360     Length = ACPI_PTR_DIFF (End, Start);
361     TmpValue = UtLocalCalloc (Length + 1);
362
363     ACPI_STRNCPY (TmpValue, Start, Length);
364     Value = DtTrim (TmpValue);
365     ACPI_FREE (TmpValue);
366
367     /* Create a new field object only if we have a valid value field */
368
369     if ((Value && *Value) || IsNullString)
370     {
371         Field = UtFieldCacheCalloc ();
372         Field->Name = Name;
373         Field->Value = Value;
374         Field->Line = Line;
375         Field->ByteOffset = Offset;
376         Field->NameColumn = NameColumn;
377         Field->Column = Column;
378         Field->StringLength = Length;
379
380         DtLinkField (Field);
381     }
382     /* Else -- Ignore this field, it has no valid data */
383
384     return (AE_OK);
385 }
386
387
388 /******************************************************************************
389  *
390  * FUNCTION:    DtGetNextLine
391  *
392  * PARAMETERS:  Handle              - Open file handle for the source file
393  *
394  * RETURN:      Filled line buffer and offset of start-of-line (ASL_EOF on EOF)
395  *
396  * DESCRIPTION: Get the next valid source line. Removes all comments.
397  *              Ignores empty lines.
398  *
399  * Handles both slash-asterisk and slash-slash comments.
400  * Also, quoted strings, but no escapes within.
401  *
402  * Line is returned in Gbl_CurrentLineBuffer.
403  * Line number in original file is returned in Gbl_CurrentLineNumber.
404  *
405  *****************************************************************************/
406
407 UINT32
408 DtGetNextLine (
409     FILE                    *Handle)
410 {
411     BOOLEAN                 LineNotAllBlanks = FALSE;
412     UINT32                  State = DT_NORMAL_TEXT;
413     UINT32                  CurrentLineOffset;
414     UINT32                  i;
415     int                     c;
416
417
418     ACPI_MEMSET (Gbl_CurrentLineBuffer, 0, Gbl_LineBufferSize);
419     for (i = 0; ;)
420     {
421         /*
422          * If line is too long, expand the line buffers. Also increases
423          * Gbl_LineBufferSize.
424          */
425         if (i >= Gbl_LineBufferSize)
426         {
427             UtExpandLineBuffers ();
428         }
429
430         c = getc (Handle);
431         if (c == EOF)
432         {
433             switch (State)
434             {
435             case DT_START_QUOTED_STRING:
436             case DT_SLASH_ASTERISK_COMMENT:
437
438                 AcpiOsPrintf ("**** EOF within comment/string %u\n", State);
439                 break;
440
441             default:
442
443                 break;
444             }
445
446             /* Standalone EOF is OK */
447
448             if (i == 0)
449             {
450                 return (ASL_EOF);
451             }
452
453             /*
454              * Received an EOF in the middle of a line. Terminate the
455              * line with a newline. The next call to this function will
456              * return a standalone EOF. Thus, the upper parsing software
457              * never has to deal with an EOF within a valid line (or
458              * the last line does not get tossed on the floor.)
459              */
460             c = '\n';
461             State = DT_NORMAL_TEXT;
462         }
463
464         switch (State)
465         {
466         case DT_NORMAL_TEXT:
467
468             /* Normal text, insert char into line buffer */
469
470             Gbl_CurrentLineBuffer[i] = (char) c;
471             switch (c)
472             {
473             case '/':
474
475                 State = DT_START_COMMENT;
476                 break;
477
478             case '"':
479
480                 State = DT_START_QUOTED_STRING;
481                 LineNotAllBlanks = TRUE;
482                 i++;
483                 break;
484
485             case '\\':
486                 /*
487                  * The continuation char MUST be last char on this line.
488                  * Otherwise, it will be assumed to be a valid ASL char.
489                  */
490                 State = DT_MERGE_LINES;
491                 break;
492
493             case '\n':
494
495                 CurrentLineOffset = Gbl_NextLineOffset;
496                 Gbl_NextLineOffset = (UINT32) ftell (Handle);
497                 Gbl_CurrentLineNumber++;
498
499                 /*
500                  * Exit if line is complete. Ignore empty lines (only \n)
501                  * or lines that contain nothing but blanks.
502                  */
503                 if ((i != 0) && LineNotAllBlanks)
504                 {
505                     if ((i + 1) >= Gbl_LineBufferSize)
506                     {
507                         UtExpandLineBuffers ();
508                     }
509
510                     Gbl_CurrentLineBuffer[i+1] = 0; /* Terminate string */
511                     return (CurrentLineOffset);
512                 }
513
514                 /* Toss this line and start a new one */
515
516                 i = 0;
517                 LineNotAllBlanks = FALSE;
518                 break;
519
520             default:
521
522                 if (c != ' ')
523                 {
524                     LineNotAllBlanks = TRUE;
525                 }
526
527                 i++;
528                 break;
529             }
530             break;
531
532         case DT_START_QUOTED_STRING:
533
534             /* Insert raw chars until end of quoted string */
535
536             Gbl_CurrentLineBuffer[i] = (char) c;
537             i++;
538
539             switch (c)
540             {
541             case '"':
542
543                 State = DT_NORMAL_TEXT;
544                 break;
545
546             case '\\':
547
548                 State = DT_ESCAPE_SEQUENCE;
549                 break;
550
551             case '\n':
552
553                 AcpiOsPrintf ("ERROR at line %u: Unterminated quoted string\n",
554                     Gbl_CurrentLineNumber++);
555                 State = DT_NORMAL_TEXT;
556                 break;
557
558             default:    /* Get next character */
559
560                 break;
561             }
562             break;
563
564         case DT_ESCAPE_SEQUENCE:
565
566             /* Just copy the escaped character. TBD: sufficient for table compiler? */
567
568             Gbl_CurrentLineBuffer[i] = (char) c;
569             i++;
570             State = DT_START_QUOTED_STRING;
571             break;
572
573         case DT_START_COMMENT:
574
575             /* Open comment if this character is an asterisk or slash */
576
577             switch (c)
578             {
579             case '*':
580
581                 State = DT_SLASH_ASTERISK_COMMENT;
582                 break;
583
584             case '/':
585
586                 State = DT_SLASH_SLASH_COMMENT;
587                 break;
588
589             default:    /* Not a comment */
590
591                 i++;    /* Save the preceding slash */
592                 if (i >= Gbl_LineBufferSize)
593                 {
594                     UtExpandLineBuffers ();
595                 }
596
597                 Gbl_CurrentLineBuffer[i] = (char) c;
598                 i++;
599                 State = DT_NORMAL_TEXT;
600                 break;
601             }
602             break;
603
604         case DT_SLASH_ASTERISK_COMMENT:
605
606             /* Ignore chars until an asterisk-slash is found */
607
608             switch (c)
609             {
610             case '\n':
611
612                 Gbl_NextLineOffset = (UINT32) ftell (Handle);
613                 Gbl_CurrentLineNumber++;
614                 break;
615
616             case '*':
617
618                 State = DT_END_COMMENT;
619                 break;
620
621             default:
622
623                 break;
624             }
625             break;
626
627         case DT_SLASH_SLASH_COMMENT:
628
629             /* Ignore chars until end-of-line */
630
631             if (c == '\n')
632             {
633                 /* We will exit via the NORMAL_TEXT path */
634
635                 ungetc (c, Handle);
636                 State = DT_NORMAL_TEXT;
637             }
638             break;
639
640         case DT_END_COMMENT:
641
642             /* End comment if this char is a slash */
643
644             switch (c)
645             {
646             case '/':
647
648                 State = DT_NORMAL_TEXT;
649                 break;
650
651             case '\n':
652
653                 CurrentLineOffset = Gbl_NextLineOffset;
654                 Gbl_NextLineOffset = (UINT32) ftell (Handle);
655                 Gbl_CurrentLineNumber++;
656                 break;
657
658             case '*':
659
660                 /* Consume all adjacent asterisks */
661                 break;
662
663             default:
664
665                 State = DT_SLASH_ASTERISK_COMMENT;
666                 break;
667             }
668             break;
669
670         case DT_MERGE_LINES:
671
672             if (c != '\n')
673             {
674                 /*
675                  * This is not a continuation backslash, it is a normal
676                  * normal ASL backslash - for example: Scope(\_SB_)
677                  */
678                 i++; /* Keep the backslash that is already in the buffer */
679
680                 ungetc (c, Handle);
681                 State = DT_NORMAL_TEXT;
682             }
683             else
684             {
685                 /*
686                  * This is a continuation line -- a backlash followed
687                  * immediately by a newline. Insert a space between the
688                  * lines (overwrite the backslash)
689                  */
690                 Gbl_CurrentLineBuffer[i] = ' ';
691                 i++;
692
693                 /* Ignore newline, this will merge the lines */
694
695                 CurrentLineOffset = Gbl_NextLineOffset;
696                 Gbl_NextLineOffset = (UINT32) ftell (Handle);
697                 Gbl_CurrentLineNumber++;
698                 State = DT_NORMAL_TEXT;
699             }
700             break;
701
702         default:
703
704             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, "Unknown input state");
705             return (ASL_EOF);
706         }
707     }
708 }
709
710
711 /******************************************************************************
712  *
713  * FUNCTION:    DtScanFile
714  *
715  * PARAMETERS:  Handle              - Open file handle for the source file
716  *
717  * RETURN:      Pointer to start of the constructed parse tree.
718  *
719  * DESCRIPTION: Scan source file, link all field names and values
720  *              to the global parse tree: Gbl_FieldList
721  *
722  *****************************************************************************/
723
724 DT_FIELD *
725 DtScanFile (
726     FILE                    *Handle)
727 {
728     ACPI_STATUS             Status;
729     UINT32                  Offset;
730
731
732     ACPI_FUNCTION_NAME (DtScanFile);
733
734
735     /* Get the file size */
736
737     Gbl_InputByteCount = CmGetFileSize (Handle);
738     if (Gbl_InputByteCount == ACPI_UINT32_MAX)
739     {
740         AslAbort ();
741     }
742
743     Gbl_CurrentLineNumber = 0;
744     Gbl_CurrentLineOffset = 0;
745     Gbl_NextLineOffset = 0;
746
747     /* Scan line-by-line */
748
749     while ((Offset = DtGetNextLine (Handle)) != ASL_EOF)
750     {
751         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s",
752             Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer));
753
754         Status = DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset);
755         if (Status == AE_NOT_FOUND)
756         {
757             break;
758         }
759     }
760
761     /* Dump the parse tree if debug enabled */
762
763     DtDumpFieldList (Gbl_FieldList);
764     return (Gbl_FieldList);
765 }
766
767
768 /*
769  * Output functions
770  */
771
772 /******************************************************************************
773  *
774  * FUNCTION:    DtWriteBinary
775  *
776  * PARAMETERS:  DT_WALK_CALLBACK
777  *
778  * RETURN:      Status
779  *
780  * DESCRIPTION: Write one subtable of a binary ACPI table
781  *
782  *****************************************************************************/
783
784 static void
785 DtWriteBinary (
786     DT_SUBTABLE             *Subtable,
787     void                    *Context,
788     void                    *ReturnValue)
789 {
790
791     FlWriteFile (ASL_FILE_AML_OUTPUT, Subtable->Buffer, Subtable->Length);
792 }
793
794
795 /******************************************************************************
796  *
797  * FUNCTION:    DtOutputBinary
798  *
799  * PARAMETERS:
800  *
801  * RETURN:      Status
802  *
803  * DESCRIPTION: Write entire binary ACPI table (result of compilation)
804  *
805  *****************************************************************************/
806
807 void
808 DtOutputBinary (
809     DT_SUBTABLE             *RootTable)
810 {
811
812     if (!RootTable)
813     {
814         return;
815     }
816
817     /* Walk the entire parse tree, emitting the binary data */
818
819     DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL);
820
821     Gbl_TableLength = CmGetFileSize (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle);
822     if (Gbl_TableLength == ACPI_UINT32_MAX)
823     {
824         AslAbort ();
825     }
826 }
827
828
829 /*
830  * Listing support
831  */
832
833 /******************************************************************************
834  *
835  * FUNCTION:    DtDumpBuffer
836  *
837  * PARAMETERS:  FileID              - Where to write buffer data
838  *              Buffer              - Buffer to dump
839  *              Offset              - Offset in current table
840  *              Length              - Buffer Length
841  *
842  * RETURN:      None
843  *
844  * DESCRIPTION: Another copy of DumpBuffer routine (unfortunately).
845  *
846  * TBD: merge dump buffer routines
847  *
848  *****************************************************************************/
849
850 static void
851 DtDumpBuffer (
852     UINT32                  FileId,
853     UINT8                   *Buffer,
854     UINT32                  Offset,
855     UINT32                  Length)
856 {
857     UINT32                  i;
858     UINT32                  j;
859     UINT8                   BufChar;
860
861
862     FlPrintFile (FileId, "Output: [%3.3Xh %4.4d %3d] ",
863         Offset, Offset, Length);
864
865     i = 0;
866     while (i < Length)
867     {
868         if (i >= 16)
869         {
870             FlPrintFile (FileId, "%24s", "");
871         }
872
873         /* Print 16 hex chars */
874
875         for (j = 0; j < 16;)
876         {
877             if (i + j >= Length)
878             {
879                 /* Dump fill spaces */
880
881                 FlPrintFile (FileId, "   ");
882                 j++;
883                 continue;
884             }
885
886             FlPrintFile (FileId, "%02X ", Buffer[i+j]);
887             j++;
888         }
889
890         FlPrintFile (FileId, " ");
891         for (j = 0; j < 16; j++)
892         {
893             if (i + j >= Length)
894             {
895                 FlPrintFile (FileId, "\n\n");
896                 return;
897             }
898
899             BufChar = Buffer[(ACPI_SIZE) i + j];
900             if (ACPI_IS_PRINT (BufChar))
901             {
902                 FlPrintFile (FileId, "%c", BufChar);
903             }
904             else
905             {
906                 FlPrintFile (FileId, ".");
907             }
908         }
909
910         /* Done with that line. */
911
912         FlPrintFile (FileId, "\n");
913         i += 16;
914     }
915
916     FlPrintFile (FileId, "\n\n");
917 }
918
919
920 /******************************************************************************
921  *
922  * FUNCTION:    DtDumpFieldList
923  *
924  * PARAMETERS:  Field               - Root field
925  *
926  * RETURN:      None
927  *
928  * DESCRIPTION: Dump the entire field list
929  *
930  *****************************************************************************/
931
932 void
933 DtDumpFieldList (
934     DT_FIELD                *Field)
935 {
936
937     if (!Gbl_DebugFlag || !Field)
938     {
939         return;
940     }
941
942     DbgPrint (ASL_DEBUG_OUTPUT,  "\nField List:\n"
943         "LineNo   ByteOff  NameCol  Column   TableOff "
944         "Flags %32s : %s\n\n", "Name", "Value");
945     while (Field)
946     {
947         DbgPrint (ASL_DEBUG_OUTPUT,
948             "%.08X %.08X %.08X %.08X %.08X %2.2X    %32s : %s\n",
949             Field->Line, Field->ByteOffset, Field->NameColumn,
950             Field->Column, Field->TableOffset, Field->Flags,
951             Field->Name, Field->Value);
952
953         Field = Field->Next;
954     }
955
956     DbgPrint (ASL_DEBUG_OUTPUT,  "\n\n");
957 }
958
959
960 /******************************************************************************
961  *
962  * FUNCTION:    DtDumpSubtableInfo, DtDumpSubtableTree
963  *
964  * PARAMETERS:  DT_WALK_CALLBACK
965  *
966  * RETURN:      None
967  *
968  * DESCRIPTION: Info - dump a subtable tree entry with extra information.
969  *              Tree - dump a subtable tree formatted by depth indentation.
970  *
971  *****************************************************************************/
972
973 static void
974 DtDumpSubtableInfo (
975     DT_SUBTABLE             *Subtable,
976     void                    *Context,
977     void                    *ReturnValue)
978 {
979
980     DbgPrint (ASL_DEBUG_OUTPUT,
981         "[%.04X] %24s %.08X %.08X %.08X %.08X %.08X %p %p %p\n",
982         Subtable->Depth, Subtable->Name, Subtable->Length, Subtable->TotalLength,
983         Subtable->SizeOfLengthField, Subtable->Flags, Subtable,
984         Subtable->Parent, Subtable->Child, Subtable->Peer);
985 }
986
987 static void
988 DtDumpSubtableTree (
989     DT_SUBTABLE             *Subtable,
990     void                    *Context,
991     void                    *ReturnValue)
992 {
993
994     DbgPrint (ASL_DEBUG_OUTPUT,
995         "[%.04X] %24s %*s%08X (%.02X) - (%.02X)\n",
996         Subtable->Depth, Subtable->Name, (4 * Subtable->Depth), " ",
997         Subtable, Subtable->Length, Subtable->TotalLength);
998 }
999
1000
1001 /******************************************************************************
1002  *
1003  * FUNCTION:    DtDumpSubtableList
1004  *
1005  * PARAMETERS:  None
1006  *
1007  * RETURN:      None
1008  *
1009  * DESCRIPTION: Dump the raw list of subtables with information, and also
1010  *              dump the subtable list in formatted tree format. Assists with
1011  *              the development of new table code.
1012  *
1013  *****************************************************************************/
1014
1015 void
1016 DtDumpSubtableList (
1017     void)
1018 {
1019
1020     if (!Gbl_DebugFlag || !Gbl_RootTable)
1021     {
1022         return;
1023     }
1024
1025     DbgPrint (ASL_DEBUG_OUTPUT,
1026         "Subtable Info:\n"
1027         "Depth                      Name Length   TotalLen LenSize  Flags    "
1028         "This     Parent   Child    Peer\n\n");
1029     DtWalkTableTree (Gbl_RootTable, DtDumpSubtableInfo, NULL, NULL);
1030
1031     DbgPrint (ASL_DEBUG_OUTPUT,
1032         "\nSubtable Tree: (Depth, Name, Subtable, Length, TotalLength)\n\n");
1033     DtWalkTableTree (Gbl_RootTable, DtDumpSubtableTree, NULL, NULL);
1034
1035     DbgPrint (ASL_DEBUG_OUTPUT, "\n");
1036 }
1037
1038
1039 /******************************************************************************
1040  *
1041  * FUNCTION:    DtWriteFieldToListing
1042  *
1043  * PARAMETERS:  Buffer              - Contains the compiled data
1044  *              Field               - Field node for the input line
1045  *              Length              - Length of the output data
1046  *
1047  * RETURN:      None
1048  *
1049  * DESCRIPTION: Write one field to the listing file (if listing is enabled).
1050  *
1051  *****************************************************************************/
1052
1053 void
1054 DtWriteFieldToListing (
1055     UINT8                   *Buffer,
1056     DT_FIELD                *Field,
1057     UINT32                  Length)
1058 {
1059     UINT8                   FileByte;
1060
1061
1062     if (!Gbl_ListingFlag || !Field)
1063     {
1064         return;
1065     }
1066
1067     /* Dump the original source line */
1068
1069     FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Input:  ");
1070     FlSeekFile (ASL_FILE_INPUT, Field->ByteOffset);
1071
1072     while (FlReadFile (ASL_FILE_INPUT, &FileByte, 1) == AE_OK)
1073     {
1074         FlWriteFile (ASL_FILE_LISTING_OUTPUT, &FileByte, 1);
1075         if (FileByte == '\n')
1076         {
1077             break;
1078         }
1079     }
1080
1081     /* Dump the line as parsed and represented internally */
1082
1083     FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Parsed: %*s : %.64s",
1084         Field->Column-4, Field->Name, Field->Value);
1085
1086     if (strlen (Field->Value) > 64)
1087     {
1088         FlPrintFile (ASL_FILE_LISTING_OUTPUT, "...Additional data, length 0x%X\n",
1089             strlen (Field->Value));
1090     }
1091     FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n");
1092
1093     /* Dump the hex data that will be output for this field */
1094
1095     DtDumpBuffer (ASL_FILE_LISTING_OUTPUT, Buffer, Field->TableOffset, Length);
1096 }
1097
1098
1099 /******************************************************************************
1100  *
1101  * FUNCTION:    DtWriteTableToListing
1102  *
1103  * PARAMETERS:  None
1104  *
1105  * RETURN:      None
1106  *
1107  * DESCRIPTION: Write the entire compiled table to the listing file
1108  *              in hex format
1109  *
1110  *****************************************************************************/
1111
1112 void
1113 DtWriteTableToListing (
1114     void)
1115 {
1116     UINT8                   *Buffer;
1117
1118
1119     if (!Gbl_ListingFlag)
1120     {
1121         return;
1122     }
1123
1124     /* Read the entire table from the output file */
1125
1126     Buffer = UtLocalCalloc (Gbl_TableLength);
1127     FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
1128     FlReadFile (ASL_FILE_AML_OUTPUT, Buffer, Gbl_TableLength);
1129
1130     /* Dump the raw table data */
1131
1132     AcpiOsRedirectOutput (Gbl_Files[ASL_FILE_LISTING_OUTPUT].Handle);
1133
1134     AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n",
1135         ACPI_RAW_TABLE_DATA_HEADER, Gbl_TableLength, Gbl_TableLength);
1136     AcpiUtDumpBuffer (Buffer, Gbl_TableLength, DB_BYTE_DISPLAY, 0);
1137
1138     AcpiOsRedirectOutput (stdout);
1139     ACPI_FREE (Buffer);
1140 }