Rev 1498 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1498 | serge | 1 | /****************************************************************************** |
2 | * |
||
3 | * Module Name: dtio.c - File I/O support for data table compiler |
||
4 | * |
||
5 | *****************************************************************************/ |
||
6 | |||
7 | /****************************************************************************** |
||
8 | * |
||
9 | * 1. Copyright Notice |
||
10 | * |
||
2216 | Serge | 11 | * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp. |
1498 | serge | 12 | * All rights reserved. |
13 | * |
||
14 | * 2. License |
||
15 | * |
||
16 | * 2.1. This is your license from Intel Corp. under its intellectual property |
||
17 | * rights. You may have additional license terms from the party that provided |
||
18 | * you this software, covering your right to use that party's intellectual |
||
19 | * property rights. |
||
20 | * |
||
21 | * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a |
||
22 | * copy of the source code appearing in this file ("Covered Code") an |
||
23 | * irrevocable, perpetual, worldwide license under Intel's copyrights in the |
||
24 | * base code distributed originally by Intel ("Original Intel Code") to copy, |
||
25 | * make derivatives, distribute, use and display any portion of the Covered |
||
26 | * Code in any form, with the right to sublicense such rights; and |
||
27 | * |
||
28 | * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent |
||
29 | * license (with the right to sublicense), under only those claims of Intel |
||
30 | * patents that are infringed by the Original Intel Code, to make, use, sell, |
||
31 | * offer to sell, and import the Covered Code and derivative works thereof |
||
32 | * solely to the minimum extent necessary to exercise the above copyright |
||
33 | * license, and in no event shall the patent license extend to any additions |
||
34 | * to or modifications of the Original Intel Code. No other license or right |
||
35 | * is granted directly or by implication, estoppel or otherwise; |
||
36 | * |
||
37 | * The above copyright and patent license is granted only if the following |
||
38 | * conditions are met: |
||
39 | * |
||
40 | * 3. Conditions |
||
41 | * |
||
42 | * 3.1. Redistribution of Source with Rights to Further Distribute Source. |
||
43 | * Redistribution of source code of any substantial portion of the Covered |
||
44 | * Code or modification with rights to further distribute source must include |
||
45 | * the above Copyright Notice, the above License, this list of Conditions, |
||
46 | * and the following Disclaimer and Export Compliance provision. In addition, |
||
47 | * Licensee must cause all Covered Code to which Licensee contributes to |
||
48 | * contain a file documenting the changes Licensee made to create that Covered |
||
49 | * Code and the date of any change. Licensee must include in that file the |
||
50 | * documentation of any changes made by any predecessor Licensee. Licensee |
||
51 | * must include a prominent statement that the modification is derived, |
||
52 | * directly or indirectly, from Original Intel Code. |
||
53 | * |
||
54 | * 3.2. Redistribution of Source with no Rights to Further Distribute Source. |
||
55 | * Redistribution of source code of any substantial portion of the Covered |
||
56 | * Code or modification without rights to further distribute source must |
||
57 | * include the following Disclaimer and Export Compliance provision in the |
||
58 | * documentation and/or other materials provided with distribution. In |
||
59 | * addition, Licensee may not authorize further sublicense of source of any |
||
60 | * portion of the Covered Code, and must include terms to the effect that the |
||
61 | * license from Licensee to its licensee is limited to the intellectual |
||
62 | * property embodied in the software Licensee provides to its licensee, and |
||
63 | * not to intellectual property embodied in modifications its licensee may |
||
64 | * make. |
||
65 | * |
||
66 | * 3.3. Redistribution of Executable. Redistribution in executable form of any |
||
67 | * substantial portion of the Covered Code or modification must reproduce the |
||
68 | * above Copyright Notice, and the following Disclaimer and Export Compliance |
||
69 | * provision in the documentation and/or other materials provided with the |
||
70 | * distribution. |
||
71 | * |
||
72 | * 3.4. Intel retains all right, title, and interest in and to the Original |
||
73 | * Intel Code. |
||
74 | * |
||
75 | * 3.5. Neither the name Intel nor any other trademark owned or controlled by |
||
76 | * Intel shall be used in advertising or otherwise to promote the sale, use or |
||
77 | * other dealings in products derived from or relating to the Covered Code |
||
78 | * without prior written authorization from Intel. |
||
79 | * |
||
80 | * 4. Disclaimer and Export Compliance |
||
81 | * |
||
82 | * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED |
||
83 | * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE |
||
84 | * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, |
||
85 | * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY |
||
86 | * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY |
||
87 | * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A |
||
88 | * PARTICULAR PURPOSE. |
||
89 | * |
||
90 | * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES |
||
91 | * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR |
||
92 | * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, |
||
93 | * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY |
||
94 | * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL |
||
95 | * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS |
||
96 | * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY |
||
97 | * LIMITED REMEDY. |
||
98 | * |
||
99 | * 4.3. Licensee shall not export, either directly or indirectly, any of this |
||
100 | * software or system incorporating such software without first obtaining any |
||
101 | * required license or other approval from the U. S. Department of Commerce or |
||
102 | * any other agency or department of the United States Government. In the |
||
103 | * event Licensee exports any such software from the United States or |
||
104 | * re-exports any such software from a foreign destination, Licensee shall |
||
105 | * ensure that the distribution and export/re-export of the software is in |
||
106 | * compliance with all laws, regulations, orders, or other restrictions of the |
||
107 | * U.S. Export Administration Regulations. Licensee agrees that neither it nor |
||
108 | * any of its subsidiaries will export/re-export any technical data, process, |
||
109 | * software, or service, directly or indirectly, to any country for which the |
||
110 | * United States government or any agency thereof requires an export license, |
||
111 | * other governmental approval, or letter of assurance, without first obtaining |
||
112 | * such license, approval or letter. |
||
113 | * |
||
114 | *****************************************************************************/ |
||
115 | |||
116 | #define __DTIO_C__ |
||
117 | |||
118 | #include "aslcompiler.h" |
||
119 | #include "dtcompiler.h" |
||
120 | |||
121 | #define _COMPONENT DT_COMPILER |
||
122 | ACPI_MODULE_NAME ("dtio") |
||
123 | |||
124 | |||
2216 | Serge | 125 | /* Local prototypes */ |
1498 | serge | 126 | |
2216 | Serge | 127 | static char * |
128 | DtTrim ( |
||
129 | char *String); |
||
1498 | serge | 130 | |
2216 | Serge | 131 | static void |
132 | DtLinkField ( |
||
133 | DT_FIELD *Field); |
||
1498 | serge | 134 | |
2216 | Serge | 135 | static ACPI_STATUS |
136 | DtParseLine ( |
||
137 | char *LineBuffer, |
||
138 | UINT32 Line, |
||
139 | UINT32 Offset); |
||
1498 | serge | 140 | |
2216 | Serge | 141 | UINT32 |
142 | DtGetNextLine ( |
||
143 | FILE *Handle); |
||
1498 | serge | 144 | |
2216 | Serge | 145 | static void |
146 | DtWriteBinary ( |
||
147 | DT_SUBTABLE *Subtable, |
||
148 | void *Context, |
||
149 | void *ReturnValue); |
||
1498 | serge | 150 | |
2216 | Serge | 151 | static void |
152 | DtDumpBuffer ( |
||
153 | UINT32 FileId, |
||
154 | UINT8 *Buffer, |
||
155 | UINT32 Offset, |
||
156 | UINT32 Length); |
||
157 | |||
158 | |||
159 | /* States for DtGetNextLine */ |
||
160 | |||
161 | #define DT_NORMAL_TEXT 0 |
||
162 | #define DT_START_QUOTED_STRING 1 |
||
163 | #define DT_START_COMMENT 2 |
||
164 | #define DT_SLASH_ASTERISK_COMMENT 3 |
||
165 | #define DT_SLASH_SLASH_COMMENT 4 |
||
166 | #define DT_END_COMMENT 5 |
||
167 | #define DT_MERGE_LINES 6 |
||
168 | |||
169 | static UINT32 Gbl_NextLineOffset; |
||
170 | |||
171 | |||
1498 | serge | 172 | /****************************************************************************** |
173 | * |
||
174 | * FUNCTION: DtTrim |
||
175 | * |
||
176 | * PARAMETERS: String - Current source code line to trim |
||
177 | * |
||
178 | * RETURN: Trimmed line. Must be freed by caller. |
||
179 | * |
||
180 | * DESCRIPTION: Trim left and right spaces |
||
181 | * |
||
182 | *****************************************************************************/ |
||
183 | |||
184 | static char * |
||
185 | DtTrim ( |
||
186 | char *String) |
||
187 | { |
||
188 | char *Start; |
||
189 | char *End; |
||
190 | char *ReturnString; |
||
191 | ACPI_SIZE Length; |
||
192 | |||
193 | |||
194 | /* Skip lines that start with a space */ |
||
195 | |||
196 | if (!ACPI_STRCMP (String, " ")) |
||
197 | { |
||
198 | ReturnString = UtLocalCalloc (1); |
||
199 | return (ReturnString); |
||
200 | } |
||
201 | |||
202 | /* Setup pointers to start and end of input string */ |
||
203 | |||
204 | Start = String; |
||
205 | End = String + ACPI_STRLEN (String) - 1; |
||
206 | |||
207 | /* Find first non-whitespace character */ |
||
208 | |||
209 | while ((Start <= End) && ((*Start == ' ') || (*Start == '\t'))) |
||
210 | { |
||
211 | Start++; |
||
212 | } |
||
213 | |||
214 | /* Find last non-space character */ |
||
215 | |||
216 | while (End >= Start) |
||
217 | { |
||
218 | if (*End == '\r' || *End == '\n') |
||
219 | { |
||
220 | End--; |
||
221 | continue; |
||
222 | } |
||
223 | |||
224 | if (*End != ' ') |
||
225 | { |
||
226 | break; |
||
227 | } |
||
228 | |||
229 | End--; |
||
230 | } |
||
231 | |||
232 | /* Remove any quotes around the string */ |
||
233 | |||
234 | if (*Start == '\"') |
||
235 | { |
||
236 | Start++; |
||
237 | } |
||
238 | if (*End == '\"') |
||
239 | { |
||
240 | End--; |
||
241 | } |
||
242 | |||
243 | /* Create the trimmed return string */ |
||
244 | |||
245 | Length = ACPI_PTR_DIFF (End, Start) + 1; |
||
246 | ReturnString = UtLocalCalloc (Length + 1); |
||
247 | if (ACPI_STRLEN (Start)) |
||
248 | { |
||
249 | ACPI_STRNCPY (ReturnString, Start, Length); |
||
250 | } |
||
251 | |||
252 | ReturnString[Length] = 0; |
||
253 | return (ReturnString); |
||
254 | } |
||
255 | |||
256 | |||
257 | /****************************************************************************** |
||
258 | * |
||
259 | * FUNCTION: DtLinkField |
||
260 | * |
||
261 | * PARAMETERS: Field - New field object to link |
||
262 | * |
||
263 | * RETURN: None |
||
264 | * |
||
265 | * DESCRIPTION: Link one field name and value to the list |
||
266 | * |
||
267 | *****************************************************************************/ |
||
268 | |||
269 | static void |
||
270 | DtLinkField ( |
||
271 | DT_FIELD *Field) |
||
272 | { |
||
273 | DT_FIELD *Prev; |
||
274 | DT_FIELD *Next; |
||
275 | |||
276 | |||
277 | Prev = Next = Gbl_FieldList; |
||
278 | |||
279 | while (Next) |
||
280 | { |
||
281 | Prev = Next; |
||
282 | Next = Next->Next; |
||
283 | } |
||
284 | |||
285 | if (Prev) |
||
286 | { |
||
287 | Prev->Next = Field; |
||
288 | } |
||
289 | else |
||
290 | { |
||
291 | Gbl_FieldList = Field; |
||
292 | } |
||
293 | } |
||
294 | |||
295 | |||
296 | /****************************************************************************** |
||
297 | * |
||
298 | * FUNCTION: DtParseLine |
||
299 | * |
||
300 | * PARAMETERS: LineBuffer - Current source code line |
||
301 | * Line - Current line number in the source |
||
302 | * Offset - Current byte offset of the line |
||
303 | * |
||
2216 | Serge | 304 | * RETURN: Status |
1498 | serge | 305 | * |
306 | * DESCRIPTION: Parse one source line |
||
307 | * |
||
308 | *****************************************************************************/ |
||
309 | |||
2216 | Serge | 310 | static ACPI_STATUS |
1498 | serge | 311 | DtParseLine ( |
312 | char *LineBuffer, |
||
313 | UINT32 Line, |
||
314 | UINT32 Offset) |
||
315 | { |
||
316 | char *Start; |
||
317 | char *End; |
||
318 | char *TmpName; |
||
319 | char *TmpValue; |
||
320 | char *Name; |
||
321 | char *Value; |
||
322 | char *Colon; |
||
323 | UINT32 Length; |
||
324 | DT_FIELD *Field; |
||
325 | UINT32 Column; |
||
326 | UINT32 NameColumn; |
||
2216 | Serge | 327 | BOOLEAN IsNullString = FALSE; |
1498 | serge | 328 | |
329 | |||
2216 | Serge | 330 | if (!LineBuffer) |
1498 | serge | 331 | { |
2216 | Serge | 332 | return (AE_OK); |
1498 | serge | 333 | } |
334 | |||
2216 | Serge | 335 | /* All lines after "Raw Table Data" are ingored */ |
336 | |||
337 | if (strstr (LineBuffer, ACPI_RAW_TABLE_DATA_HEADER)) |
||
338 | { |
||
339 | return (AE_NOT_FOUND); |
||
340 | } |
||
341 | |||
1498 | serge | 342 | Colon = strchr (LineBuffer, ':'); |
2216 | Serge | 343 | if (!Colon) |
1498 | serge | 344 | { |
2216 | Serge | 345 | return (AE_OK); |
1498 | serge | 346 | } |
347 | |||
348 | Start = LineBuffer; |
||
349 | End = Colon; |
||
350 | |||
351 | while (Start < Colon) |
||
352 | { |
||
353 | if (*Start == ' ') |
||
354 | { |
||
355 | Start++; |
||
356 | continue; |
||
357 | } |
||
358 | |||
359 | /* Found left bracket, go to the right bracket */ |
||
360 | |||
361 | if (*Start == '[') |
||
362 | { |
||
363 | while (Start < Colon && *Start != ']') |
||
364 | { |
||
365 | Start++; |
||
366 | } |
||
367 | |||
368 | if (Start == Colon) |
||
369 | { |
||
370 | break; |
||
371 | } |
||
372 | |||
373 | Start++; |
||
374 | continue; |
||
375 | } |
||
376 | |||
377 | break; |
||
378 | } |
||
379 | |||
380 | /* |
||
381 | * There are two column values. One for the field name, |
||
382 | * and one for the field value. |
||
383 | */ |
||
384 | Column = ACPI_PTR_DIFF (Colon, LineBuffer) + 3; |
||
385 | NameColumn = ACPI_PTR_DIFF (Start, LineBuffer) + 1; |
||
386 | |||
387 | Length = ACPI_PTR_DIFF (End, Start); |
||
388 | |||
389 | TmpName = UtLocalCalloc (Length + 1); |
||
390 | ACPI_STRNCPY (TmpName, Start, Length); |
||
391 | Name = DtTrim (TmpName); |
||
392 | ACPI_FREE (TmpName); |
||
393 | |||
394 | Start = End = (Colon + 1); |
||
395 | while (*End) |
||
396 | { |
||
397 | /* Found left quotation, go to the right quotation and break */ |
||
398 | |||
399 | if (*End == '"') |
||
400 | { |
||
401 | End++; |
||
2216 | Serge | 402 | |
403 | /* Check for an explicit null string */ |
||
404 | |||
405 | if (*End == '"') |
||
1498 | serge | 406 | { |
2216 | Serge | 407 | IsNullString = TRUE; |
408 | } |
||
409 | while (*End && (*End != '"')) |
||
410 | { |
||
1498 | serge | 411 | End++; |
412 | } |
||
413 | |||
414 | End++; |
||
415 | break; |
||
416 | } |
||
417 | |||
2216 | Serge | 418 | /* |
419 | * Special "comment" fields at line end, ignore them. |
||
420 | * Note: normal slash-slash and slash-asterisk comments are |
||
421 | * stripped already by the DtGetNextLine parser. |
||
422 | * |
||
423 | * TBD: Perhaps DtGetNextLine should parse the following type |
||
424 | * of comments also. |
||
425 | */ |
||
426 | if (*End == '[') |
||
1498 | serge | 427 | { |
2216 | Serge | 428 | End--; |
1498 | serge | 429 | break; |
430 | } |
||
431 | End++; |
||
432 | } |
||
433 | |||
434 | Length = ACPI_PTR_DIFF (End, Start); |
||
435 | TmpValue = UtLocalCalloc (Length + 1); |
||
2216 | Serge | 436 | |
1498 | serge | 437 | ACPI_STRNCPY (TmpValue, Start, Length); |
438 | Value = DtTrim (TmpValue); |
||
439 | ACPI_FREE (TmpValue); |
||
440 | |||
2216 | Serge | 441 | /* Create a new field object only if we have a valid value field */ |
442 | |||
443 | if ((Value && *Value) || IsNullString) |
||
1498 | serge | 444 | { |
445 | Field = UtLocalCalloc (sizeof (DT_FIELD)); |
||
446 | Field->Name = Name; |
||
447 | Field->Value = Value; |
||
448 | Field->Line = Line; |
||
449 | Field->ByteOffset = Offset; |
||
450 | Field->NameColumn = NameColumn; |
||
451 | Field->Column = Column; |
||
452 | |||
453 | DtLinkField (Field); |
||
454 | } |
||
2216 | Serge | 455 | else /* Ignore this field, it has no valid data */ |
456 | { |
||
457 | ACPI_FREE (Name); |
||
458 | ACPI_FREE (Value); |
||
459 | } |
||
460 | |||
461 | return (AE_OK); |
||
1498 | serge | 462 | } |
463 | |||
464 | |||
465 | /****************************************************************************** |
||
466 | * |
||
2216 | Serge | 467 | * FUNCTION: DtGetNextLine |
468 | * |
||
469 | * PARAMETERS: Handle - Open file handle for the source file |
||
470 | * |
||
471 | * RETURN: Filled line buffer and offset of start-of-line (ASL_EOF on EOF) |
||
472 | * |
||
473 | * DESCRIPTION: Get the next valid source line. Removes all comments. |
||
474 | * Ignores empty lines. |
||
475 | * |
||
476 | * Handles both slash-asterisk and slash-slash comments. |
||
477 | * Also, quoted strings, but no escapes within. |
||
478 | * |
||
479 | * Line is returned in Gbl_CurrentLineBuffer. |
||
480 | * Line number in original file is returned in Gbl_CurrentLineNumber. |
||
481 | * |
||
482 | *****************************************************************************/ |
||
483 | |||
484 | UINT32 |
||
485 | DtGetNextLine ( |
||
486 | FILE *Handle) |
||
487 | { |
||
488 | BOOLEAN LineNotAllBlanks = FALSE; |
||
489 | UINT32 State = DT_NORMAL_TEXT; |
||
490 | UINT32 CurrentLineOffset; |
||
491 | UINT32 i; |
||
492 | char c; |
||
493 | |||
494 | |||
495 | for (i = 0; i < ASL_LINE_BUFFER_SIZE;) |
||
496 | { |
||
497 | c = (char) getc (Handle); |
||
498 | if (c == EOF) |
||
499 | { |
||
500 | switch (State) |
||
501 | { |
||
502 | case DT_START_QUOTED_STRING: |
||
503 | case DT_SLASH_ASTERISK_COMMENT: |
||
504 | case DT_SLASH_SLASH_COMMENT: |
||
505 | |||
506 | AcpiOsPrintf ("**** EOF within comment/string %u\n", State); |
||
507 | break; |
||
508 | |||
509 | default: |
||
510 | break; |
||
511 | } |
||
512 | |||
513 | return (ASL_EOF); |
||
514 | } |
||
515 | |||
516 | switch (State) |
||
517 | { |
||
518 | case DT_NORMAL_TEXT: |
||
519 | |||
520 | /* Normal text, insert char into line buffer */ |
||
521 | |||
522 | Gbl_CurrentLineBuffer[i] = c; |
||
523 | switch (c) |
||
524 | { |
||
525 | case '/': |
||
526 | State = DT_START_COMMENT; |
||
527 | break; |
||
528 | |||
529 | case '"': |
||
530 | State = DT_START_QUOTED_STRING; |
||
531 | LineNotAllBlanks = TRUE; |
||
532 | i++; |
||
533 | break; |
||
534 | |||
535 | case '\\': |
||
536 | /* |
||
537 | * The continuation char MUST be last char on this line. |
||
538 | * Otherwise, it will be assumed to be a valid ASL char. |
||
539 | */ |
||
540 | State = DT_MERGE_LINES; |
||
541 | break; |
||
542 | |||
543 | case '\n': |
||
544 | CurrentLineOffset = Gbl_NextLineOffset; |
||
545 | Gbl_NextLineOffset = (UINT32) ftell (Handle); |
||
546 | Gbl_CurrentLineNumber++; |
||
547 | |||
548 | /* |
||
549 | * Exit if line is complete. Ignore empty lines (only \n) |
||
550 | * or lines that contain nothing but blanks. |
||
551 | */ |
||
552 | if ((i != 0) && LineNotAllBlanks) |
||
553 | { |
||
554 | Gbl_CurrentLineBuffer[i+1] = 0; /* Terminate string */ |
||
555 | return (CurrentLineOffset); |
||
556 | } |
||
557 | |||
558 | /* Toss this line and start a new one */ |
||
559 | |||
560 | i = 0; |
||
561 | LineNotAllBlanks = FALSE; |
||
562 | break; |
||
563 | |||
564 | default: |
||
565 | if (c != ' ') |
||
566 | { |
||
567 | LineNotAllBlanks = TRUE; |
||
568 | } |
||
569 | |||
570 | i++; |
||
571 | break; |
||
572 | } |
||
573 | break; |
||
574 | |||
575 | case DT_START_QUOTED_STRING: |
||
576 | |||
577 | /* Insert raw chars until end of quoted string */ |
||
578 | |||
579 | Gbl_CurrentLineBuffer[i] = c; |
||
580 | i++; |
||
581 | |||
582 | if (c == '"') |
||
583 | { |
||
584 | State = DT_NORMAL_TEXT; |
||
585 | } |
||
586 | break; |
||
587 | |||
588 | case DT_START_COMMENT: |
||
589 | |||
590 | /* Open comment if this character is an asterisk or slash */ |
||
591 | |||
592 | switch (c) |
||
593 | { |
||
594 | case '*': |
||
595 | State = DT_SLASH_ASTERISK_COMMENT; |
||
596 | break; |
||
597 | |||
598 | case '/': |
||
599 | State = DT_SLASH_SLASH_COMMENT; |
||
600 | break; |
||
601 | |||
602 | default: /* Not a comment */ |
||
603 | i++; /* Save the preceeding slash */ |
||
604 | Gbl_CurrentLineBuffer[i] = c; |
||
605 | i++; |
||
606 | State = DT_NORMAL_TEXT; |
||
607 | break; |
||
608 | } |
||
609 | break; |
||
610 | |||
611 | case DT_SLASH_ASTERISK_COMMENT: |
||
612 | |||
613 | /* Ignore chars until an asterisk-slash is found */ |
||
614 | |||
615 | switch (c) |
||
616 | { |
||
617 | case '\n': |
||
618 | Gbl_NextLineOffset = (UINT32) ftell (Handle); |
||
619 | Gbl_CurrentLineNumber++; |
||
620 | break; |
||
621 | |||
622 | case '*': |
||
623 | State = DT_END_COMMENT; |
||
624 | break; |
||
625 | |||
626 | default: |
||
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 | State = DT_NORMAL_TEXT; |
||
652 | break; |
||
653 | |||
654 | case '\n': |
||
655 | CurrentLineOffset = Gbl_NextLineOffset; |
||
656 | Gbl_NextLineOffset = (UINT32) ftell (Handle); |
||
657 | Gbl_CurrentLineNumber++; |
||
658 | break; |
||
659 | |||
660 | case '*': |
||
661 | /* Consume all adjacent asterisks */ |
||
662 | break; |
||
663 | |||
664 | default: |
||
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 | DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, "Unknown input state"); |
||
704 | return (ASL_EOF); |
||
705 | } |
||
706 | } |
||
707 | |||
708 | printf ("ERROR - Input line is too long (max %u)\n", ASL_LINE_BUFFER_SIZE); |
||
709 | return (ASL_EOF); |
||
710 | } |
||
711 | |||
712 | |||
713 | /****************************************************************************** |
||
714 | * |
||
1498 | serge | 715 | * FUNCTION: DtScanFile |
716 | * |
||
717 | * PARAMETERS: Handle - Open file handle for the source file |
||
718 | * |
||
719 | * RETURN: Pointer to start of the constructed parse tree. |
||
720 | * |
||
2216 | Serge | 721 | * DESCRIPTION: Scan source file, link all field names and values |
1498 | serge | 722 | * to the global parse tree: Gbl_FieldList |
723 | * |
||
724 | *****************************************************************************/ |
||
725 | |||
726 | DT_FIELD * |
||
727 | DtScanFile ( |
||
728 | FILE *Handle) |
||
729 | { |
||
2216 | Serge | 730 | ACPI_STATUS Status; |
731 | UINT32 Offset; |
||
732 | DT_FIELD *Next; |
||
1498 | serge | 733 | |
734 | |||
2216 | Serge | 735 | ACPI_FUNCTION_NAME (DtScanFile); |
736 | |||
737 | |||
1498 | serge | 738 | /* Get the file size */ |
739 | |||
740 | Gbl_InputByteCount = DtGetFileSize (Handle); |
||
741 | |||
2216 | Serge | 742 | Gbl_CurrentLineNumber = 0; |
743 | Gbl_CurrentLineOffset = 0; |
||
744 | Gbl_NextLineOffset = 0; |
||
745 | |||
1498 | serge | 746 | /* Scan line-by-line */ |
747 | |||
2216 | Serge | 748 | while ((Offset = DtGetNextLine (Handle)) != ASL_EOF) |
1498 | serge | 749 | { |
2216 | Serge | 750 | ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", |
751 | Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); |
||
1498 | serge | 752 | |
2216 | Serge | 753 | Status = DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); |
754 | if (Status == AE_NOT_FOUND) |
||
755 | { |
||
756 | break; |
||
757 | } |
||
1498 | serge | 758 | } |
759 | |||
2216 | Serge | 760 | /* Dump the parse tree if debug enabled */ |
761 | |||
762 | if (Gbl_DebugFlag) |
||
763 | { |
||
764 | Next = Gbl_FieldList; |
||
765 | DbgPrint (ASL_DEBUG_OUTPUT, "Tree: %32s %32s %8s %8s %8s %8s %8s %8s\n\n", |
||
766 | "Name", "Value", "Line", "ByteOff", "NameCol", "Column", "TableOff", "Flags"); |
||
767 | |||
768 | while (Next) |
||
769 | { |
||
770 | DbgPrint (ASL_DEBUG_OUTPUT, "Field: %32.32s %32.32s %.8X %.8X %.8X %.8X %.8X %.8X\n", |
||
771 | Next->Name, |
||
772 | Next->Value, |
||
773 | Next->Line, |
||
774 | Next->ByteOffset, |
||
775 | Next->NameColumn, |
||
776 | Next->Column, |
||
777 | Next->TableOffset, |
||
778 | Next->Flags); |
||
779 | |||
780 | Next = Next->Next; |
||
781 | } |
||
782 | } |
||
783 | |||
1498 | serge | 784 | return (Gbl_FieldList); |
785 | } |
||
786 | |||
787 | |||
788 | /* |
||
789 | * Output functions |
||
790 | */ |
||
791 | |||
792 | /****************************************************************************** |
||
793 | * |
||
794 | * FUNCTION: DtWriteBinary |
||
795 | * |
||
796 | * PARAMETERS: DT_WALK_CALLBACK |
||
797 | * |
||
798 | * RETURN: Status |
||
799 | * |
||
800 | * DESCRIPTION: Write one subtable of a binary ACPI table |
||
801 | * |
||
802 | *****************************************************************************/ |
||
803 | |||
804 | static void |
||
805 | DtWriteBinary ( |
||
806 | DT_SUBTABLE *Subtable, |
||
807 | void *Context, |
||
808 | void *ReturnValue) |
||
809 | { |
||
810 | |||
811 | FlWriteFile (ASL_FILE_AML_OUTPUT, Subtable->Buffer, Subtable->Length); |
||
812 | } |
||
813 | |||
814 | |||
815 | /****************************************************************************** |
||
816 | * |
||
817 | * FUNCTION: DtOutputBinary |
||
818 | * |
||
819 | * PARAMETERS: |
||
820 | * |
||
821 | * RETURN: Status |
||
822 | * |
||
823 | * DESCRIPTION: Write entire binary ACPI table (result of compilation) |
||
824 | * |
||
825 | *****************************************************************************/ |
||
826 | |||
827 | void |
||
828 | DtOutputBinary ( |
||
829 | DT_SUBTABLE *RootTable) |
||
830 | { |
||
831 | |||
832 | if (!RootTable) |
||
833 | { |
||
834 | return; |
||
835 | } |
||
836 | |||
837 | /* Walk the entire parse tree, emitting the binary data */ |
||
838 | |||
839 | DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL); |
||
840 | Gbl_TableLength = DtGetFileSize (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); |
||
841 | } |
||
2216 | Serge | 842 | |
843 | |||
844 | /* |
||
845 | * Listing support |
||
846 | */ |
||
847 | |||
848 | /****************************************************************************** |
||
849 | * |
||
850 | * FUNCTION: DtDumpBuffer |
||
851 | * |
||
852 | * PARAMETERS: FileID - Where to write buffer data |
||
853 | * Buffer - Buffer to dump |
||
854 | * Offset - Offset in current table |
||
855 | * Length - Buffer Length |
||
856 | * |
||
857 | * RETURN: None |
||
858 | * |
||
859 | * DESCRIPTION: Another copy of DumpBuffer routine (unfortunately). |
||
860 | * |
||
861 | * TBD: merge dump buffer routines |
||
862 | * |
||
863 | *****************************************************************************/ |
||
864 | |||
865 | static void |
||
866 | DtDumpBuffer ( |
||
867 | UINT32 FileId, |
||
868 | UINT8 *Buffer, |
||
869 | UINT32 Offset, |
||
870 | UINT32 Length) |
||
871 | { |
||
872 | UINT32 i; |
||
873 | UINT32 j; |
||
874 | UINT8 BufChar; |
||
875 | |||
876 | |||
877 | FlPrintFile (FileId, "Output: [%3.3Xh %4.4d %3d] ", |
||
878 | Offset, Offset, Length); |
||
879 | |||
880 | i = 0; |
||
881 | while (i < Length) |
||
882 | { |
||
883 | if (i >= 16) |
||
884 | { |
||
885 | FlPrintFile (FileId, "%24s", ""); |
||
886 | } |
||
887 | |||
888 | /* Print 16 hex chars */ |
||
889 | |||
890 | for (j = 0; j < 16;) |
||
891 | { |
||
892 | if (i + j >= Length) |
||
893 | { |
||
894 | /* Dump fill spaces */ |
||
895 | |||
896 | FlPrintFile (FileId, " "); |
||
897 | j++; |
||
898 | continue; |
||
899 | } |
||
900 | |||
901 | FlPrintFile (FileId, "%02X ", Buffer[i+j]); |
||
902 | j++; |
||
903 | } |
||
904 | |||
905 | FlPrintFile (FileId, " "); |
||
906 | for (j = 0; j < 16; j++) |
||
907 | { |
||
908 | if (i + j >= Length) |
||
909 | { |
||
910 | FlPrintFile (FileId, "\n\n"); |
||
911 | return; |
||
912 | } |
||
913 | |||
914 | BufChar = Buffer[(ACPI_SIZE) i + j]; |
||
915 | if (ACPI_IS_PRINT (BufChar)) |
||
916 | { |
||
917 | FlPrintFile (FileId, "%c", BufChar); |
||
918 | } |
||
919 | else |
||
920 | { |
||
921 | FlPrintFile (FileId, "."); |
||
922 | } |
||
923 | } |
||
924 | |||
925 | /* Done with that line. */ |
||
926 | |||
927 | FlPrintFile (FileId, "\n"); |
||
928 | i += 16; |
||
929 | } |
||
930 | |||
931 | FlPrintFile (FileId, "\n\n"); |
||
932 | } |
||
933 | |||
934 | |||
935 | /****************************************************************************** |
||
936 | * |
||
937 | * FUNCTION: DtWriteFieldToListing |
||
938 | * |
||
939 | * PARAMETERS: Buffer - Contains the compiled data |
||
940 | * Field - Field node for the input line |
||
941 | * Length - Length of the output data |
||
942 | * |
||
943 | * RETURN: None |
||
944 | * |
||
945 | * DESCRIPTION: Write one field to the listing file (if listing is enabled). |
||
946 | * |
||
947 | *****************************************************************************/ |
||
948 | |||
949 | void |
||
950 | DtWriteFieldToListing ( |
||
951 | UINT8 *Buffer, |
||
952 | DT_FIELD *Field, |
||
953 | UINT32 Length) |
||
954 | { |
||
955 | UINT8 FileByte; |
||
956 | |||
957 | |||
958 | if (!Gbl_ListingFlag || !Field) |
||
959 | { |
||
960 | return; |
||
961 | } |
||
962 | |||
963 | /* Dump the original source line */ |
||
964 | |||
965 | FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Input: "); |
||
966 | FlSeekFile (ASL_FILE_INPUT, Field->ByteOffset); |
||
967 | |||
968 | while (FlReadFile (ASL_FILE_INPUT, &FileByte, 1) == AE_OK) |
||
969 | { |
||
970 | FlWriteFile (ASL_FILE_LISTING_OUTPUT, &FileByte, 1); |
||
971 | if (FileByte == '\n') |
||
972 | { |
||
973 | break; |
||
974 | } |
||
975 | } |
||
976 | |||
977 | /* Dump the line as parsed and represented internally */ |
||
978 | |||
979 | FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Parsed: %*s : %.64s", |
||
980 | Field->Column-4, Field->Name, Field->Value); |
||
981 | |||
982 | if (strlen (Field->Value) > 64) |
||
983 | { |
||
984 | FlPrintFile (ASL_FILE_LISTING_OUTPUT, "...Additional data, length 0x%X\n", |
||
985 | strlen (Field->Value)); |
||
986 | } |
||
987 | FlPrintFile (ASL_FILE_LISTING_OUTPUT, "\n"); |
||
988 | |||
989 | /* Dump the hex data that will be output for this field */ |
||
990 | |||
991 | DtDumpBuffer (ASL_FILE_LISTING_OUTPUT, Buffer, Field->TableOffset, Length); |
||
992 | } |
||
993 | |||
994 | |||
995 | /****************************************************************************** |
||
996 | * |
||
997 | * FUNCTION: DtWriteTableToListing |
||
998 | * |
||
999 | * PARAMETERS: None |
||
1000 | * |
||
1001 | * RETURN: None |
||
1002 | * |
||
1003 | * DESCRIPTION: Write the entire compiled table to the listing file |
||
1004 | * in hex format |
||
1005 | * |
||
1006 | *****************************************************************************/ |
||
1007 | |||
1008 | void |
||
1009 | DtWriteTableToListing ( |
||
1010 | void) |
||
1011 | { |
||
1012 | UINT8 *Buffer; |
||
1013 | |||
1014 | |||
1015 | if (!Gbl_ListingFlag) |
||
1016 | { |
||
1017 | return; |
||
1018 | } |
||
1019 | |||
1020 | /* Read the entire table from the output file */ |
||
1021 | |||
1022 | Buffer = UtLocalCalloc (Gbl_TableLength); |
||
1023 | FlSeekFile (ASL_FILE_AML_OUTPUT, 0); |
||
1024 | FlReadFile (ASL_FILE_AML_OUTPUT, Buffer, Gbl_TableLength); |
||
1025 | |||
1026 | /* Dump the raw table data */ |
||
1027 | |||
1028 | AcpiOsRedirectOutput (Gbl_Files[ASL_FILE_LISTING_OUTPUT].Handle); |
||
1029 | |||
1030 | AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n", |
||
1031 | ACPI_RAW_TABLE_DATA_HEADER, Gbl_TableLength, Gbl_TableLength); |
||
1032 | AcpiUtDumpBuffer2 (Buffer, Gbl_TableLength, DB_BYTE_DISPLAY); |
||
1033 | |||
1034 | AcpiOsRedirectOutput (stdout); |
||
1035 | }>>>>>>=> |