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