xref: /netbsd-src/sys/external/bsd/acpica/dist/compiler/dtio.c (revision 046a29855e04359424fd074e8313af6b6be8cfb6)
128c506b8Sjruoho /******************************************************************************
228c506b8Sjruoho  *
328c506b8Sjruoho  * Module Name: dtio.c - File I/O support for data table compiler
428c506b8Sjruoho  *
528c506b8Sjruoho  *****************************************************************************/
628c506b8Sjruoho 
7124f4c82Sjruoho /*
8*046a2985Schristos  * Copyright (C) 2000 - 2023, Intel Corp.
928c506b8Sjruoho  * All rights reserved.
1028c506b8Sjruoho  *
11124f4c82Sjruoho  * Redistribution and use in source and binary forms, with or without
12124f4c82Sjruoho  * modification, are permitted provided that the following conditions
13124f4c82Sjruoho  * are met:
14124f4c82Sjruoho  * 1. Redistributions of source code must retain the above copyright
15124f4c82Sjruoho  *    notice, this list of conditions, and the following disclaimer,
16124f4c82Sjruoho  *    without modification.
17124f4c82Sjruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18124f4c82Sjruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
19124f4c82Sjruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
20124f4c82Sjruoho  *    including a substantially similar Disclaimer requirement for further
21124f4c82Sjruoho  *    binary redistribution.
22124f4c82Sjruoho  * 3. Neither the names of the above-listed copyright holders nor the names
23124f4c82Sjruoho  *    of any contributors may be used to endorse or promote products derived
24124f4c82Sjruoho  *    from this software without specific prior written permission.
2528c506b8Sjruoho  *
26124f4c82Sjruoho  * Alternatively, this software may be distributed under the terms of the
27124f4c82Sjruoho  * GNU General Public License ("GPL") version 2 as published by the Free
28124f4c82Sjruoho  * Software Foundation.
2928c506b8Sjruoho  *
30124f4c82Sjruoho  * NO WARRANTY
31124f4c82Sjruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32124f4c82Sjruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3346a330b4Schristos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34124f4c82Sjruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35124f4c82Sjruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36124f4c82Sjruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37124f4c82Sjruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38124f4c82Sjruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39124f4c82Sjruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40124f4c82Sjruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41124f4c82Sjruoho  * POSSIBILITY OF SUCH DAMAGES.
42124f4c82Sjruoho  */
4328c506b8Sjruoho 
4428c506b8Sjruoho #include "aslcompiler.h"
45460301d4Schristos #include "acapps.h"
4628c506b8Sjruoho 
4728c506b8Sjruoho #define _COMPONENT          DT_COMPILER
4828c506b8Sjruoho         ACPI_MODULE_NAME    ("dtio")
4928c506b8Sjruoho 
5028c506b8Sjruoho 
51124f4c82Sjruoho /* Local prototypes */
5228c506b8Sjruoho 
53124f4c82Sjruoho static char *
54124f4c82Sjruoho DtTrim (
55124f4c82Sjruoho     char                    *String);
5628c506b8Sjruoho 
57124f4c82Sjruoho static ACPI_STATUS
58124f4c82Sjruoho DtParseLine (
59124f4c82Sjruoho     char                    *LineBuffer,
60124f4c82Sjruoho     UINT32                  Line,
61124f4c82Sjruoho     UINT32                  Offset);
6228c506b8Sjruoho 
63124f4c82Sjruoho static void
64124f4c82Sjruoho DtWriteBinary (
65124f4c82Sjruoho     DT_SUBTABLE             *Subtable,
66124f4c82Sjruoho     void                    *Context,
67124f4c82Sjruoho     void                    *ReturnValue);
68124f4c82Sjruoho 
69124f4c82Sjruoho static void
70124f4c82Sjruoho DtDumpBuffer (
71124f4c82Sjruoho     UINT32                  FileId,
72124f4c82Sjruoho     UINT8                   *Buffer,
73124f4c82Sjruoho     UINT32                  Offset,
74124f4c82Sjruoho     UINT32                  Length);
75124f4c82Sjruoho 
76ff4a156dSchristos static void
77ff4a156dSchristos DtDumpSubtableInfo (
78ff4a156dSchristos     DT_SUBTABLE             *Subtable,
79ff4a156dSchristos     void                    *Context,
80ff4a156dSchristos     void                    *ReturnValue);
81ff4a156dSchristos 
82ff4a156dSchristos static void
83ff4a156dSchristos DtDumpSubtableTree (
84ff4a156dSchristos     DT_SUBTABLE             *Subtable,
85ff4a156dSchristos     void                    *Context,
86ff4a156dSchristos     void                    *ReturnValue);
87ff4a156dSchristos 
88124f4c82Sjruoho 
89124f4c82Sjruoho /* States for DtGetNextLine */
90124f4c82Sjruoho 
91124f4c82Sjruoho #define DT_NORMAL_TEXT              0
92124f4c82Sjruoho #define DT_START_QUOTED_STRING      1
93124f4c82Sjruoho #define DT_START_COMMENT            2
94124f4c82Sjruoho #define DT_SLASH_ASTERISK_COMMENT   3
95124f4c82Sjruoho #define DT_SLASH_SLASH_COMMENT      4
96124f4c82Sjruoho #define DT_END_COMMENT              5
97a8e4c046Sjruoho #define DT_MERGE_LINES              6
98ff4a156dSchristos #define DT_ESCAPE_SEQUENCE          7
99124f4c82Sjruoho 
1004c4e8184Schristos static UINT32               AslGbl_NextLineOffset;
10128c506b8Sjruoho 
10228c506b8Sjruoho 
10328c506b8Sjruoho /******************************************************************************
10428c506b8Sjruoho  *
10528c506b8Sjruoho  * FUNCTION:    DtTrim
10628c506b8Sjruoho  *
10728c506b8Sjruoho  * PARAMETERS:  String              - Current source code line to trim
10828c506b8Sjruoho  *
10928c506b8Sjruoho  * RETURN:      Trimmed line. Must be freed by caller.
11028c506b8Sjruoho  *
11128c506b8Sjruoho  * DESCRIPTION: Trim left and right spaces
11228c506b8Sjruoho  *
11328c506b8Sjruoho  *****************************************************************************/
11428c506b8Sjruoho 
11528c506b8Sjruoho static char *
DtTrim(char * String)11628c506b8Sjruoho DtTrim (
11728c506b8Sjruoho     char                    *String)
11828c506b8Sjruoho {
11928c506b8Sjruoho     char                    *Start;
12028c506b8Sjruoho     char                    *End;
12128c506b8Sjruoho     char                    *ReturnString;
12228c506b8Sjruoho     ACPI_SIZE               Length;
12328c506b8Sjruoho 
12428c506b8Sjruoho 
12528c506b8Sjruoho     /* Skip lines that start with a space */
12628c506b8Sjruoho 
1274c4e8184Schristos     if (*String == 0 || !strcmp (String, " "))
12828c506b8Sjruoho     {
129b406f703Schristos         ReturnString = UtLocalCacheCalloc (1);
13028c506b8Sjruoho         return (ReturnString);
13128c506b8Sjruoho     }
13228c506b8Sjruoho 
13328c506b8Sjruoho     /* Setup pointers to start and end of input string */
13428c506b8Sjruoho 
13528c506b8Sjruoho     Start = String;
136c72da027Schristos     End = String + strlen (String) - 1;
13728c506b8Sjruoho 
13828c506b8Sjruoho     /* Find first non-whitespace character */
13928c506b8Sjruoho 
14028c506b8Sjruoho     while ((Start <= End) && ((*Start == ' ') || (*Start == '\t')))
14128c506b8Sjruoho     {
14228c506b8Sjruoho         Start++;
14328c506b8Sjruoho     }
14428c506b8Sjruoho 
14528c506b8Sjruoho     /* Find last non-space character */
14628c506b8Sjruoho 
14728c506b8Sjruoho     while (End >= Start)
14828c506b8Sjruoho     {
1494c4e8184Schristos         if (*End == '\n')
15028c506b8Sjruoho         {
15128c506b8Sjruoho             End--;
15228c506b8Sjruoho             continue;
15328c506b8Sjruoho         }
15428c506b8Sjruoho 
15528c506b8Sjruoho         if (*End != ' ')
15628c506b8Sjruoho         {
15728c506b8Sjruoho             break;
15828c506b8Sjruoho         }
15928c506b8Sjruoho 
16028c506b8Sjruoho         End--;
16128c506b8Sjruoho     }
16228c506b8Sjruoho 
16328c506b8Sjruoho     /* Remove any quotes around the string */
16428c506b8Sjruoho 
16528c506b8Sjruoho     if (*Start == '\"')
16628c506b8Sjruoho     {
16728c506b8Sjruoho         Start++;
16828c506b8Sjruoho     }
16928c506b8Sjruoho     if (*End == '\"')
17028c506b8Sjruoho     {
17128c506b8Sjruoho         End--;
17228c506b8Sjruoho     }
17328c506b8Sjruoho 
17428c506b8Sjruoho     /* Create the trimmed return string */
17528c506b8Sjruoho 
17628c506b8Sjruoho     Length = ACPI_PTR_DIFF (End, Start) + 1;
177b406f703Schristos     ReturnString = UtLocalCacheCalloc (Length + 1);
178c72da027Schristos     if (strlen (Start))
17928c506b8Sjruoho     {
180c72da027Schristos         strncpy (ReturnString, Start, Length);
18128c506b8Sjruoho     }
18228c506b8Sjruoho 
18328c506b8Sjruoho     ReturnString[Length] = 0;
18428c506b8Sjruoho     return (ReturnString);
18528c506b8Sjruoho }
18628c506b8Sjruoho 
18728c506b8Sjruoho 
18828c506b8Sjruoho /******************************************************************************
18928c506b8Sjruoho  *
19028c506b8Sjruoho  * FUNCTION:    DtParseLine
19128c506b8Sjruoho  *
19228c506b8Sjruoho  * PARAMETERS:  LineBuffer          - Current source code line
19328c506b8Sjruoho  *              Line                - Current line number in the source
19428c506b8Sjruoho  *              Offset              - Current byte offset of the line
19528c506b8Sjruoho  *
196124f4c82Sjruoho  * RETURN:      Status
19728c506b8Sjruoho  *
19828c506b8Sjruoho  * DESCRIPTION: Parse one source line
19928c506b8Sjruoho  *
20028c506b8Sjruoho  *****************************************************************************/
20128c506b8Sjruoho 
202124f4c82Sjruoho static ACPI_STATUS
DtParseLine(char * LineBuffer,UINT32 Line,UINT32 Offset)20328c506b8Sjruoho DtParseLine (
20428c506b8Sjruoho     char                    *LineBuffer,
20528c506b8Sjruoho     UINT32                  Line,
20628c506b8Sjruoho     UINT32                  Offset)
20728c506b8Sjruoho {
20828c506b8Sjruoho     char                    *Start;
20928c506b8Sjruoho     char                    *End;
21028c506b8Sjruoho     char                    *TmpName;
21128c506b8Sjruoho     char                    *TmpValue;
21228c506b8Sjruoho     char                    *Name;
21328c506b8Sjruoho     char                    *Value;
21428c506b8Sjruoho     char                    *Colon;
21528c506b8Sjruoho     UINT32                  Length;
21628c506b8Sjruoho     DT_FIELD                *Field;
21728c506b8Sjruoho     UINT32                  Column;
21828c506b8Sjruoho     UINT32                  NameColumn;
219a8e4c046Sjruoho     BOOLEAN                 IsNullString = FALSE;
22028c506b8Sjruoho 
22128c506b8Sjruoho 
222124f4c82Sjruoho     if (!LineBuffer)
22328c506b8Sjruoho     {
224124f4c82Sjruoho         return (AE_OK);
225124f4c82Sjruoho     }
226124f4c82Sjruoho 
22794783addSchristos     /* All lines after "Raw Table Data" are ignored */
228124f4c82Sjruoho 
229124f4c82Sjruoho     if (strstr (LineBuffer, ACPI_RAW_TABLE_DATA_HEADER))
230124f4c82Sjruoho     {
231124f4c82Sjruoho         return (AE_NOT_FOUND);
23228c506b8Sjruoho     }
23328c506b8Sjruoho 
23428c506b8Sjruoho     Colon = strchr (LineBuffer, ':');
235124f4c82Sjruoho     if (!Colon)
23628c506b8Sjruoho     {
237124f4c82Sjruoho         return (AE_OK);
23828c506b8Sjruoho     }
23928c506b8Sjruoho 
24028c506b8Sjruoho     Start = LineBuffer;
24128c506b8Sjruoho     End = Colon;
24228c506b8Sjruoho 
24328c506b8Sjruoho     while (Start < Colon)
24428c506b8Sjruoho     {
24528c506b8Sjruoho         if (*Start == '[')
24628c506b8Sjruoho         {
247ff4a156dSchristos             /* Found left bracket, go to the right bracket */
248ff4a156dSchristos 
24928c506b8Sjruoho             while (Start < Colon && *Start != ']')
25028c506b8Sjruoho             {
25128c506b8Sjruoho                 Start++;
25228c506b8Sjruoho             }
253ff4a156dSchristos         }
254ff4a156dSchristos         else if (*Start != ' ')
25528c506b8Sjruoho         {
25628c506b8Sjruoho             break;
25728c506b8Sjruoho         }
25828c506b8Sjruoho 
25928c506b8Sjruoho         Start++;
26028c506b8Sjruoho     }
26128c506b8Sjruoho 
26228c506b8Sjruoho     /*
26328c506b8Sjruoho      * There are two column values. One for the field name,
26428c506b8Sjruoho      * and one for the field value.
26528c506b8Sjruoho      */
26628c506b8Sjruoho     Column = ACPI_PTR_DIFF (Colon, LineBuffer) + 3;
26728c506b8Sjruoho     NameColumn = ACPI_PTR_DIFF (Start, LineBuffer) + 1;
26828c506b8Sjruoho 
26928c506b8Sjruoho     Length = ACPI_PTR_DIFF (End, Start);
27028c506b8Sjruoho 
27128c506b8Sjruoho     TmpName = UtLocalCalloc (Length + 1);
272c72da027Schristos     strncpy (TmpName, Start, Length);
27328c506b8Sjruoho     Name = DtTrim (TmpName);
27428c506b8Sjruoho     ACPI_FREE (TmpName);
27528c506b8Sjruoho 
27628c506b8Sjruoho     Start = End = (Colon + 1);
27728c506b8Sjruoho     while (*End)
27828c506b8Sjruoho     {
27928c506b8Sjruoho         /* Found left quotation, go to the right quotation and break */
28028c506b8Sjruoho 
28128c506b8Sjruoho         if (*End == '"')
28228c506b8Sjruoho         {
28328c506b8Sjruoho             End++;
284a8e4c046Sjruoho 
285a8e4c046Sjruoho             /* Check for an explicit null string */
286a8e4c046Sjruoho 
287a8e4c046Sjruoho             if (*End == '"')
288a8e4c046Sjruoho             {
289a8e4c046Sjruoho                 IsNullString = TRUE;
290a8e4c046Sjruoho             }
291124f4c82Sjruoho             while (*End && (*End != '"'))
29228c506b8Sjruoho             {
29328c506b8Sjruoho                 End++;
29428c506b8Sjruoho             }
29528c506b8Sjruoho 
29628c506b8Sjruoho             End++;
29728c506b8Sjruoho             break;
29828c506b8Sjruoho         }
29928c506b8Sjruoho 
300124f4c82Sjruoho         /*
301124f4c82Sjruoho          * Special "comment" fields at line end, ignore them.
302124f4c82Sjruoho          * Note: normal slash-slash and slash-asterisk comments are
303124f4c82Sjruoho          * stripped already by the DtGetNextLine parser.
304124f4c82Sjruoho          *
305124f4c82Sjruoho          * TBD: Perhaps DtGetNextLine should parse the following type
306124f4c82Sjruoho          * of comments also.
307124f4c82Sjruoho          */
308a8e4c046Sjruoho         if (*End == '[')
30928c506b8Sjruoho         {
310a8e4c046Sjruoho             End--;
31128c506b8Sjruoho             break;
31228c506b8Sjruoho         }
31371e38f1dSchristos 
31428c506b8Sjruoho         End++;
31528c506b8Sjruoho     }
31628c506b8Sjruoho 
31728c506b8Sjruoho     Length = ACPI_PTR_DIFF (End, Start);
31828c506b8Sjruoho     TmpValue = UtLocalCalloc (Length + 1);
319a8e4c046Sjruoho 
320c72da027Schristos     strncpy (TmpValue, Start, Length);
32128c506b8Sjruoho     Value = DtTrim (TmpValue);
32228c506b8Sjruoho     ACPI_FREE (TmpValue);
32328c506b8Sjruoho 
324a8e4c046Sjruoho     /* Create a new field object only if we have a valid value field */
325a8e4c046Sjruoho 
326a8e4c046Sjruoho     if ((Value && *Value) || IsNullString)
32728c506b8Sjruoho     {
328460301d4Schristos         Field = UtFieldCacheCalloc ();
32928c506b8Sjruoho         Field->Name = Name;
33028c506b8Sjruoho         Field->Value = Value;
33128c506b8Sjruoho         Field->Line = Line;
33228c506b8Sjruoho         Field->ByteOffset = Offset;
33328c506b8Sjruoho         Field->NameColumn = NameColumn;
33428c506b8Sjruoho         Field->Column = Column;
335679c17fdSchristos         Field->StringLength = Length;
33628c506b8Sjruoho 
33728c506b8Sjruoho         DtLinkField (Field);
33828c506b8Sjruoho     }
339460301d4Schristos     /* Else -- Ignore this field, it has no valid data */
340124f4c82Sjruoho 
341124f4c82Sjruoho     return (AE_OK);
342124f4c82Sjruoho }
343124f4c82Sjruoho 
344124f4c82Sjruoho 
345124f4c82Sjruoho /******************************************************************************
346124f4c82Sjruoho  *
347124f4c82Sjruoho  * FUNCTION:    DtGetNextLine
348124f4c82Sjruoho  *
349124f4c82Sjruoho  * PARAMETERS:  Handle              - Open file handle for the source file
350124f4c82Sjruoho  *
351a8e4c046Sjruoho  * RETURN:      Filled line buffer and offset of start-of-line (ASL_EOF on EOF)
352124f4c82Sjruoho  *
353124f4c82Sjruoho  * DESCRIPTION: Get the next valid source line. Removes all comments.
354124f4c82Sjruoho  *              Ignores empty lines.
355124f4c82Sjruoho  *
356124f4c82Sjruoho  * Handles both slash-asterisk and slash-slash comments.
357124f4c82Sjruoho  * Also, quoted strings, but no escapes within.
358124f4c82Sjruoho  *
3594c4e8184Schristos  * Line is returned in AslGbl_CurrentLineBuffer.
3604c4e8184Schristos  * Line number in original file is returned in AslGbl_CurrentLineNumber.
361124f4c82Sjruoho  *
362124f4c82Sjruoho  *****************************************************************************/
363124f4c82Sjruoho 
364124f4c82Sjruoho UINT32
DtGetNextLine(FILE * Handle,UINT32 Flags)365124f4c82Sjruoho DtGetNextLine (
366c72da027Schristos     FILE                    *Handle,
367c72da027Schristos     UINT32                  Flags)
368124f4c82Sjruoho {
369a8e4c046Sjruoho     BOOLEAN                 LineNotAllBlanks = FALSE;
370124f4c82Sjruoho     UINT32                  State = DT_NORMAL_TEXT;
371124f4c82Sjruoho     UINT32                  CurrentLineOffset;
372124f4c82Sjruoho     UINT32                  i;
373ff4a156dSchristos     int                     c;
3744c4e8184Schristos     int                     c1;
375124f4c82Sjruoho 
376124f4c82Sjruoho 
3774c4e8184Schristos     memset (AslGbl_CurrentLineBuffer, 0, AslGbl_LineBufferSize);
378ff4a156dSchristos     for (i = 0; ;)
379124f4c82Sjruoho     {
380ff4a156dSchristos         /*
381ff4a156dSchristos          * If line is too long, expand the line buffers. Also increases
3824c4e8184Schristos          * AslGbl_LineBufferSize.
383ff4a156dSchristos          */
3844c4e8184Schristos         if (i >= AslGbl_LineBufferSize)
385ff4a156dSchristos         {
386ff4a156dSchristos             UtExpandLineBuffers ();
387ff4a156dSchristos         }
388ff4a156dSchristos 
389ff4a156dSchristos         c = getc (Handle);
390124f4c82Sjruoho         if (c == EOF)
391124f4c82Sjruoho         {
392124f4c82Sjruoho             switch (State)
393124f4c82Sjruoho             {
394124f4c82Sjruoho             case DT_START_QUOTED_STRING:
395124f4c82Sjruoho             case DT_SLASH_ASTERISK_COMMENT:
396124f4c82Sjruoho 
397124f4c82Sjruoho                 AcpiOsPrintf ("**** EOF within comment/string %u\n", State);
398124f4c82Sjruoho                 break;
399124f4c82Sjruoho 
400124f4c82Sjruoho             default:
401ff4a156dSchristos 
402124f4c82Sjruoho                 break;
403124f4c82Sjruoho             }
404124f4c82Sjruoho 
405ff4a156dSchristos             /* Standalone EOF is OK */
406ff4a156dSchristos 
407ff4a156dSchristos             if (i == 0)
408ff4a156dSchristos             {
409a8e4c046Sjruoho                 return (ASL_EOF);
410124f4c82Sjruoho             }
411124f4c82Sjruoho 
412ff4a156dSchristos             /*
413ff4a156dSchristos              * Received an EOF in the middle of a line. Terminate the
414ff4a156dSchristos              * line with a newline. The next call to this function will
415ff4a156dSchristos              * return a standalone EOF. Thus, the upper parsing software
416ff4a156dSchristos              * never has to deal with an EOF within a valid line (or
417ff4a156dSchristos              * the last line does not get tossed on the floor.)
418ff4a156dSchristos              */
419ff4a156dSchristos             c = '\n';
420ff4a156dSchristos             State = DT_NORMAL_TEXT;
421ff4a156dSchristos         }
4224c4e8184Schristos         else if (c == '\r')
4234c4e8184Schristos         {
4244c4e8184Schristos             c1 = getc (Handle);
4254c4e8184Schristos             if (c1 == '\n')
4264c4e8184Schristos             {
4274c4e8184Schristos                 /*
4284c4e8184Schristos                  * Skip the carriage return as if it didn't exist. This is
4294c4e8184Schristos                  * onlt meant for input files in DOS format in unix. fopen in
4304c4e8184Schristos                  * unix may not support "text mode" and leaves CRLF intact.
4314c4e8184Schristos                  */
4324c4e8184Schristos                 c = '\n';
4334c4e8184Schristos             }
4344c4e8184Schristos             else
4354c4e8184Schristos             {
4364c4e8184Schristos                 /* This was not a CRLF. Only a CR */
4374c4e8184Schristos 
4384c4e8184Schristos                 ungetc(c1, Handle);
4394c4e8184Schristos 
4404c4e8184Schristos                 DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL,
4414c4e8184Schristos                     "Carriage return without linefeed detected");
4424c4e8184Schristos                 return (ASL_EOF);
4434c4e8184Schristos             }
4444c4e8184Schristos         }
445ff4a156dSchristos 
446124f4c82Sjruoho         switch (State)
447124f4c82Sjruoho         {
448124f4c82Sjruoho         case DT_NORMAL_TEXT:
449124f4c82Sjruoho 
450124f4c82Sjruoho             /* Normal text, insert char into line buffer */
451124f4c82Sjruoho 
4524c4e8184Schristos             AslGbl_CurrentLineBuffer[i] = (char) c;
453124f4c82Sjruoho             switch (c)
454124f4c82Sjruoho             {
455124f4c82Sjruoho             case '/':
456ff4a156dSchristos 
457124f4c82Sjruoho                 State = DT_START_COMMENT;
458124f4c82Sjruoho                 break;
459124f4c82Sjruoho 
460124f4c82Sjruoho             case '"':
461ff4a156dSchristos 
462124f4c82Sjruoho                 State = DT_START_QUOTED_STRING;
463a8e4c046Sjruoho                 LineNotAllBlanks = TRUE;
464124f4c82Sjruoho                 i++;
465124f4c82Sjruoho                 break;
466124f4c82Sjruoho 
467a8e4c046Sjruoho             case '\\':
468a8e4c046Sjruoho                 /*
469a8e4c046Sjruoho                  * The continuation char MUST be last char on this line.
470a8e4c046Sjruoho                  * Otherwise, it will be assumed to be a valid ASL char.
471a8e4c046Sjruoho                  */
472a8e4c046Sjruoho                 State = DT_MERGE_LINES;
473a8e4c046Sjruoho                 break;
474a8e4c046Sjruoho 
475124f4c82Sjruoho             case '\n':
476ff4a156dSchristos 
4774c4e8184Schristos                 CurrentLineOffset = AslGbl_NextLineOffset;
4784c4e8184Schristos                 AslGbl_NextLineOffset = (UINT32) ftell (Handle);
4794c4e8184Schristos                 AslGbl_CurrentLineNumber++;
480124f4c82Sjruoho 
481a8e4c046Sjruoho                 /*
482a8e4c046Sjruoho                  * Exit if line is complete. Ignore empty lines (only \n)
483a8e4c046Sjruoho                  * or lines that contain nothing but blanks.
484a8e4c046Sjruoho                  */
485a8e4c046Sjruoho                 if ((i != 0) && LineNotAllBlanks)
486124f4c82Sjruoho                 {
4874c4e8184Schristos                     if ((i + 1) >= AslGbl_LineBufferSize)
488ff4a156dSchristos                     {
489ff4a156dSchristos                         UtExpandLineBuffers ();
490ff4a156dSchristos                     }
491ff4a156dSchristos 
4924c4e8184Schristos                     AslGbl_CurrentLineBuffer[i+1] = 0; /* Terminate string */
493124f4c82Sjruoho                     return (CurrentLineOffset);
494124f4c82Sjruoho                 }
495a8e4c046Sjruoho 
496a8e4c046Sjruoho                 /* Toss this line and start a new one */
497a8e4c046Sjruoho 
498a8e4c046Sjruoho                 i = 0;
499a8e4c046Sjruoho                 LineNotAllBlanks = FALSE;
500124f4c82Sjruoho                 break;
501124f4c82Sjruoho 
502124f4c82Sjruoho             default:
503ff4a156dSchristos 
504a8e4c046Sjruoho                 if (c != ' ')
505a8e4c046Sjruoho                 {
506a8e4c046Sjruoho                     LineNotAllBlanks = TRUE;
507a8e4c046Sjruoho                 }
508a8e4c046Sjruoho 
509124f4c82Sjruoho                 i++;
510124f4c82Sjruoho                 break;
511124f4c82Sjruoho             }
512124f4c82Sjruoho             break;
513124f4c82Sjruoho 
514124f4c82Sjruoho         case DT_START_QUOTED_STRING:
515124f4c82Sjruoho 
516124f4c82Sjruoho             /* Insert raw chars until end of quoted string */
517124f4c82Sjruoho 
5184c4e8184Schristos             AslGbl_CurrentLineBuffer[i] = (char) c;
519124f4c82Sjruoho             i++;
520124f4c82Sjruoho 
521ff4a156dSchristos             switch (c)
522124f4c82Sjruoho             {
523ff4a156dSchristos             case '"':
524ff4a156dSchristos 
525124f4c82Sjruoho                 State = DT_NORMAL_TEXT;
526ff4a156dSchristos                 break;
527ff4a156dSchristos 
528ff4a156dSchristos             case '\\':
529ff4a156dSchristos 
530ff4a156dSchristos                 State = DT_ESCAPE_SEQUENCE;
531ff4a156dSchristos                 break;
532ff4a156dSchristos 
533ff4a156dSchristos             case '\n':
534ff4a156dSchristos 
535c72da027Schristos                 if (!(Flags & DT_ALLOW_MULTILINE_QUOTES))
536c72da027Schristos                 {
53771e38f1dSchristos                     AcpiOsPrintf (
53871e38f1dSchristos                         "ERROR at line %u: Unterminated quoted string\n",
5394c4e8184Schristos                         AslGbl_CurrentLineNumber++);
540ff4a156dSchristos                     State = DT_NORMAL_TEXT;
541c72da027Schristos                 }
542ff4a156dSchristos                 break;
543ff4a156dSchristos 
544ff4a156dSchristos             default:    /* Get next character */
545ff4a156dSchristos 
546ff4a156dSchristos                 break;
547124f4c82Sjruoho             }
548124f4c82Sjruoho             break;
549124f4c82Sjruoho 
550ff4a156dSchristos         case DT_ESCAPE_SEQUENCE:
551ff4a156dSchristos 
552ff4a156dSchristos             /* Just copy the escaped character. TBD: sufficient for table compiler? */
553ff4a156dSchristos 
5544c4e8184Schristos             AslGbl_CurrentLineBuffer[i] = (char) c;
555ff4a156dSchristos             i++;
556ff4a156dSchristos             State = DT_START_QUOTED_STRING;
557ff4a156dSchristos             break;
558ff4a156dSchristos 
559124f4c82Sjruoho         case DT_START_COMMENT:
560124f4c82Sjruoho 
561124f4c82Sjruoho             /* Open comment if this character is an asterisk or slash */
562124f4c82Sjruoho 
563124f4c82Sjruoho             switch (c)
564124f4c82Sjruoho             {
565124f4c82Sjruoho             case '*':
566ff4a156dSchristos 
567124f4c82Sjruoho                 State = DT_SLASH_ASTERISK_COMMENT;
568124f4c82Sjruoho                 break;
569124f4c82Sjruoho 
570124f4c82Sjruoho             case '/':
571ff4a156dSchristos 
572124f4c82Sjruoho                 State = DT_SLASH_SLASH_COMMENT;
573124f4c82Sjruoho                 break;
574124f4c82Sjruoho 
575124f4c82Sjruoho             default:    /* Not a comment */
576ff4a156dSchristos 
577ff4a156dSchristos                 i++;    /* Save the preceding slash */
5784c4e8184Schristos                 if (i >= AslGbl_LineBufferSize)
579ff4a156dSchristos                 {
580ff4a156dSchristos                     UtExpandLineBuffers ();
581ff4a156dSchristos                 }
582ff4a156dSchristos 
5834c4e8184Schristos                 AslGbl_CurrentLineBuffer[i] = (char) c;
584124f4c82Sjruoho                 i++;
585124f4c82Sjruoho                 State = DT_NORMAL_TEXT;
586124f4c82Sjruoho                 break;
587124f4c82Sjruoho             }
588124f4c82Sjruoho             break;
589124f4c82Sjruoho 
590124f4c82Sjruoho         case DT_SLASH_ASTERISK_COMMENT:
591124f4c82Sjruoho 
592124f4c82Sjruoho             /* Ignore chars until an asterisk-slash is found */
593124f4c82Sjruoho 
594124f4c82Sjruoho             switch (c)
595124f4c82Sjruoho             {
596124f4c82Sjruoho             case '\n':
597ff4a156dSchristos 
5984c4e8184Schristos                 AslGbl_NextLineOffset = (UINT32) ftell (Handle);
5994c4e8184Schristos                 AslGbl_CurrentLineNumber++;
600124f4c82Sjruoho                 break;
601124f4c82Sjruoho 
602124f4c82Sjruoho             case '*':
603ff4a156dSchristos 
604124f4c82Sjruoho                 State = DT_END_COMMENT;
605124f4c82Sjruoho                 break;
606124f4c82Sjruoho 
607124f4c82Sjruoho             default:
608ff4a156dSchristos 
609124f4c82Sjruoho                 break;
610124f4c82Sjruoho             }
611124f4c82Sjruoho             break;
612124f4c82Sjruoho 
613124f4c82Sjruoho         case DT_SLASH_SLASH_COMMENT:
614124f4c82Sjruoho 
615124f4c82Sjruoho             /* Ignore chars until end-of-line */
616124f4c82Sjruoho 
617124f4c82Sjruoho             if (c == '\n')
618124f4c82Sjruoho             {
619124f4c82Sjruoho                 /* We will exit via the NORMAL_TEXT path */
620124f4c82Sjruoho 
621124f4c82Sjruoho                 ungetc (c, Handle);
622124f4c82Sjruoho                 State = DT_NORMAL_TEXT;
623124f4c82Sjruoho             }
624124f4c82Sjruoho             break;
625124f4c82Sjruoho 
626124f4c82Sjruoho         case DT_END_COMMENT:
627124f4c82Sjruoho 
628124f4c82Sjruoho             /* End comment if this char is a slash */
629124f4c82Sjruoho 
630124f4c82Sjruoho             switch (c)
631124f4c82Sjruoho             {
632124f4c82Sjruoho             case '/':
633ff4a156dSchristos 
634124f4c82Sjruoho                 State = DT_NORMAL_TEXT;
635124f4c82Sjruoho                 break;
636124f4c82Sjruoho 
637124f4c82Sjruoho             case '\n':
638ff4a156dSchristos 
6394c4e8184Schristos                 AslGbl_NextLineOffset = (UINT32) ftell (Handle);
6404c4e8184Schristos                 AslGbl_CurrentLineNumber++;
641124f4c82Sjruoho                 break;
642124f4c82Sjruoho 
643124f4c82Sjruoho             case '*':
644ff4a156dSchristos 
645124f4c82Sjruoho                 /* Consume all adjacent asterisks */
646124f4c82Sjruoho                 break;
647124f4c82Sjruoho 
648124f4c82Sjruoho             default:
649ff4a156dSchristos 
650124f4c82Sjruoho                 State = DT_SLASH_ASTERISK_COMMENT;
651124f4c82Sjruoho                 break;
652124f4c82Sjruoho             }
653124f4c82Sjruoho             break;
654124f4c82Sjruoho 
655a8e4c046Sjruoho         case DT_MERGE_LINES:
656a8e4c046Sjruoho 
657a8e4c046Sjruoho             if (c != '\n')
658a8e4c046Sjruoho             {
659a8e4c046Sjruoho                 /*
660a8e4c046Sjruoho                  * This is not a continuation backslash, it is a normal
661a8e4c046Sjruoho                  * normal ASL backslash - for example: Scope(\_SB_)
662a8e4c046Sjruoho                  */
663a8e4c046Sjruoho                 i++; /* Keep the backslash that is already in the buffer */
664a8e4c046Sjruoho 
665a8e4c046Sjruoho                 ungetc (c, Handle);
666a8e4c046Sjruoho                 State = DT_NORMAL_TEXT;
667a8e4c046Sjruoho             }
668a8e4c046Sjruoho             else
669a8e4c046Sjruoho             {
670a8e4c046Sjruoho                 /*
671a8e4c046Sjruoho                  * This is a continuation line -- a backlash followed
672a8e4c046Sjruoho                  * immediately by a newline. Insert a space between the
673a8e4c046Sjruoho                  * lines (overwrite the backslash)
674a8e4c046Sjruoho                  */
6754c4e8184Schristos                 AslGbl_CurrentLineBuffer[i] = ' ';
676a8e4c046Sjruoho                 i++;
677a8e4c046Sjruoho 
678a8e4c046Sjruoho                 /* Ignore newline, this will merge the lines */
679a8e4c046Sjruoho 
6804c4e8184Schristos                 AslGbl_NextLineOffset = (UINT32) ftell (Handle);
6814c4e8184Schristos                 AslGbl_CurrentLineNumber++;
682a8e4c046Sjruoho                 State = DT_NORMAL_TEXT;
683a8e4c046Sjruoho             }
684a8e4c046Sjruoho             break;
685a8e4c046Sjruoho 
686124f4c82Sjruoho         default:
687ff4a156dSchristos 
688124f4c82Sjruoho             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, "Unknown input state");
689a8e4c046Sjruoho             return (ASL_EOF);
690124f4c82Sjruoho         }
691124f4c82Sjruoho     }
69228c506b8Sjruoho }
69328c506b8Sjruoho 
69428c506b8Sjruoho 
69528c506b8Sjruoho /******************************************************************************
69628c506b8Sjruoho  *
69728c506b8Sjruoho  * FUNCTION:    DtScanFile
69828c506b8Sjruoho  *
69928c506b8Sjruoho  * PARAMETERS:  Handle              - Open file handle for the source file
70028c506b8Sjruoho  *
70128c506b8Sjruoho  * RETURN:      Pointer to start of the constructed parse tree.
70228c506b8Sjruoho  *
703124f4c82Sjruoho  * DESCRIPTION: Scan source file, link all field names and values
7044c4e8184Schristos  *              to the global parse tree: AslGbl_FieldList
70528c506b8Sjruoho  *
70628c506b8Sjruoho  *****************************************************************************/
70728c506b8Sjruoho 
70828c506b8Sjruoho DT_FIELD *
DtScanFile(FILE * Handle)70928c506b8Sjruoho DtScanFile (
71028c506b8Sjruoho     FILE                    *Handle)
71128c506b8Sjruoho {
712124f4c82Sjruoho     ACPI_STATUS             Status;
713124f4c82Sjruoho     UINT32                  Offset;
714124f4c82Sjruoho 
715124f4c82Sjruoho 
716124f4c82Sjruoho     ACPI_FUNCTION_NAME (DtScanFile);
71728c506b8Sjruoho 
71828c506b8Sjruoho 
71928c506b8Sjruoho     /* Get the file size */
72028c506b8Sjruoho 
7214c4e8184Schristos     AslGbl_InputByteCount = CmGetFileSize (Handle);
7224c4e8184Schristos     if (AslGbl_InputByteCount == ACPI_UINT32_MAX)
723460301d4Schristos     {
724460301d4Schristos         AslAbort ();
725460301d4Schristos     }
72628c506b8Sjruoho 
7274c4e8184Schristos     AslGbl_CurrentLineNumber = 0;
7284c4e8184Schristos     AslGbl_CurrentLineOffset = 0;
7294c4e8184Schristos     AslGbl_NextLineOffset = 0;
730124f4c82Sjruoho 
73128c506b8Sjruoho     /* Scan line-by-line */
73228c506b8Sjruoho 
733c72da027Schristos     while ((Offset = DtGetNextLine (Handle, 0)) != ASL_EOF)
73428c506b8Sjruoho     {
735124f4c82Sjruoho         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s",
7364c4e8184Schristos             AslGbl_CurrentLineNumber, Offset, AslGbl_CurrentLineBuffer));
73728c506b8Sjruoho 
7384c4e8184Schristos         Status = DtParseLine (AslGbl_CurrentLineBuffer,
7394c4e8184Schristos             AslGbl_CurrentLineNumber, Offset);
740124f4c82Sjruoho         if (Status == AE_NOT_FOUND)
741124f4c82Sjruoho         {
742124f4c82Sjruoho             break;
743124f4c82Sjruoho         }
74428c506b8Sjruoho     }
74528c506b8Sjruoho 
746a8e4c046Sjruoho     /* Dump the parse tree if debug enabled */
747a8e4c046Sjruoho 
7484c4e8184Schristos     DtDumpFieldList (AslGbl_FieldList);
7494c4e8184Schristos     return (AslGbl_FieldList);
75028c506b8Sjruoho }
75128c506b8Sjruoho 
75228c506b8Sjruoho 
75328c506b8Sjruoho /*
75428c506b8Sjruoho  * Output functions
75528c506b8Sjruoho  */
75628c506b8Sjruoho 
75728c506b8Sjruoho /******************************************************************************
75828c506b8Sjruoho  *
75928c506b8Sjruoho  * FUNCTION:    DtWriteBinary
76028c506b8Sjruoho  *
76128c506b8Sjruoho  * PARAMETERS:  DT_WALK_CALLBACK
76228c506b8Sjruoho  *
76328c506b8Sjruoho  * RETURN:      Status
76428c506b8Sjruoho  *
76528c506b8Sjruoho  * DESCRIPTION: Write one subtable of a binary ACPI table
76628c506b8Sjruoho  *
76728c506b8Sjruoho  *****************************************************************************/
76828c506b8Sjruoho 
76928c506b8Sjruoho static void
DtWriteBinary(DT_SUBTABLE * Subtable,void * Context,void * ReturnValue)77028c506b8Sjruoho DtWriteBinary (
77128c506b8Sjruoho     DT_SUBTABLE             *Subtable,
77228c506b8Sjruoho     void                    *Context,
77328c506b8Sjruoho     void                    *ReturnValue)
77428c506b8Sjruoho {
77528c506b8Sjruoho 
77628c506b8Sjruoho     FlWriteFile (ASL_FILE_AML_OUTPUT, Subtable->Buffer, Subtable->Length);
77728c506b8Sjruoho }
77828c506b8Sjruoho 
77928c506b8Sjruoho 
78028c506b8Sjruoho /******************************************************************************
78128c506b8Sjruoho  *
78228c506b8Sjruoho  * FUNCTION:    DtOutputBinary
78328c506b8Sjruoho  *
78428c506b8Sjruoho  * PARAMETERS:
78528c506b8Sjruoho  *
78628c506b8Sjruoho  * RETURN:      Status
78728c506b8Sjruoho  *
78828c506b8Sjruoho  * DESCRIPTION: Write entire binary ACPI table (result of compilation)
78928c506b8Sjruoho  *
79028c506b8Sjruoho  *****************************************************************************/
79128c506b8Sjruoho 
79228c506b8Sjruoho void
DtOutputBinary(DT_SUBTABLE * RootTable)79328c506b8Sjruoho DtOutputBinary (
79428c506b8Sjruoho     DT_SUBTABLE             *RootTable)
79528c506b8Sjruoho {
79628c506b8Sjruoho 
79728c506b8Sjruoho     if (!RootTable)
79828c506b8Sjruoho     {
79928c506b8Sjruoho         return;
80028c506b8Sjruoho     }
80128c506b8Sjruoho 
80228c506b8Sjruoho     /* Walk the entire parse tree, emitting the binary data */
80328c506b8Sjruoho 
80428c506b8Sjruoho     DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL);
805460301d4Schristos 
8064c4e8184Schristos     AslGbl_TableLength = CmGetFileSize (AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle);
8074c4e8184Schristos     if (AslGbl_TableLength == ACPI_UINT32_MAX)
808460301d4Schristos     {
809460301d4Schristos         AslAbort ();
810460301d4Schristos     }
81128c506b8Sjruoho }
812124f4c82Sjruoho 
813124f4c82Sjruoho 
814124f4c82Sjruoho /*
815124f4c82Sjruoho  * Listing support
816124f4c82Sjruoho  */
817124f4c82Sjruoho 
818124f4c82Sjruoho /******************************************************************************
819124f4c82Sjruoho  *
820124f4c82Sjruoho  * FUNCTION:    DtDumpBuffer
821124f4c82Sjruoho  *
822124f4c82Sjruoho  * PARAMETERS:  FileID              - Where to write buffer data
823124f4c82Sjruoho  *              Buffer              - Buffer to dump
824124f4c82Sjruoho  *              Offset              - Offset in current table
825124f4c82Sjruoho  *              Length              - Buffer Length
826124f4c82Sjruoho  *
827124f4c82Sjruoho  * RETURN:      None
828124f4c82Sjruoho  *
829124f4c82Sjruoho  * DESCRIPTION: Another copy of DumpBuffer routine (unfortunately).
830124f4c82Sjruoho  *
831124f4c82Sjruoho  * TBD: merge dump buffer routines
832124f4c82Sjruoho  *
833124f4c82Sjruoho  *****************************************************************************/
834124f4c82Sjruoho 
835124f4c82Sjruoho static void
DtDumpBuffer(UINT32 FileId,UINT8 * Buffer,UINT32 Offset,UINT32 Length)836124f4c82Sjruoho DtDumpBuffer (
837124f4c82Sjruoho     UINT32                  FileId,
838124f4c82Sjruoho     UINT8                   *Buffer,
839124f4c82Sjruoho     UINT32                  Offset,
840124f4c82Sjruoho     UINT32                  Length)
841124f4c82Sjruoho {
842124f4c82Sjruoho     UINT32                  i;
843124f4c82Sjruoho     UINT32                  j;
844124f4c82Sjruoho     UINT8                   BufChar;
845124f4c82Sjruoho 
846124f4c82Sjruoho 
84782065f3bSchristos     FlPrintFile (FileId, "Output: [%3.3Xh %4.4d %3.3Xh] ",
848124f4c82Sjruoho         Offset, Offset, Length);
849124f4c82Sjruoho 
850124f4c82Sjruoho     i = 0;
851124f4c82Sjruoho     while (i < Length)
852124f4c82Sjruoho     {
853124f4c82Sjruoho         if (i >= 16)
854124f4c82Sjruoho         {
855a8e4c046Sjruoho             FlPrintFile (FileId, "%24s", "");
856124f4c82Sjruoho         }
857124f4c82Sjruoho 
858124f4c82Sjruoho         /* Print 16 hex chars */
859124f4c82Sjruoho 
860124f4c82Sjruoho         for (j = 0; j < 16;)
861124f4c82Sjruoho         {
862124f4c82Sjruoho             if (i + j >= Length)
863124f4c82Sjruoho             {
864124f4c82Sjruoho                 /* Dump fill spaces */
865124f4c82Sjruoho 
866124f4c82Sjruoho                 FlPrintFile (FileId, "   ");
867124f4c82Sjruoho                 j++;
868124f4c82Sjruoho                 continue;
869124f4c82Sjruoho             }
870124f4c82Sjruoho 
871124f4c82Sjruoho             FlPrintFile (FileId, "%02X ", Buffer[i+j]);
872124f4c82Sjruoho             j++;
873124f4c82Sjruoho         }
874124f4c82Sjruoho 
875124f4c82Sjruoho         FlPrintFile (FileId, " ");
876124f4c82Sjruoho         for (j = 0; j < 16; j++)
877124f4c82Sjruoho         {
878124f4c82Sjruoho             if (i + j >= Length)
879124f4c82Sjruoho             {
880124f4c82Sjruoho                 FlPrintFile (FileId, "\n\n");
881124f4c82Sjruoho                 return;
882124f4c82Sjruoho             }
883124f4c82Sjruoho 
884124f4c82Sjruoho             BufChar = Buffer[(ACPI_SIZE) i + j];
885c72da027Schristos             if (isprint (BufChar))
886124f4c82Sjruoho             {
887124f4c82Sjruoho                 FlPrintFile (FileId, "%c", BufChar);
888124f4c82Sjruoho             }
889124f4c82Sjruoho             else
890124f4c82Sjruoho             {
891124f4c82Sjruoho                 FlPrintFile (FileId, ".");
892124f4c82Sjruoho             }
893124f4c82Sjruoho         }
894124f4c82Sjruoho 
895124f4c82Sjruoho         /* Done with that line. */
896124f4c82Sjruoho 
897124f4c82Sjruoho         FlPrintFile (FileId, "\n");
898124f4c82Sjruoho         i += 16;
899124f4c82Sjruoho     }
900124f4c82Sjruoho 
901124f4c82Sjruoho     FlPrintFile (FileId, "\n\n");
902124f4c82Sjruoho }
903124f4c82Sjruoho 
904124f4c82Sjruoho 
905124f4c82Sjruoho /******************************************************************************
906124f4c82Sjruoho  *
907ff4a156dSchristos  * FUNCTION:    DtDumpFieldList
908ff4a156dSchristos  *
909ff4a156dSchristos  * PARAMETERS:  Field               - Root field
910ff4a156dSchristos  *
911ff4a156dSchristos  * RETURN:      None
912ff4a156dSchristos  *
913ff4a156dSchristos  * DESCRIPTION: Dump the entire field list
914ff4a156dSchristos  *
915ff4a156dSchristos  *****************************************************************************/
916ff4a156dSchristos 
917ff4a156dSchristos void
DtDumpFieldList(DT_FIELD * Field)918ff4a156dSchristos DtDumpFieldList (
919ff4a156dSchristos     DT_FIELD                *Field)
920ff4a156dSchristos {
921ff4a156dSchristos 
9224c4e8184Schristos     if (!AslGbl_DebugFlag || !Field)
923ff4a156dSchristos     {
924ff4a156dSchristos         return;
925ff4a156dSchristos     }
926ff4a156dSchristos 
927ff4a156dSchristos     DbgPrint (ASL_DEBUG_OUTPUT,  "\nField List:\n"
928ff4a156dSchristos         "LineNo   ByteOff  NameCol  Column   TableOff "
929ff4a156dSchristos         "Flags %32s : %s\n\n", "Name", "Value");
93071e38f1dSchristos 
931ff4a156dSchristos     while (Field)
932ff4a156dSchristos     {
933ff4a156dSchristos         DbgPrint (ASL_DEBUG_OUTPUT,
934679c17fdSchristos             "%.08X %.08X %.08X %.08X %.08X %2.2X    %32s : %s\n",
935ff4a156dSchristos             Field->Line, Field->ByteOffset, Field->NameColumn,
936ff4a156dSchristos             Field->Column, Field->TableOffset, Field->Flags,
937ff4a156dSchristos             Field->Name, Field->Value);
938ff4a156dSchristos 
939ff4a156dSchristos         Field = Field->Next;
940ff4a156dSchristos     }
941ff4a156dSchristos 
942ff4a156dSchristos     DbgPrint (ASL_DEBUG_OUTPUT,  "\n\n");
943ff4a156dSchristos }
944ff4a156dSchristos 
945ff4a156dSchristos 
946ff4a156dSchristos /******************************************************************************
947ff4a156dSchristos  *
948ff4a156dSchristos  * FUNCTION:    DtDumpSubtableInfo, DtDumpSubtableTree
949ff4a156dSchristos  *
950ff4a156dSchristos  * PARAMETERS:  DT_WALK_CALLBACK
951ff4a156dSchristos  *
952ff4a156dSchristos  * RETURN:      None
953ff4a156dSchristos  *
954ff4a156dSchristos  * DESCRIPTION: Info - dump a subtable tree entry with extra information.
955ff4a156dSchristos  *              Tree - dump a subtable tree formatted by depth indentation.
956ff4a156dSchristos  *
957ff4a156dSchristos  *****************************************************************************/
958ff4a156dSchristos 
959ff4a156dSchristos static void
DtDumpSubtableInfo(DT_SUBTABLE * Subtable,void * Context,void * ReturnValue)960ff4a156dSchristos DtDumpSubtableInfo (
961ff4a156dSchristos     DT_SUBTABLE             *Subtable,
962ff4a156dSchristos     void                    *Context,
963ff4a156dSchristos     void                    *ReturnValue)
964ff4a156dSchristos {
965ff4a156dSchristos 
966ff4a156dSchristos     DbgPrint (ASL_DEBUG_OUTPUT,
967783af925Schristos         "[%.04X] %24s %.08X %.08X %.08X %.08X %p %p %p %p\n",
968c72da027Schristos         Subtable->Depth, Subtable->Name, Subtable->Length, Subtable->TotalLength,
969ff4a156dSchristos         Subtable->SizeOfLengthField, Subtable->Flags, Subtable,
970ff4a156dSchristos         Subtable->Parent, Subtable->Child, Subtable->Peer);
971ff4a156dSchristos }
972ff4a156dSchristos 
973ff4a156dSchristos static void
DtDumpSubtableTree(DT_SUBTABLE * Subtable,void * Context,void * ReturnValue)974ff4a156dSchristos DtDumpSubtableTree (
975ff4a156dSchristos     DT_SUBTABLE             *Subtable,
976ff4a156dSchristos     void                    *Context,
977ff4a156dSchristos     void                    *ReturnValue)
978ff4a156dSchristos {
979ff4a156dSchristos 
980ff4a156dSchristos     DbgPrint (ASL_DEBUG_OUTPUT,
9813e9809d7Schristos         "[%.04X] %24s %*s%p (%.02X) - (%.02X)        %.02X\n",
982c72da027Schristos         Subtable->Depth, Subtable->Name, (4 * Subtable->Depth), " ",
9833e9809d7Schristos         Subtable, Subtable->Length, Subtable->TotalLength, *Subtable->Buffer);
984ff4a156dSchristos }
985ff4a156dSchristos 
986ff4a156dSchristos 
987ff4a156dSchristos /******************************************************************************
988ff4a156dSchristos  *
989ff4a156dSchristos  * FUNCTION:    DtDumpSubtableList
990ff4a156dSchristos  *
991ff4a156dSchristos  * PARAMETERS:  None
992ff4a156dSchristos  *
993ff4a156dSchristos  * RETURN:      None
994ff4a156dSchristos  *
995ff4a156dSchristos  * DESCRIPTION: Dump the raw list of subtables with information, and also
996ff4a156dSchristos  *              dump the subtable list in formatted tree format. Assists with
997ff4a156dSchristos  *              the development of new table code.
998ff4a156dSchristos  *
999ff4a156dSchristos  *****************************************************************************/
1000ff4a156dSchristos 
1001ff4a156dSchristos void
DtDumpSubtableList(void)1002ff4a156dSchristos DtDumpSubtableList (
1003ff4a156dSchristos     void)
1004ff4a156dSchristos {
1005ff4a156dSchristos 
10064c4e8184Schristos     if (!AslGbl_DebugFlag || !AslGbl_RootTable)
1007ff4a156dSchristos     {
1008ff4a156dSchristos         return;
1009ff4a156dSchristos     }
1010ff4a156dSchristos 
1011ff4a156dSchristos     DbgPrint (ASL_DEBUG_OUTPUT,
1012ff4a156dSchristos         "Subtable Info:\n"
1013c72da027Schristos         "Depth                      Name Length   TotalLen LenSize  Flags    "
1014ff4a156dSchristos         "This     Parent   Child    Peer\n\n");
10154c4e8184Schristos     DtWalkTableTree (AslGbl_RootTable, DtDumpSubtableInfo, NULL, NULL);
1016ff4a156dSchristos 
1017ff4a156dSchristos     DbgPrint (ASL_DEBUG_OUTPUT,
10183e9809d7Schristos         "\nSubtable Tree: (Depth, Name, Subtable, Length, TotalLength, Integer Value)\n\n");
10194c4e8184Schristos     DtWalkTableTree (AslGbl_RootTable, DtDumpSubtableTree, NULL, NULL);
1020460301d4Schristos 
1021460301d4Schristos     DbgPrint (ASL_DEBUG_OUTPUT, "\n");
1022ff4a156dSchristos }
1023ff4a156dSchristos 
1024ff4a156dSchristos 
1025ff4a156dSchristos /******************************************************************************
1026ff4a156dSchristos  *
1027124f4c82Sjruoho  * FUNCTION:    DtWriteFieldToListing
1028124f4c82Sjruoho  *
1029124f4c82Sjruoho  * PARAMETERS:  Buffer              - Contains the compiled data
1030124f4c82Sjruoho  *              Field               - Field node for the input line
1031124f4c82Sjruoho  *              Length              - Length of the output data
1032124f4c82Sjruoho  *
1033124f4c82Sjruoho  * RETURN:      None
1034124f4c82Sjruoho  *
1035124f4c82Sjruoho  * DESCRIPTION: Write one field to the listing file (if listing is enabled).
1036124f4c82Sjruoho  *
1037124f4c82Sjruoho  *****************************************************************************/
1038124f4c82Sjruoho 
1039124f4c82Sjruoho void
DtWriteFieldToListing(UINT8 * Buffer,DT_FIELD * Field,UINT32 Length)1040124f4c82Sjruoho DtWriteFieldToListing (
1041124f4c82Sjruoho     UINT8                   *Buffer,
1042124f4c82Sjruoho     DT_FIELD                *Field,
1043124f4c82Sjruoho     UINT32                  Length)
1044124f4c82Sjruoho {
1045124f4c82Sjruoho     UINT8                   FileByte;
1046124f4c82Sjruoho 
1047124f4c82Sjruoho 
10484c4e8184Schristos     if (!AslGbl_ListingFlag || !Field)
1049124f4c82Sjruoho     {
1050124f4c82Sjruoho         return;
1051124f4c82Sjruoho     }
1052124f4c82Sjruoho 
1053124f4c82Sjruoho     /* Dump the original source line */
1054124f4c82Sjruoho 
1055124f4c82Sjruoho     FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Input:  ");
1056124f4c82Sjruoho     FlSeekFile (ASL_FILE_INPUT, Field->ByteOffset);
1057124f4c82Sjruoho 
1058124f4c82Sjruoho     while (FlReadFile (ASL_FILE_INPUT, &FileByte, 1) == AE_OK)
1059124f4c82Sjruoho     {
1060124f4c82Sjruoho         FlWriteFile (ASL_FILE_LISTING_OUTPUT, &FileByte, 1);
1061124f4c82Sjruoho         if (FileByte == '\n')
1062124f4c82Sjruoho         {
1063124f4c82Sjruoho             break;
1064124f4c82Sjruoho         }
1065124f4c82Sjruoho     }
1066124f4c82Sjruoho 
1067124f4c82Sjruoho     /* Dump the line as parsed and represented internally */
1068124f4c82Sjruoho 
1069a8e4c046Sjruoho     FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Parsed: %*s : %.64s",
1070124f4c82Sjruoho         Field->Column-4, Field->Name, Field->Value);
1071124f4c82Sjruoho 
1072a8e4c046Sjruoho     if (strlen (Field->Value) > 64)
1073a8e4c046Sjruoho     {
1074a8e4c046Sjruoho         FlPrintFile (ASL_FILE_LISTING_OUTPUT, "...Additional data, length 0x%X\n",
1075783af925Schristos             (UINT32) strlen (Field->Value));
1076a8e4c046Sjruoho     }
107771e38f1dSchristos 
1078a8e4c046Sjruoho     FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n");
1079a8e4c046Sjruoho 
1080124f4c82Sjruoho     /* Dump the hex data that will be output for this field */
1081124f4c82Sjruoho 
1082124f4c82Sjruoho     DtDumpBuffer (ASL_FILE_LISTING_OUTPUT, Buffer, Field->TableOffset, Length);
1083124f4c82Sjruoho }
1084124f4c82Sjruoho 
1085124f4c82Sjruoho 
1086124f4c82Sjruoho /******************************************************************************
1087124f4c82Sjruoho  *
1088124f4c82Sjruoho  * FUNCTION:    DtWriteTableToListing
1089124f4c82Sjruoho  *
1090124f4c82Sjruoho  * PARAMETERS:  None
1091124f4c82Sjruoho  *
1092124f4c82Sjruoho  * RETURN:      None
1093124f4c82Sjruoho  *
1094124f4c82Sjruoho  * DESCRIPTION: Write the entire compiled table to the listing file
1095124f4c82Sjruoho  *              in hex format
1096124f4c82Sjruoho  *
1097124f4c82Sjruoho  *****************************************************************************/
1098124f4c82Sjruoho 
1099124f4c82Sjruoho void
DtWriteTableToListing(void)1100124f4c82Sjruoho DtWriteTableToListing (
1101124f4c82Sjruoho     void)
1102124f4c82Sjruoho {
1103124f4c82Sjruoho     UINT8                   *Buffer;
1104124f4c82Sjruoho 
1105124f4c82Sjruoho 
11064c4e8184Schristos     if (!AslGbl_ListingFlag)
1107124f4c82Sjruoho     {
1108124f4c82Sjruoho         return;
1109124f4c82Sjruoho     }
1110124f4c82Sjruoho 
1111124f4c82Sjruoho     /* Read the entire table from the output file */
1112124f4c82Sjruoho 
11134c4e8184Schristos     Buffer = UtLocalCalloc (AslGbl_TableLength);
1114124f4c82Sjruoho     FlSeekFile (ASL_FILE_AML_OUTPUT, 0);
11154c4e8184Schristos     FlReadFile (ASL_FILE_AML_OUTPUT, Buffer, AslGbl_TableLength);
1116124f4c82Sjruoho 
1117124f4c82Sjruoho     /* Dump the raw table data */
1118124f4c82Sjruoho 
11194c4e8184Schristos     AcpiOsRedirectOutput (AslGbl_Files[ASL_FILE_LISTING_OUTPUT].Handle);
1120124f4c82Sjruoho 
1121124f4c82Sjruoho     AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n",
11224c4e8184Schristos         ACPI_RAW_TABLE_DATA_HEADER, AslGbl_TableLength, AslGbl_TableLength);
11234c4e8184Schristos     AcpiUtDumpBuffer (Buffer, AslGbl_TableLength, DB_BYTE_DISPLAY, 0);
1124124f4c82Sjruoho 
1125124f4c82Sjruoho     AcpiOsRedirectOutput (stdout);
1126ff4a156dSchristos     ACPI_FREE (Buffer);
1127124f4c82Sjruoho }
1128