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 - 2021, 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: UtIsIdInteger 212 * 213 * PARAMETERS: Pointer to an ACPI ID (HID, CID) string 214 * 215 * RETURN: TRUE if string is an integer 216 * FALSE if string is not an integer 217 * 218 * DESCRIPTION: Determine whether the input ACPI ID string can be converted to 219 * an integer value. 220 * 221 ******************************************************************************/ 222 223 BOOLEAN 224 UtIsIdInteger ( 225 UINT8 *Target) 226 { 227 UINT32 i; 228 229 230 /* The first three characters of the string must be alphabetic */ 231 232 for (i = 0; i < 3; i++) 233 { 234 if (!isalpha ((int) Target[i])) 235 { 236 break; 237 } 238 } 239 240 if (i < 3) 241 { 242 return (TRUE); 243 } 244 245 return (FALSE); 246 } 247 248 249 /****************************************************************************** 250 * 251 * FUNCTION: UtQueryForOverwrite 252 * 253 * PARAMETERS: Pathname - Output filename 254 * 255 * RETURN: TRUE if file does not exist or overwrite is authorized 256 * 257 * DESCRIPTION: Query for file overwrite if it already exists. 258 * 259 ******************************************************************************/ 260 261 BOOLEAN 262 UtQueryForOverwrite ( 263 char *Pathname) 264 { 265 struct stat StatInfo; 266 int InChar; 267 268 269 if (!stat (Pathname, &StatInfo)) 270 { 271 fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ", 272 Pathname); 273 274 InChar = fgetc (stdin); 275 if (InChar == '\n') 276 { 277 InChar = fgetc (stdin); 278 } 279 280 if ((InChar != 'y') && (InChar != 'Y')) 281 { 282 return (FALSE); 283 } 284 } 285 286 return (TRUE); 287 } 288 289 290 /******************************************************************************* 291 * 292 * FUNCTION: UtNodeIsDescendantOf 293 * 294 * PARAMETERS: Node1 - Child node 295 * Node2 - Possible parent node 296 * 297 * RETURN: Boolean 298 * 299 * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise, 300 * return FALSE. Note, we assume a NULL Node2 element to be the 301 * topmost (root) scope. All nodes are descendants of the root. 302 * Note: Nodes at the same level (siblings) are not considered 303 * descendants. 304 * 305 ******************************************************************************/ 306 307 BOOLEAN 308 UtNodeIsDescendantOf ( 309 ACPI_NAMESPACE_NODE *Node1, 310 ACPI_NAMESPACE_NODE *Node2) 311 { 312 313 if (Node1 == Node2) 314 { 315 return (FALSE); 316 } 317 318 if (!Node2) 319 { 320 return (TRUE); /* All nodes descend from the root */ 321 } 322 323 /* Walk upward until the root is reached or parent is found */ 324 325 while (Node1) 326 { 327 if (Node1 == Node2) 328 { 329 return (TRUE); 330 } 331 332 Node1 = Node1->Parent; 333 } 334 335 return (FALSE); 336 } 337 338 339 /******************************************************************************* 340 * 341 * FUNCTION: UtGetParentMethodNode 342 * 343 * PARAMETERS: Node - Namespace node for any object 344 * 345 * RETURN: Namespace node for the parent method 346 * NULL - object is not within a method 347 * 348 * DESCRIPTION: Find the parent (owning) method node for a namespace object 349 * 350 ******************************************************************************/ 351 352 ACPI_NAMESPACE_NODE * 353 UtGetParentMethodNode ( 354 ACPI_NAMESPACE_NODE *Node) 355 { 356 ACPI_NAMESPACE_NODE *ParentNode; 357 358 359 if (!Node) 360 { 361 return (NULL); 362 } 363 364 /* Walk upward until a method is found, or the root is reached */ 365 366 ParentNode = Node->Parent; 367 while (ParentNode) 368 { 369 if (ParentNode->Type == ACPI_TYPE_METHOD) 370 { 371 return (ParentNode); 372 } 373 374 ParentNode = ParentNode->Parent; 375 } 376 377 return (NULL); /* Object is not within a control method */ 378 } 379 380 381 /******************************************************************************* 382 * 383 * FUNCTION: UtGetParentMethodOp 384 * 385 * PARAMETERS: Op - Parse Op to be checked 386 * 387 * RETURN: Control method Op if found. NULL otherwise 388 * 389 * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if 390 * the input Op is not within a control method. 391 * 392 ******************************************************************************/ 393 394 ACPI_PARSE_OBJECT * 395 UtGetParentMethodOp ( 396 ACPI_PARSE_OBJECT *Op) 397 { 398 ACPI_PARSE_OBJECT *NextOp; 399 400 401 NextOp = Op->Asl.Parent; 402 while (NextOp) 403 { 404 if (NextOp->Asl.AmlOpcode == AML_METHOD_OP) 405 { 406 return (NextOp); 407 } 408 409 NextOp = NextOp->Asl.Parent; 410 } 411 412 return (NULL); /* No parent method found */ 413 } 414 415 416 /******************************************************************************* 417 * 418 * FUNCTION: UtDisplaySupportedTables 419 * 420 * PARAMETERS: None 421 * 422 * RETURN: None 423 * 424 * DESCRIPTION: Print all supported ACPI table names. 425 * 426 ******************************************************************************/ 427 428 void 429 UtDisplaySupportedTables ( 430 void) 431 { 432 const AH_TABLE *TableData; 433 UINT32 i; 434 435 436 printf ("\nACPI tables supported by iASL version %8.8X:\n" 437 " (Compiler, Disassembler, Template Generator)\n\n", 438 ACPI_CA_VERSION); 439 440 /* All ACPI tables with the common table header */ 441 442 printf ("\n Supported ACPI tables:\n"); 443 for (TableData = AcpiGbl_SupportedTables, i = 1; 444 TableData->Signature; TableData++, i++) 445 { 446 printf ("%8u) %s %s\n", i, 447 TableData->Signature, TableData->Description); 448 } 449 } 450 451 452 /******************************************************************************* 453 * 454 * FUNCTION: UtDisplayConstantOpcodes 455 * 456 * PARAMETERS: None 457 * 458 * RETURN: None 459 * 460 * DESCRIPTION: Print AML opcodes that can be used in constant expressions. 461 * 462 ******************************************************************************/ 463 464 void 465 UtDisplayConstantOpcodes ( 466 void) 467 { 468 UINT32 i; 469 470 471 printf ("Constant expression opcode information\n\n"); 472 473 for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++) 474 { 475 if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT) 476 { 477 printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name); 478 } 479 } 480 } 481 482 483 /******************************************************************************* 484 * 485 * FUNCTION: UtBeginEvent 486 * 487 * PARAMETERS: Name - Ascii name of this event 488 * 489 * RETURN: Event number (integer index) 490 * 491 * DESCRIPTION: Saves the current time with this event 492 * 493 ******************************************************************************/ 494 495 UINT8 496 UtBeginEvent ( 497 char *Name) 498 { 499 500 if (AslGbl_NextEvent >= ASL_NUM_EVENTS) 501 { 502 AcpiOsPrintf ("Ran out of compiler event structs!\n"); 503 return (AslGbl_NextEvent); 504 } 505 506 /* Init event with current (start) time */ 507 508 AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer (); 509 AslGbl_Events[AslGbl_NextEvent].EventName = Name; 510 AslGbl_Events[AslGbl_NextEvent].Valid = TRUE; 511 return (AslGbl_NextEvent++); 512 } 513 514 515 /******************************************************************************* 516 * 517 * FUNCTION: UtEndEvent 518 * 519 * PARAMETERS: Event - Event number (integer index) 520 * 521 * RETURN: None 522 * 523 * DESCRIPTION: Saves the current time (end time) with this event 524 * 525 ******************************************************************************/ 526 527 void 528 UtEndEvent ( 529 UINT8 Event) 530 { 531 532 if (Event >= ASL_NUM_EVENTS) 533 { 534 return; 535 } 536 537 /* Insert end time for event */ 538 539 AslGbl_Events[Event].EndTime = AcpiOsGetTimer (); 540 } 541 542 543 /******************************************************************************* 544 * 545 * FUNCTION: DbgPrint 546 * 547 * PARAMETERS: Type - Type of output 548 * Fmt - Printf format string 549 * ... - variable printf list 550 * 551 * RETURN: None 552 * 553 * DESCRIPTION: Conditional print statement. Prints to stderr only if the 554 * debug flag is set. 555 * 556 ******************************************************************************/ 557 558 void 559 DbgPrint ( 560 UINT32 Type, 561 char *Fmt, 562 ...) 563 { 564 va_list Args; 565 566 567 if (!AslGbl_DebugFlag) 568 { 569 return; 570 } 571 572 if ((Type == ASL_PARSE_OUTPUT) && 573 (!(AslCompilerdebug))) 574 { 575 return; 576 } 577 578 va_start (Args, Fmt); 579 (void) vfprintf (stderr, Fmt, Args); 580 va_end (Args); 581 return; 582 } 583 584 585 /******************************************************************************* 586 * 587 * FUNCTION: UtSetParseOpName 588 * 589 * PARAMETERS: Op - Parse op to be named. 590 * 591 * RETURN: None 592 * 593 * DESCRIPTION: Insert the ascii name of the parse opcode 594 * 595 ******************************************************************************/ 596 597 void 598 UtSetParseOpName ( 599 ACPI_PARSE_OBJECT *Op) 600 { 601 602 AcpiUtSafeStrncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode), 603 ACPI_MAX_PARSEOP_NAME); 604 } 605 606 607 /******************************************************************************* 608 * 609 * FUNCTION: UtDisplayOneSummary 610 * 611 * PARAMETERS: FileID - ID of outpout file 612 * 613 * RETURN: None 614 * 615 * DESCRIPTION: Display compilation statistics for one input file 616 * 617 ******************************************************************************/ 618 619 void 620 UtDisplayOneSummary ( 621 UINT32 FileId, 622 BOOLEAN DisplayErrorSummary) 623 { 624 UINT32 i; 625 ASL_GLOBAL_FILE_NODE *FileNode; 626 BOOLEAN DisplayAMLSummary; 627 628 629 DisplayAMLSummary = 630 !AslGbl_PreprocessOnly && !AslGbl_ParserErrorDetected && 631 ((AslGbl_ExceptionCount[ASL_ERROR] == 0) || AslGbl_IgnoreErrors) && 632 AslGbl_Files[ASL_FILE_AML_OUTPUT].Handle; 633 634 if (FileId != ASL_FILE_STDOUT) 635 { 636 /* Compiler name and version number */ 637 638 FlPrintFile (FileId, "%s version %X\n\n", 639 ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION); 640 } 641 642 /* Summary of main input and output files */ 643 644 FileNode = FlGetCurrentFileNode (); 645 646 if (FileNode->ParserErrorDetected) 647 { 648 FlPrintFile (FileId, 649 "%-14s %s - Compilation aborted due to parser-detected syntax error(s)\n", 650 "Input file:", AslGbl_Files[ASL_FILE_INPUT].Filename); 651 } 652 else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_DATA) 653 { 654 FlPrintFile (FileId, 655 "%-14s %s - %7u bytes %6u fields %8u source lines\n", 656 "Table Input:", 657 AslGbl_Files[ASL_FILE_INPUT].Filename, 658 FileNode->OriginalInputFileSize, FileNode->TotalFields, 659 FileNode->TotalLineCount); 660 661 FlPrintFile (FileId, 662 "%-14s %s - %7u bytes\n", 663 "Binary Output:", 664 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename, FileNode->OutputByteLength); 665 } 666 else if (FileNode->FileType == ASL_INPUT_TYPE_ASCII_ASL) 667 { 668 FlPrintFile (FileId, 669 "%-14s %s - %7u bytes %6u keywords %6u source lines\n", 670 "ASL Input:", 671 AslGbl_Files[ASL_FILE_INPUT].Filename, 672 FileNode->OriginalInputFileSize, 673 FileNode->TotalKeywords, 674 FileNode->TotalLineCount); 675 676 /* AML summary */ 677 678 if (DisplayAMLSummary) 679 { 680 FlPrintFile (FileId, 681 "%-14s %s - %7u bytes %6u opcodes %6u named objects\n", 682 "AML Output:", 683 AslGbl_Files[ASL_FILE_AML_OUTPUT].Filename, 684 FlGetFileSize (ASL_FILE_AML_OUTPUT), 685 FileNode->TotalExecutableOpcodes, 686 FileNode->TotalNamedObjects); 687 } 688 } 689 690 /* Display summary of any optional files */ 691 692 for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++) 693 { 694 if (!AslGbl_Files[i].Filename || !AslGbl_Files[i].Handle) 695 { 696 continue; 697 } 698 699 /* .SRC is a temp file unless specifically requested */ 700 701 if ((i == ASL_FILE_SOURCE_OUTPUT) && (!AslGbl_SourceOutputFlag)) 702 { 703 continue; 704 } 705 706 /* .PRE is the preprocessor intermediate file */ 707 708 if ((i == ASL_FILE_PREPROCESSOR) && (!AslGbl_KeepPreprocessorTempFile)) 709 { 710 continue; 711 } 712 713 FlPrintFile (FileId, "%-14s %s - %7u bytes\n", 714 AslGbl_FileDescs[i].ShortDescription, 715 AslGbl_Files[i].Filename, FlGetFileSize (i)); 716 } 717 718 719 /* 720 * Optionally emit an error summary for a file. This is used to enhance the 721 * appearance of listing files. 722 */ 723 if (DisplayErrorSummary) 724 { 725 UtDisplayErrorSummary (FileId); 726 } 727 } 728 729 730 /******************************************************************************* 731 * 732 * FUNCTION: UtDisplayErrorSummary 733 * 734 * PARAMETERS: FileID - ID of outpout file 735 * 736 * RETURN: None 737 * 738 * DESCRIPTION: Display compilation statistics for all input files 739 * 740 ******************************************************************************/ 741 742 static void 743 UtDisplayErrorSummary ( 744 UINT32 FileId) 745 { 746 BOOLEAN ErrorDetected; 747 748 749 ErrorDetected = AslGbl_ParserErrorDetected || 750 ((AslGbl_ExceptionCount[ASL_ERROR] > 0) && !AslGbl_IgnoreErrors); 751 752 if (ErrorDetected) 753 { 754 FlPrintFile (FileId, "\nCompilation failed. "); 755 } 756 else 757 { 758 FlPrintFile (FileId, "\nCompilation successful. "); 759 } 760 761 FlPrintFile (FileId, 762 "%u Errors, %u Warnings, %u Remarks", 763 AslGbl_ExceptionCount[ASL_ERROR], 764 AslGbl_ExceptionCount[ASL_WARNING] + 765 AslGbl_ExceptionCount[ASL_WARNING2] + 766 AslGbl_ExceptionCount[ASL_WARNING3], 767 AslGbl_ExceptionCount[ASL_REMARK]); 768 769 if (AslGbl_FileType != ASL_INPUT_TYPE_ASCII_DATA) 770 { 771 if (AslGbl_ParserErrorDetected) 772 { 773 FlPrintFile (FileId, 774 "\nNo AML files were generated due to syntax error(s)\n"); 775 return; 776 } 777 else if (ErrorDetected) 778 { 779 FlPrintFile (FileId, 780 "\nNo AML files were generated due to compiler error(s)\n"); 781 return; 782 } 783 784 FlPrintFile (FileId, ", %u Optimizations", 785 AslGbl_ExceptionCount[ASL_OPTIMIZATION]); 786 787 if (AslGbl_TotalFolds) 788 { 789 FlPrintFile (FileId, ", %u Constants Folded", AslGbl_TotalFolds); 790 } 791 } 792 793 FlPrintFile (FileId, "\n"); 794 } 795 796 797 /******************************************************************************* 798 * 799 * FUNCTION: UtDisplaySummary 800 * 801 * PARAMETERS: FileID - ID of outpout file 802 * 803 * RETURN: None 804 * 805 * DESCRIPTION: Display compilation statistics for all input files 806 * 807 ******************************************************************************/ 808 809 void 810 UtDisplaySummary ( 811 UINT32 FileId) 812 { 813 ASL_GLOBAL_FILE_NODE *Current = AslGbl_FilesList; 814 815 816 while (Current) 817 { 818 switch (FlSwitchFileSet(Current->Files[ASL_FILE_INPUT].Filename)) 819 { 820 case SWITCH_TO_SAME_FILE: 821 case SWITCH_TO_DIFFERENT_FILE: 822 823 UtDisplayOneSummary (FileId, FALSE); 824 Current = Current->Next; 825 break; 826 827 case FILE_NOT_FOUND: 828 default: 829 830 Current = NULL; 831 break; 832 } 833 } 834 UtDisplayErrorSummary (FileId); 835 } 836 837 /******************************************************************************* 838 * 839 * FUNCTION: UtCheckIntegerRange 840 * 841 * PARAMETERS: Op - Integer parse node 842 * LowValue - Smallest allowed value 843 * HighValue - Largest allowed value 844 * 845 * RETURN: Op if OK, otherwise NULL 846 * 847 * DESCRIPTION: Check integer for an allowable range 848 * 849 ******************************************************************************/ 850 851 ACPI_PARSE_OBJECT * 852 UtCheckIntegerRange ( 853 ACPI_PARSE_OBJECT *Op, 854 UINT32 LowValue, 855 UINT32 HighValue) 856 { 857 858 if (!Op) 859 { 860 return (NULL); 861 } 862 863 if ((Op->Asl.Value.Integer < LowValue) || 864 (Op->Asl.Value.Integer > HighValue)) 865 { 866 sprintf (AslGbl_MsgBuffer, "0x%X, allowable: 0x%X-0x%X", 867 (UINT32) Op->Asl.Value.Integer, LowValue, HighValue); 868 869 AslError (ASL_ERROR, ASL_MSG_RANGE, Op, AslGbl_MsgBuffer); 870 return (NULL); 871 } 872 873 return (Op); 874 } 875 876 877 /******************************************************************************* 878 * 879 * FUNCTION: UtInternalizeName 880 * 881 * PARAMETERS: ExternalName - Name to convert 882 * ConvertedName - Where the converted name is returned 883 * 884 * RETURN: Status 885 * 886 * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name 887 * 888 ******************************************************************************/ 889 890 ACPI_STATUS 891 UtInternalizeName ( 892 char *ExternalName, 893 char **ConvertedName) 894 { 895 ACPI_NAMESTRING_INFO Info; 896 ACPI_STATUS Status; 897 898 899 if (!ExternalName) 900 { 901 return (AE_OK); 902 } 903 904 /* Get the length of the new internal name */ 905 906 Info.ExternalName = ExternalName; 907 AcpiNsGetInternalNameLength (&Info); 908 909 /* We need a segment to store the internal name */ 910 911 Info.InternalName = UtLocalCacheCalloc (Info.Length); 912 913 /* Build the name */ 914 915 Status = AcpiNsBuildInternalName (&Info); 916 if (ACPI_FAILURE (Status)) 917 { 918 return (Status); 919 } 920 921 *ConvertedName = Info.InternalName; 922 return (AE_OK); 923 } 924 925 926 /******************************************************************************* 927 * 928 * FUNCTION: UtPadNameWithUnderscores 929 * 930 * PARAMETERS: NameSeg - Input nameseg 931 * PaddedNameSeg - Output padded nameseg 932 * 933 * RETURN: Padded nameseg. 934 * 935 * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full 936 * ACPI_NAME. 937 * 938 ******************************************************************************/ 939 940 static void 941 UtPadNameWithUnderscores ( 942 char *NameSeg, 943 char *PaddedNameSeg) 944 { 945 UINT32 i; 946 947 948 for (i = 0; (i < ACPI_NAMESEG_SIZE); i++) 949 { 950 if (*NameSeg) 951 { 952 *PaddedNameSeg = *NameSeg; 953 NameSeg++; 954 } 955 else 956 { 957 *PaddedNameSeg = '_'; 958 } 959 960 PaddedNameSeg++; 961 } 962 } 963 964 965 /******************************************************************************* 966 * 967 * FUNCTION: UtAttachNameseg 968 * 969 * PARAMETERS: Op - Parent parse node 970 * Name - Full ExternalName 971 * 972 * RETURN: None; Sets the NameSeg field in parent node 973 * 974 * DESCRIPTION: Extract the last nameseg of the ExternalName and store it 975 * in the NameSeg field of the Op. 976 * 977 ******************************************************************************/ 978 979 static void 980 UtAttachNameseg ( 981 ACPI_PARSE_OBJECT *Op, 982 char *Name) 983 { 984 char *NameSeg; 985 char PaddedNameSeg[4]; 986 987 988 if (!Name) 989 { 990 return; 991 } 992 993 /* Look for the last dot in the namepath */ 994 995 NameSeg = strrchr (Name, '.'); 996 if (NameSeg) 997 { 998 /* Found last dot, we have also found the final nameseg */ 999 1000 NameSeg++; 1001 UtPadNameWithUnderscores (NameSeg, PaddedNameSeg); 1002 } 1003 else 1004 { 1005 /* No dots in the namepath, there is only a single nameseg. */ 1006 /* Handle prefixes */ 1007 1008 while (ACPI_IS_ROOT_PREFIX (*Name) || 1009 ACPI_IS_PARENT_PREFIX (*Name)) 1010 { 1011 Name++; 1012 } 1013 1014 /* Remaining string should be one single nameseg */ 1015 1016 UtPadNameWithUnderscores (Name, PaddedNameSeg); 1017 } 1018 1019 ACPI_COPY_NAMESEG (Op->Asl.NameSeg, PaddedNameSeg); 1020 } 1021 1022 1023 /******************************************************************************* 1024 * 1025 * FUNCTION: UtAttachNamepathToOwner 1026 * 1027 * PARAMETERS: Op - Parent parse node 1028 * NameOp - Node that contains the name 1029 * 1030 * RETURN: Sets the ExternalName and Namepath in the parent node 1031 * 1032 * DESCRIPTION: Store the name in two forms in the parent node: The original 1033 * (external) name, and the internalized name that is used within 1034 * the ACPI namespace manager. 1035 * 1036 ******************************************************************************/ 1037 1038 void 1039 UtAttachNamepathToOwner ( 1040 ACPI_PARSE_OBJECT *Op, 1041 ACPI_PARSE_OBJECT *NameOp) 1042 { 1043 ACPI_STATUS Status; 1044 1045 1046 /* Full external path */ 1047 1048 Op->Asl.ExternalName = NameOp->Asl.Value.String; 1049 1050 /* Save the NameOp for possible error reporting later */ 1051 1052 Op->Asl.ParentMethod = (void *) NameOp; 1053 1054 /* Last nameseg of the path */ 1055 1056 UtAttachNameseg (Op, Op->Asl.ExternalName); 1057 1058 /* Create internalized path */ 1059 1060 Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath); 1061 if (ACPI_FAILURE (Status)) 1062 { 1063 /* TBD: abort on no memory */ 1064 } 1065 } 1066 1067 1068 /******************************************************************************* 1069 * 1070 * FUNCTION: UtNameContainsAllPrefix 1071 * 1072 * PARAMETERS: Op - Op containing NameString 1073 * 1074 * RETURN: NameString consists of all ^ characters 1075 * 1076 * DESCRIPTION: Determine if this Op contains a name segment that consists of 1077 * all '^' characters. 1078 * 1079 ******************************************************************************/ 1080 1081 BOOLEAN 1082 UtNameContainsAllPrefix ( 1083 ACPI_PARSE_OBJECT *Op) 1084 { 1085 UINT32 Length = Op->Asl.AmlLength; 1086 UINT32 i; 1087 1088 for (i = 0; i < Length; i++) 1089 { 1090 if (Op->Asl.Value.String[i] != '^') 1091 { 1092 return (FALSE); 1093 } 1094 } 1095 1096 return (TRUE); 1097 } 1098 1099 /******************************************************************************* 1100 * 1101 * FUNCTION: UtDoConstant 1102 * 1103 * PARAMETERS: String - Hex/Decimal/Octal 1104 * 1105 * RETURN: Converted Integer 1106 * 1107 * DESCRIPTION: Convert a string to an integer, with overflow/error checking. 1108 * 1109 ******************************************************************************/ 1110 1111 UINT64 1112 UtDoConstant ( 1113 char *String) 1114 { 1115 ACPI_STATUS Status; 1116 UINT64 ConvertedInteger; 1117 char ErrBuf[128]; 1118 const ACPI_EXCEPTION_INFO *ExceptionInfo; 1119 1120 1121 Status = AcpiUtStrtoul64 (String, &ConvertedInteger); 1122 if (ACPI_FAILURE (Status)) 1123 { 1124 ExceptionInfo = AcpiUtValidateException ((ACPI_STATUS) Status); 1125 sprintf (ErrBuf, " %s while converting to 64-bit integer", 1126 ExceptionInfo->Description); 1127 1128 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, AslGbl_CurrentLineNumber, 1129 AslGbl_LogicalLineNumber, AslGbl_CurrentLineOffset, 1130 AslGbl_CurrentColumn, AslGbl_Files[ASL_FILE_INPUT].Filename, ErrBuf); 1131 } 1132 1133 return (ConvertedInteger); 1134 } 1135 1136 1137 /****************************************************************************** 1138 * 1139 * FUNCTION: AcpiUtStrdup 1140 * 1141 * PARAMETERS: String1 - string to duplicate 1142 * 1143 * RETURN: int that signifies string relationship. Zero means strings 1144 * are equal. 1145 * 1146 * DESCRIPTION: Duplicate the string using UtCacheAlloc to avoid manual memory 1147 * reclamation. 1148 * 1149 ******************************************************************************/ 1150 1151 char * 1152 AcpiUtStrdup ( 1153 char *String) 1154 { 1155 char *NewString = (char *) UtLocalCalloc (strlen (String) + 1); 1156 1157 1158 strcpy (NewString, String); 1159 return (NewString); 1160 } 1161 1162 1163 /****************************************************************************** 1164 * 1165 * FUNCTION: AcpiUtStrcat 1166 * 1167 * PARAMETERS: String1 1168 * String2 1169 * 1170 * RETURN: New string with String1 concatenated with String2 1171 * 1172 * DESCRIPTION: Concatenate string1 and string2 1173 * 1174 ******************************************************************************/ 1175 1176 char * 1177 AcpiUtStrcat ( 1178 char *String1, 1179 char *String2) 1180 { 1181 UINT32 String1Length = strlen (String1); 1182 char *NewString = (char *) UtLocalCalloc (strlen (String1) + strlen (String2) + 1); 1183 1184 strcpy (NewString, String1); 1185 strcpy (NewString + String1Length, String2); 1186 return (NewString); 1187 } 1188