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