dtio.c (212761) | dtio.c (217365) |
---|---|
1/****************************************************************************** 2 * 3 * Module Name: dtio.c - File I/O support for data table compiler 4 * 5 *****************************************************************************/ 6 | 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 * 11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. | 7/* 8 * Copyright (C) 2000 - 2011, Intel Corp. |
12 * All rights reserved. 13 * | 9 * All rights reserved. 10 * |
14 * 2. License | 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. |
15 * | 25 * |
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. | 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. |
20 * | 29 * |
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 *****************************************************************************/ | 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 */ |
115 116#define __DTIO_C__ 117 118#include <contrib/dev/acpica/compiler/aslcompiler.h> 119#include <contrib/dev/acpica/compiler/dtcompiler.h> 120 121#define _COMPONENT DT_COMPILER 122 ACPI_MODULE_NAME ("dtio") --- 4 unchanged lines hidden (view full) --- 127static char * 128DtTrim ( 129 char *String); 130 131static void 132DtLinkField ( 133 DT_FIELD *Field); 134 | 43 44#define __DTIO_C__ 45 46#include <contrib/dev/acpica/compiler/aslcompiler.h> 47#include <contrib/dev/acpica/compiler/dtcompiler.h> 48 49#define _COMPONENT DT_COMPILER 50 ACPI_MODULE_NAME ("dtio") --- 4 unchanged lines hidden (view full) --- 55static char * 56DtTrim ( 57 char *String); 58 59static void 60DtLinkField ( 61 DT_FIELD *Field); 62 |
135static void | 63static ACPI_STATUS |
136DtParseLine ( 137 char *LineBuffer, 138 UINT32 Line, 139 UINT32 Offset); 140 141static UINT32 142DtGetNextLine ( 143 FILE *Handle); 144 145static void 146DtWriteBinary ( 147 DT_SUBTABLE *Subtable, 148 void *Context, 149 void *ReturnValue); 150 | 64DtParseLine ( 65 char *LineBuffer, 66 UINT32 Line, 67 UINT32 Offset); 68 69static UINT32 70DtGetNextLine ( 71 FILE *Handle); 72 73static void 74DtWriteBinary ( 75 DT_SUBTABLE *Subtable, 76 void *Context, 77 void *ReturnValue); 78 |
79static void 80DtDumpBuffer ( 81 UINT32 FileId, 82 UINT8 *Buffer, 83 UINT32 Length); |
|
151 152/* States for DtGetNextLine */ 153 154#define DT_NORMAL_TEXT 0 155#define DT_START_QUOTED_STRING 1 156#define DT_START_COMMENT 2 157#define DT_SLASH_ASTERISK_COMMENT 3 158#define DT_SLASH_SLASH_COMMENT 4 --- 129 unchanged lines hidden (view full) --- 288/****************************************************************************** 289 * 290 * FUNCTION: DtParseLine 291 * 292 * PARAMETERS: LineBuffer - Current source code line 293 * Line - Current line number in the source 294 * Offset - Current byte offset of the line 295 * | 84 85/* States for DtGetNextLine */ 86 87#define DT_NORMAL_TEXT 0 88#define DT_START_QUOTED_STRING 1 89#define DT_START_COMMENT 2 90#define DT_SLASH_ASTERISK_COMMENT 3 91#define DT_SLASH_SLASH_COMMENT 4 --- 129 unchanged lines hidden (view full) --- 221/****************************************************************************** 222 * 223 * FUNCTION: DtParseLine 224 * 225 * PARAMETERS: LineBuffer - Current source code line 226 * Line - Current line number in the source 227 * Offset - Current byte offset of the line 228 * |
296 * RETURN: None | 229 * RETURN: Status |
297 * 298 * DESCRIPTION: Parse one source line 299 * 300 *****************************************************************************/ 301 | 230 * 231 * DESCRIPTION: Parse one source line 232 * 233 *****************************************************************************/ 234 |
302static void | 235static ACPI_STATUS |
303DtParseLine ( 304 char *LineBuffer, 305 UINT32 Line, 306 UINT32 Offset) 307{ 308 char *Start; 309 char *End; 310 char *TmpName; --- 4 unchanged lines hidden (view full) --- 315 UINT32 Length; 316 DT_FIELD *Field; 317 UINT32 Column; 318 UINT32 NameColumn; 319 320 321 if (!LineBuffer) 322 { | 236DtParseLine ( 237 char *LineBuffer, 238 UINT32 Line, 239 UINT32 Offset) 240{ 241 char *Start; 242 char *End; 243 char *TmpName; --- 4 unchanged lines hidden (view full) --- 248 UINT32 Length; 249 DT_FIELD *Field; 250 UINT32 Column; 251 UINT32 NameColumn; 252 253 254 if (!LineBuffer) 255 { |
323 return; | 256 return (AE_OK); |
324 } 325 | 257 } 258 |
259 /* All lines after "Raw Table Data" are ingored */ 260 261 if (strstr (LineBuffer, ACPI_RAW_TABLE_DATA_HEADER)) 262 { 263 return (AE_NOT_FOUND); 264 } 265 |
|
326 Colon = strchr (LineBuffer, ':'); | 266 Colon = strchr (LineBuffer, ':'); |
327 if (!Colon || *(Colon - 1) != ' ') | 267 if (!Colon) |
328 { | 268 { |
329 return; | 269 return (AE_OK); |
330 } 331 332 Start = LineBuffer; 333 End = Colon; 334 335 while (Start < Colon) 336 { 337 if (*Start == ' ') --- 8 unchanged lines hidden (view full) --- 346 { 347 while (Start < Colon && *Start != ']') 348 { 349 Start++; 350 } 351 352 if (Start == Colon) 353 { | 270 } 271 272 Start = LineBuffer; 273 End = Colon; 274 275 while (Start < Colon) 276 { 277 if (*Start == ' ') --- 8 unchanged lines hidden (view full) --- 286 { 287 while (Start < Colon && *Start != ']') 288 { 289 Start++; 290 } 291 292 if (Start == Colon) 293 { |
354 MYDEBUG ("ERROR: right bracket reaches colon position\n"); | |
355 break; 356 } 357 358 Start++; 359 continue; 360 } 361 362 break; --- 54 unchanged lines hidden (view full) --- 417 Field->Value = Value; 418 Field->Line = Line; 419 Field->ByteOffset = Offset; 420 Field->NameColumn = NameColumn; 421 Field->Column = Column; 422 423 DtLinkField (Field); 424 } | 294 break; 295 } 296 297 Start++; 298 continue; 299 } 300 301 break; --- 54 unchanged lines hidden (view full) --- 356 Field->Value = Value; 357 Field->Line = Line; 358 Field->ByteOffset = Offset; 359 Field->NameColumn = NameColumn; 360 Field->Column = Column; 361 362 DtLinkField (Field); 363 } |
364 365 return (AE_OK); |
|
425} 426 427 428/****************************************************************************** 429 * 430 * FUNCTION: DtGetNextLine 431 * 432 * PARAMETERS: Handle - Open file handle for the source file --- 175 unchanged lines hidden (view full) --- 608 * to the global parse tree: Gbl_FieldList 609 * 610 *****************************************************************************/ 611 612DT_FIELD * 613DtScanFile ( 614 FILE *Handle) 615{ | 366} 367 368 369/****************************************************************************** 370 * 371 * FUNCTION: DtGetNextLine 372 * 373 * PARAMETERS: Handle - Open file handle for the source file --- 175 unchanged lines hidden (view full) --- 549 * to the global parse tree: Gbl_FieldList 550 * 551 *****************************************************************************/ 552 553DT_FIELD * 554DtScanFile ( 555 FILE *Handle) 556{ |
557 ACPI_STATUS Status; |
|
616 UINT32 Offset; 617 618 619 ACPI_FUNCTION_NAME (DtScanFile); 620 621 622 /* Get the file size */ 623 --- 5 unchanged lines hidden (view full) --- 629 630 /* Scan line-by-line */ 631 632 while ((Offset = DtGetNextLine (Handle))) 633 { 634 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", 635 Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); 636 | 558 UINT32 Offset; 559 560 561 ACPI_FUNCTION_NAME (DtScanFile); 562 563 564 /* Get the file size */ 565 --- 5 unchanged lines hidden (view full) --- 571 572 /* Scan line-by-line */ 573 574 while ((Offset = DtGetNextLine (Handle))) 575 { 576 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Line %2.2u/%4.4X - %s", 577 Gbl_CurrentLineNumber, Offset, Gbl_CurrentLineBuffer)); 578 |
637 DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); | 579 Status = DtParseLine (Gbl_CurrentLineBuffer, Gbl_CurrentLineNumber, Offset); 580 if (Status == AE_NOT_FOUND) 581 { 582 break; 583 } |
638 } 639 640 return (Gbl_FieldList); 641} 642 643 644/* 645 * Output functions 646 */ 647 | 584 } 585 586 return (Gbl_FieldList); 587} 588 589 590/* 591 * Output functions 592 */ 593 |
648 | |
649/****************************************************************************** 650 * 651 * FUNCTION: DtWriteBinary 652 * 653 * PARAMETERS: DT_WALK_CALLBACK 654 * 655 * RETURN: Status 656 * --- 34 unchanged lines hidden (view full) --- 691 return; 692 } 693 694 /* Walk the entire parse tree, emitting the binary data */ 695 696 DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL); 697 Gbl_TableLength = DtGetFileSize (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); 698} | 594/****************************************************************************** 595 * 596 * FUNCTION: DtWriteBinary 597 * 598 * PARAMETERS: DT_WALK_CALLBACK 599 * 600 * RETURN: Status 601 * --- 34 unchanged lines hidden (view full) --- 636 return; 637 } 638 639 /* Walk the entire parse tree, emitting the binary data */ 640 641 DtWalkTableTree (RootTable, DtWriteBinary, NULL, NULL); 642 Gbl_TableLength = DtGetFileSize (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle); 643} |
644 645 646/* 647 * Listing support 648 */ 649 650/****************************************************************************** 651 * 652 * FUNCTION: DtDumpBuffer 653 * 654 * PARAMETERS: FileID - Where to write buffer data 655 * Buffer - Buffer to dump 656 * Length - Buffer Length 657 * 658 * RETURN: None 659 * 660 * DESCRIPTION: Another copy of DumpBuffer routine (unfortunately). 661 * 662 * TBD: merge dump buffer routines 663 * 664 *****************************************************************************/ 665 666static void 667DtDumpBuffer ( 668 UINT32 FileId, 669 UINT8 *Buffer, 670 UINT32 Length) 671{ 672 UINT32 i; 673 UINT32 j; 674 UINT8 BufChar; 675 676 677 i = 0; 678 while (i < Length) 679 { 680 /* Print 16 hex chars */ 681 682 FlPrintFile (FileId, "Output: [%.3d] ", Length); 683 684 for (j = 0; j < 16;) 685 { 686 if (i + j >= Length) 687 { 688 /* Dump fill spaces */ 689 690 FlPrintFile (FileId, " "); 691 j++; 692 continue; 693 } 694 695 FlPrintFile (FileId, "%02X ", Buffer[i+j]); 696 j++; 697 } 698 699 FlPrintFile (FileId, " "); 700 for (j = 0; j < 16; j++) 701 { 702 if (i + j >= Length) 703 { 704 FlPrintFile (FileId, "\n\n"); 705 return; 706 } 707 708 BufChar = Buffer[(ACPI_SIZE) i + j]; 709 if (ACPI_IS_PRINT (BufChar)) 710 { 711 FlPrintFile (FileId, "%c", BufChar); 712 } 713 else 714 { 715 FlPrintFile (FileId, "."); 716 } 717 } 718 719 /* Done with that line. */ 720 721 FlPrintFile (FileId, "\n"); 722 i += 16; 723 } 724 725 FlPrintFile (FileId, "\n\n"); 726} 727 728 729/****************************************************************************** 730 * 731 * FUNCTION: DtWriteFieldToListing 732 * 733 * PARAMETERS: Buffer - Contains the compiled data 734 * Field - Field node for the input line 735 * Length - Length of the output data 736 * 737 * RETURN: None 738 * 739 * DESCRIPTION: Write one field to the listing file (if listing is enabled). 740 * 741 *****************************************************************************/ 742 743void 744DtWriteFieldToListing ( 745 UINT8 *Buffer, 746 DT_FIELD *Field, 747 UINT32 Length) 748{ 749 UINT8 FileByte; 750 751 752 if (!Gbl_ListingFlag || !Field) 753 { 754 return; 755 } 756 757 /* Dump the original source line */ 758 759 FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Input: "); 760 FlSeekFile (ASL_FILE_INPUT, Field->ByteOffset); 761 762 while (FlReadFile (ASL_FILE_INPUT, &FileByte, 1) == AE_OK) 763 { 764 FlWriteFile (ASL_FILE_LISTING_OUTPUT, &FileByte, 1); 765 if (FileByte == '\n') 766 { 767 break; 768 } 769 } 770 771 /* Dump the line as parsed and represented internally */ 772 773 FlPrintFile (ASL_FILE_LISTING_OUTPUT, "Parsed: %*s : %s\n", 774 Field->Column-4, Field->Name, Field->Value); 775 776#if 0 777 /* TBD Dump the length and AML offset */ 778 779 FlPrintFile (ASL_FILE_LISTING_OUTPUT, 780 "Output: Length %d(0x%X) Offset %d(0x%X)\n", 781 Field->Column-4, Field->Name, Field->Value); 782#endif 783 784 /* Dump the hex data that will be output for this field */ 785 786 DtDumpBuffer (ASL_FILE_LISTING_OUTPUT, Buffer, Length); 787} 788 789 790/****************************************************************************** 791 * 792 * FUNCTION: DtWriteTableToListing 793 * 794 * PARAMETERS: None 795 * 796 * RETURN: None 797 * 798 * DESCRIPTION: Write the entire compiled table to the listing file 799 * in hex format 800 * 801 *****************************************************************************/ 802 803void 804DtWriteTableToListing ( 805 void) 806{ 807 UINT8 *Buffer; 808 809 810 if (!Gbl_ListingFlag) 811 { 812 return; 813 } 814 815 /* Read the entire table from the output file */ 816 817 Buffer = UtLocalCalloc (Gbl_TableLength); 818 FlSeekFile (ASL_FILE_AML_OUTPUT, 0); 819 FlReadFile (ASL_FILE_AML_OUTPUT, Buffer, Gbl_TableLength); 820 821 /* Dump the raw table data */ 822 823 AcpiOsRedirectOutput (Gbl_Files[ASL_FILE_LISTING_OUTPUT].Handle); 824 825 AcpiOsPrintf ("\n%s: Length %d (0x%X)\n\n", 826 ACPI_RAW_TABLE_DATA_HEADER, Gbl_TableLength, Gbl_TableLength); 827 AcpiUtDumpBuffer2 (Buffer, Gbl_TableLength, DB_BYTE_DISPLAY); 828 829 AcpiOsRedirectOutput (stdout); 830} |
|