1 /****************************************************************************** 2 * 3 * Module Name: aslutils -- compiler utilities 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp. 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 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/compiler/aslcompiler.h> 153 #include "aslcompiler.y.h" 154 #include <contrib/dev/acpica/include/acdisasm.h> 155 #include <contrib/dev/acpica/include/acnamesp.h> 156 #include <contrib/dev/acpica/include/amlcode.h> 157 #include <contrib/dev/acpica/include/acapps.h> 158 #include <sys/stat.h> 159 160 161 #define _COMPONENT ACPI_COMPILER 162 ACPI_MODULE_NAME ("aslutils") 163 164 165 /* Local prototypes */ 166 167 static void 168 UtPadNameWithUnderscores ( 169 char *NameSeg, 170 char *PaddedNameSeg); 171 172 static void 173 UtAttachNameseg ( 174 ACPI_PARSE_OBJECT *Op, 175 char *Name); 176 177 static void 178 UtDisplayErrorSummary ( 179 UINT32 FileId); 180 181 182 /******************************************************************************* 183 * 184 * FUNCTION: UtIsBigEndianMachine 185 * 186 * PARAMETERS: None 187 * 188 * RETURN: TRUE if machine is big endian 189 * FALSE if machine is little endian 190 * 191 * DESCRIPTION: Detect whether machine is little endian or big endian. 192 * 193 ******************************************************************************/ 194 195 UINT8 196 UtIsBigEndianMachine ( 197 void) 198 { 199 union { 200 UINT32 Integer; 201 UINT8 Bytes[4]; 202 } Overlay = {0xFF000000}; 203 204 205 return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */ 206 } 207 208 209 /****************************************************************************** 210 * 211 * FUNCTION: UtQueryForOverwrite 212 * 213 * PARAMETERS: Pathname - Output filename 214 * 215 * RETURN: TRUE if file does not exist or overwrite is authorized 216 * 217 * DESCRIPTION: Query for file overwrite if it already exists. 218 * 219 ******************************************************************************/ 220 221 BOOLEAN 222 UtQueryForOverwrite ( 223 char *Pathname) 224 { 225 struct stat StatInfo; 226 227 228 if (!stat (Pathname, &StatInfo)) 229 { 230 fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ", 231 Pathname); 232 233 if (getchar () != 'y') 234 { 235 return (FALSE); 236 } 237 } 238 239 return (TRUE); 240 } 241 242 243 /******************************************************************************* 244 * 245 * FUNCTION: UtNodeIsDescendantOf 246 * 247 * PARAMETERS: Node1 - Child node 248 * Node2 - Possible parent node 249 * 250 * RETURN: Boolean 251 * 252 * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise, 253 * return FALSE. Note, we assume a NULL Node2 element to be the 254 * topmost (root) scope. All nodes are descendants of the root. 255 * Note: Nodes at the same level (siblings) are not considered 256 * descendants. 257 * 258 ******************************************************************************/ 259 260 BOOLEAN 261 UtNodeIsDescendantOf ( 262 ACPI_NAMESPACE_NODE *Node1, 263 ACPI_NAMESPACE_NODE *Node2) 264 { 265 266 if (Node1 == Node2) 267 { 268 return (FALSE); 269 } 270 271 if (!Node2) 272 { 273 return (TRUE); /* All nodes descend from the root */ 274 } 275 276 /* Walk upward until the root is reached or parent is found */ 277 278 while (Node1) 279 { 280 if (Node1 == Node2) 281 { 282 return (TRUE); 283 } 284 285 Node1 = Node1->Parent; 286 } 287 288 return (FALSE); 289 } 290 291 292 /******************************************************************************* 293 * 294 * FUNCTION: UtGetParentMethod 295 * 296 * PARAMETERS: Node - Namespace node for any object 297 * 298 * RETURN: Namespace node for the parent method 299 * NULL - object is not within a method 300 * 301 * DESCRIPTION: Find the parent (owning) method node for a namespace object 302 * 303 ******************************************************************************/ 304 305 void * 306 UtGetParentMethod ( 307 ACPI_NAMESPACE_NODE *Node) 308 { 309 ACPI_NAMESPACE_NODE *ParentNode; 310 311 312 if (!Node) 313 { 314 return (NULL); 315 } 316 317 /* Walk upward until a method is found, or the root is reached */ 318 319 ParentNode = Node->Parent; 320 while (ParentNode) 321 { 322 if (ParentNode->Type == ACPI_TYPE_METHOD) 323 { 324 return (ParentNode); 325 } 326 327 ParentNode = ParentNode->Parent; 328 } 329 330 return (NULL); /* Object is not within a control method */ 331 } 332 333 334 /******************************************************************************* 335 * 336 * FUNCTION: UtDisplaySupportedTables 337 * 338 * PARAMETERS: None 339 * 340 * RETURN: None 341 * 342 * DESCRIPTION: Print all supported ACPI table names. 343 * 344 ******************************************************************************/ 345 346 void 347 UtDisplaySupportedTables ( 348 void) 349 { 350 const AH_TABLE *TableData; 351 UINT32 i; 352 353 354 printf ("\nACPI tables supported by iASL version %8.8X:\n" 355 " (Compiler, Disassembler, Template Generator)\n\n", 356 ACPI_CA_VERSION); 357 358 /* All ACPI tables with the common table header */ 359 360 printf ("\n Supported ACPI tables:\n"); 361 for (TableData = AcpiGbl_SupportedTables, i = 1; 362 TableData->Signature; TableData++, i++) 363 { 364 printf ("%8u) %s %s\n", i, 365 TableData->Signature, TableData->Description); 366 } 367 } 368 369 370 /******************************************************************************* 371 * 372 * FUNCTION: UtDisplayConstantOpcodes 373 * 374 * PARAMETERS: None 375 * 376 * RETURN: None 377 * 378 * DESCRIPTION: Print AML opcodes that can be used in constant expressions. 379 * 380 ******************************************************************************/ 381 382 void 383 UtDisplayConstantOpcodes ( 384 void) 385 { 386 UINT32 i; 387 388 389 printf ("Constant expression opcode information\n\n"); 390 391 for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++) 392 { 393 if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT) 394 { 395 printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name); 396 } 397 } 398 } 399 400 401 /******************************************************************************* 402 * 403 * FUNCTION: UtBeginEvent 404 * 405 * PARAMETERS: Name - Ascii name of this event 406 * 407 * RETURN: Event number (integer index) 408 * 409 * DESCRIPTION: Saves the current time with this event 410 * 411 ******************************************************************************/ 412 413 UINT8 414 UtBeginEvent ( 415 char *Name) 416 { 417 418 if (AslGbl_NextEvent >= ASL_NUM_EVENTS) 419 { 420 AcpiOsPrintf ("Ran out of compiler event structs!\n"); 421 return (AslGbl_NextEvent); 422 } 423 424 /* Init event with current (start) time */ 425 426 AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer (); 427 AslGbl_Events[AslGbl_NextEvent].EventName = Name; 428 AslGbl_Events[AslGbl_NextEvent].Valid = TRUE; 429 return (AslGbl_NextEvent++); 430 } 431 432 433 /******************************************************************************* 434 * 435 * FUNCTION: UtEndEvent 436 * 437 * PARAMETERS: Event - Event number (integer index) 438 * 439 * RETURN: None 440 * 441 * DESCRIPTION: Saves the current time (end time) with this event 442 * 443 ******************************************************************************/ 444 445 void 446 UtEndEvent ( 447 UINT8 Event) 448 { 449 450 if (Event >= ASL_NUM_EVENTS) 451 { 452 return; 453 } 454 455 /* Insert end time for event */ 456 457 AslGbl_Events[Event].EndTime = AcpiOsGetTimer (); 458 } 459 460 461 /******************************************************************************* 462 * 463 * FUNCTION: DbgPrint 464 * 465 * PARAMETERS: Type - Type of output 466 * Fmt - Printf format string 467 * ... - variable printf list 468 * 469 * RETURN: None 470 * 471 * DESCRIPTION: Conditional print statement. Prints to stderr only if the 472 * debug flag is set. 473 * 474 ******************************************************************************/ 475 476 void 477 DbgPrint ( 478 UINT32 Type, 479 char *Fmt, 480 ...) 481 { 482 va_list Args; 483 484 485 if (!AslGbl_DebugFlag) 486 { 487 return; 488 } 489 490 if ((Type == ASL_PARSE_OUTPUT) && 491 (!(AslCompilerdebug))) 492 { 493 return; 494 } 495 496 va_start (Args, Fmt); 497 (void) vfprintf (stderr, Fmt, Args); 498 va_end (Args); 499 return; 500 } 501 502 503 /******************************************************************************* 504 * 505 * FUNCTION: UtSetParseOpName 506 * 507 * PARAMETERS: Op - Parse op to be named. 508 * 509 * RETURN: None 510 * 511 * DESCRIPTION: Insert the ascii name of the parse opcode 512 * 513 ******************************************************************************/ 514 515 void 516 UtSetParseOpName ( 517 ACPI_PARSE_OBJECT *Op) 518 { 519 520 AcpiUtSafeStrncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode), 521 ACPI_MAX_PARSEOP_NAME); 522 } 523 524 525 /******************************************************************************* 526 * 527 * FUNCTION: UtDisplayOneSummary 528 * 529 * PARAMETERS: FileID - ID of outpout file 530 * 531 * RETURN: None 532 * 533 * DESCRIPTION: Display compilation statistics for one input file 534 * 535 ******************************************************************************/ 536 537 void 538 UtDisplayOneSummary ( 539 UINT32 FileId, 540 BOOLEAN DisplayErrorSummary) 541 { 542 UINT32 i; 543 ASL_GLOBAL_FILE_NODE *FileNode; 544 BOOLEAN DisplayAMLSummary; 545 546 547 DisplayAMLSummary = 548 !AslGbl_PreprocessOnly && !AslGbl_ParserErrorDetected && 549 ((AslGbl_ExceptionCount[ASL_ERROR] == 0) || AslGbl_IgnoreErrors) && 550 AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle; 551 552 if (FileId != ASL_FILE_STDOUT) 553 { 554 /* Compiler name and version number */ 555 556 FlPrintFile (FileId, "%s version %X\n\n", 557 ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION); 558 } 559 560 /* Summary of main input and output files */ 561 562 if (AslGbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 563 { 564 FlPrintFile (FileId, 565 "%-14s %s - %u lines, %u bytes, %u fields\n", 566 "Table Input:", 567 AslGbl_Files[ASL_FILE_INPUT].Filename, AslGbl_CurrentLineNumber, 568 AslGbl_InputByteCount, AslGbl_InputFieldCount); 569 570 if ((AslGbl_ExceptionCount[ASL_ERROR] == 0) || (AslGbl_IgnoreErrors)) 571 { 572 FlPrintFile (FileId, 573 "%-14s %s - %u bytes\n", 574 "Binary Output:", 575 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename, AslGbl_TableLength); 576 } 577 } 578 else 579 { 580 FileNode = FlGetCurrentFileNode (); 581 if (!FileNode) 582 { 583 fprintf (stderr, "Summary could not be generated"); 584 return; 585 } 586 if (FileNode->ParserErrorDetected) 587 { 588 FlPrintFile (FileId, 589 "%-14s %s - Compilation aborted due to parser-detected syntax error(s)\n", 590 "ASL Input:", AslGbl_Files[ASL_FILE_INPUT].Filename); 591 } 592 else 593 { 594 FlPrintFile (FileId, 595 "%-14s %s - %7u bytes %6u keywords %6u source lines\n", 596 "ASL Input:", 597 AslGbl_Files[ASL_FILE_INPUT].Filename, 598 FileNode->OriginalInputFileSize, 599 FileNode->TotalKeywords, 600 FileNode->TotalLineCount); 601 602 /* AML summary */ 603 604 if (DisplayAMLSummary) 605 { 606 FlPrintFile (FileId, 607 "%-14s %s - %7u bytes %6u opcodes %6u named objects\n", 608 "AML Output:", 609 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename, 610 FlGetFileSize (ASL_FILE_AML_OUTPUT), 611 FileNode->TotalExecutableOpcodes, 612 FileNode->TotalNamedObjects); 613 } 614 } 615 } 616 617 /* Display summary of any optional files */ 618 619 for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++) 620 { 621 if (!AslGbl_Files[i].Filename || !AslGbl_Files[i].Handle) 622 { 623 continue; 624 } 625 626 /* .SRC is a temp file unless specifically requested */ 627 628 if ((i == ASL_FILE_SOURCE_OUTPUT) && (!AslGbl_SourceOutputFlag)) 629 { 630 continue; 631 } 632 633 /* .PRE is the preprocessor intermediate file */ 634 635 if ((i == ASL_FILE_PREPROCESSOR) && (!AslGbl_KeepPreprocessorTempFile)) 636 { 637 continue; 638 } 639 640 FlPrintFile (FileId, "%-14s %s - %7u bytes\n", 641 AslGbl_FileDescs[i].ShortDescription, 642 AslGbl_Files[i].Filename, FlGetFileSize (i)); 643 } 644 645 646 /* 647 * Optionally emit an error summary for a file. This is used to enhance the 648 * appearance of listing files. 649 */ 650 if (DisplayErrorSummary) 651 { 652 UtDisplayErrorSummary (FileId); 653 } 654 } 655 656 657 /******************************************************************************* 658 * 659 * FUNCTION: UtDisplayErrorSummary 660 * 661 * PARAMETERS: FileID - ID of outpout file 662 * 663 * RETURN: None 664 * 665 * DESCRIPTION: Display compilation statistics for all input files 666 * 667 ******************************************************************************/ 668 669 static void 670 UtDisplayErrorSummary ( 671 UINT32 FileId) 672 { 673 BOOLEAN ErrorDetected; 674 675 676 ErrorDetected = AslGbl_ParserErrorDetected || 677 ((AslGbl_ExceptionCount[ASL_ERROR] > 0) && !AslGbl_IgnoreErrors); 678 679 if (ErrorDetected) 680 { 681 FlPrintFile (FileId, "\nCompilation failed. "); 682 } 683 else 684 { 685 FlPrintFile (FileId, "\nCompilation successful. "); 686 } 687 688 FlPrintFile (FileId, 689 "%u Errors, %u Warnings, %u Remarks", 690 AslGbl_ExceptionCount[ASL_ERROR], 691 AslGbl_ExceptionCount[ASL_WARNING] + 692 AslGbl_ExceptionCount[ASL_WARNING2] + 693 AslGbl_ExceptionCount[ASL_WARNING3], 694 AslGbl_ExceptionCount[ASL_REMARK]); 695 696 if (AslGbl_FileType != ASL_INPUT_TYPE_ASCII_DATA) 697 { 698 if (AslGbl_ParserErrorDetected) 699 { 700 FlPrintFile (FileId, 701 "\nNo AML files were generated due to syntax error(s)\n"); 702 return; 703 } 704 else if (ErrorDetected) 705 { 706 FlPrintFile (FileId, 707 "\nNo AML files were generated due to compiler error(s)\n"); 708 return; 709 } 710 711 FlPrintFile (FileId, ", %u Optimizations", 712 AslGbl_ExceptionCount[ASL_OPTIMIZATION]); 713 714 if (AslGbl_TotalFolds) 715 { 716 FlPrintFile (FileId, ", %u Constants Folded", AslGbl_TotalFolds); 717 } 718 } 719 720 FlPrintFile (FileId, "\n"); 721 } 722 723 724 /******************************************************************************* 725 * 726 * FUNCTION: UtDisplaySummary 727 * 728 * PARAMETERS: FileID - ID of outpout file 729 * 730 * RETURN: None 731 * 732 * DESCRIPTION: Display compilation statistics for all input files 733 * 734 ******************************************************************************/ 735 736 void 737 UtDisplaySummary ( 738 UINT32 FileId) 739 { 740 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList; 741 742 743 while (Current) 744 { 745 switch (FlSwitchFileSet(Current->Files[ASL_FILE_INPUT].Filename)) 746 { 747 case SWITCH_TO_SAME_FILE: 748 case SWITCH_TO_DIFFERENT_FILE: 749 750 UtDisplayOneSummary (FileId, FALSE); 751 Current = Current->Next; 752 break; 753 754 case FILE_NOT_FOUND: 755 default: 756 757 Current = NULL; 758 break; 759 } 760 } 761 UtDisplayErrorSummary (FileId); 762 } 763 764 /******************************************************************************* 765 * 766 * FUNCTION: UtCheckIntegerRange 767 * 768 * PARAMETERS: Op - Integer parse node 769 * LowValue - Smallest allowed value 770 * HighValue - Largest allowed value 771 * 772 * RETURN: Op if OK, otherwise NULL 773 * 774 * DESCRIPTION: Check integer for an allowable range 775 * 776 ******************************************************************************/ 777 778 ACPI_PARSE_OBJECT * 779 UtCheckIntegerRange ( 780 ACPI_PARSE_OBJECT *Op, 781 UINT32 LowValue, 782 UINT32 HighValue) 783 { 784 785 if (!Op) 786 { 787 return (NULL); 788 } 789 790 if ((Op->Asl.Value.Integer < LowValue) || 791 (Op->Asl.Value.Integer > HighValue)) 792 { 793 sprintf (AslGbl_MsgBuffer, "0x%X, allowable: 0x%X-0x%X", 794 (UINT32) Op->Asl.Value.Integer, LowValue, HighValue); 795 796 AslError (ASL_ERROR, ASL_MSG_RANGE, Op, AslGbl_MsgBuffer); 797 return (NULL); 798 } 799 800 return (Op); 801 } 802 803 804 /******************************************************************************* 805 * 806 * FUNCTION: UtInternalizeName 807 * 808 * PARAMETERS: ExternalName - Name to convert 809 * ConvertedName - Where the converted name is returned 810 * 811 * RETURN: Status 812 * 813 * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name 814 * 815 ******************************************************************************/ 816 817 ACPI_STATUS 818 UtInternalizeName ( 819 char *ExternalName, 820 char **ConvertedName) 821 { 822 ACPI_NAMESTRING_INFO Info; 823 ACPI_STATUS Status; 824 825 826 if (!ExternalName) 827 { 828 return (AE_OK); 829 } 830 831 /* Get the length of the new internal name */ 832 833 Info.ExternalName = ExternalName; 834 AcpiNsGetInternalNameLength (&Info); 835 836 /* We need a segment to store the internal name */ 837 838 Info.InternalName = UtLocalCacheCalloc (Info.Length); 839 840 /* Build the name */ 841 842 Status = AcpiNsBuildInternalName (&Info); 843 if (ACPI_FAILURE (Status)) 844 { 845 return (Status); 846 } 847 848 *ConvertedName = Info.InternalName; 849 return (AE_OK); 850 } 851 852 853 /******************************************************************************* 854 * 855 * FUNCTION: UtPadNameWithUnderscores 856 * 857 * PARAMETERS: NameSeg - Input nameseg 858 * PaddedNameSeg - Output padded nameseg 859 * 860 * RETURN: Padded nameseg. 861 * 862 * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full 863 * ACPI_NAME. 864 * 865 ******************************************************************************/ 866 867 static void 868 UtPadNameWithUnderscores ( 869 char *NameSeg, 870 char *PaddedNameSeg) 871 { 872 UINT32 i; 873 874 875 for (i = 0; (i < ACPI_NAMESEG_SIZE); i++) 876 { 877 if (*NameSeg) 878 { 879 *PaddedNameSeg = *NameSeg; 880 NameSeg++; 881 } 882 else 883 { 884 *PaddedNameSeg = '_'; 885 } 886 887 PaddedNameSeg++; 888 } 889 } 890 891 892 /******************************************************************************* 893 * 894 * FUNCTION: UtAttachNameseg 895 * 896 * PARAMETERS: Op - Parent parse node 897 * Name - Full ExternalName 898 * 899 * RETURN: None; Sets the NameSeg field in parent node 900 * 901 * DESCRIPTION: Extract the last nameseg of the ExternalName and store it 902 * in the NameSeg field of the Op. 903 * 904 ******************************************************************************/ 905 906 static void 907 UtAttachNameseg ( 908 ACPI_PARSE_OBJECT *Op, 909 char *Name) 910 { 911 char *NameSeg; 912 char PaddedNameSeg[4]; 913 914 915 if (!Name) 916 { 917 return; 918 } 919 920 /* Look for the last dot in the namepath */ 921 922 NameSeg = strrchr (Name, '.'); 923 if (NameSeg) 924 { 925 /* Found last dot, we have also found the final nameseg */ 926 927 NameSeg++; 928 UtPadNameWithUnderscores (NameSeg, PaddedNameSeg); 929 } 930 else 931 { 932 /* No dots in the namepath, there is only a single nameseg. */ 933 /* Handle prefixes */ 934 935 while (ACPI_IS_ROOT_PREFIX (*Name) || 936 ACPI_IS_PARENT_PREFIX (*Name)) 937 { 938 Name++; 939 } 940 941 /* Remaining string should be one single nameseg */ 942 943 UtPadNameWithUnderscores (Name, PaddedNameSeg); 944 } 945 946 ACPI_COPY_NAMESEG (Op->Asl.NameSeg, PaddedNameSeg); 947 } 948 949 950 /******************************************************************************* 951 * 952 * FUNCTION: UtAttachNamepathToOwner 953 * 954 * PARAMETERS: Op - Parent parse node 955 * NameOp - Node that contains the name 956 * 957 * RETURN: Sets the ExternalName and Namepath in the parent node 958 * 959 * DESCRIPTION: Store the name in two forms in the parent node: The original 960 * (external) name, and the internalized name that is used within 961 * the ACPI namespace manager. 962 * 963 ******************************************************************************/ 964 965 void 966 UtAttachNamepathToOwner ( 967 ACPI_PARSE_OBJECT *Op, 968 ACPI_PARSE_OBJECT *NameOp) 969 { 970 ACPI_STATUS Status; 971 972 973 /* Full external path */ 974 975 Op->Asl.ExternalName = NameOp->Asl.Value.String; 976 977 /* Save the NameOp for possible error reporting later */ 978 979 Op->Asl.ParentMethod = (void *) NameOp; 980 981 /* Last nameseg of the path */ 982 983 UtAttachNameseg (Op, Op->Asl.ExternalName); 984 985 /* Create internalized path */ 986 987 Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath); 988 if (ACPI_FAILURE (Status)) 989 { 990 /* TBD: abort on no memory */ 991 } 992 } 993 994 995 /******************************************************************************* 996 * 997 * FUNCTION: UtDoConstant 998 * 999 * PARAMETERS: String - Hex/Decimal/Octal 1000 * 1001 * RETURN: Converted Integer 1002 * 1003 * DESCRIPTION: Convert a string to an integer, with overflow/error checking. 1004 * 1005 ******************************************************************************/ 1006 1007 UINT64 1008 UtDoConstant ( 1009 char *String) 1010 { 1011 ACPI_STATUS Status; 1012 UINT64 ConvertedInteger; 1013 char ErrBuf[64]; 1014 1015 1016 Status = AcpiUtStrtoul64 (String, &ConvertedInteger); 1017 if (ACPI_FAILURE (Status)) 1018 { 1019 sprintf (ErrBuf, "While creating 64-bit constant: %s\n", 1020 AcpiFormatException (Status)); 1021 1022 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, AslGbl_CurrentLineNumber, 1023 AslGbl_LogicalLineNumber, AslGbl_CurrentLineOffset, 1024 AslGbl_CurrentColumn, AslGbl_Files[ASL_FILE_INPUT].Filename, ErrBuf); 1025 } 1026 1027 return (ConvertedInteger); 1028 } 1029