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 - 2018, 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 "aslcompiler.h" 153 #include "aslcompiler.y.h" 154 #include "acdisasm.h" 155 #include "acnamesp.h" 156 #include "amlcode.h" 157 #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 178 /******************************************************************************* 179 * 180 * FUNCTION: UtIsBigEndianMachine 181 * 182 * PARAMETERS: None 183 * 184 * RETURN: TRUE if machine is big endian 185 * FALSE if machine is little endian 186 * 187 * DESCRIPTION: Detect whether machine is little endian or big endian. 188 * 189 ******************************************************************************/ 190 191 UINT8 192 UtIsBigEndianMachine ( 193 void) 194 { 195 union { 196 UINT32 Integer; 197 UINT8 Bytes[4]; 198 } Overlay = {0xFF000000}; 199 200 201 return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */ 202 } 203 204 205 /****************************************************************************** 206 * 207 * FUNCTION: UtQueryForOverwrite 208 * 209 * PARAMETERS: Pathname - Output filename 210 * 211 * RETURN: TRUE if file does not exist or overwrite is authorized 212 * 213 * DESCRIPTION: Query for file overwrite if it already exists. 214 * 215 ******************************************************************************/ 216 217 BOOLEAN 218 UtQueryForOverwrite ( 219 char *Pathname) 220 { 221 struct stat StatInfo; 222 223 224 if (!stat (Pathname, &StatInfo)) 225 { 226 fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ", 227 Pathname); 228 229 if (getchar () != 'y') 230 { 231 return (FALSE); 232 } 233 } 234 235 return (TRUE); 236 } 237 238 239 /******************************************************************************* 240 * 241 * FUNCTION: UtNodeIsDescendantOf 242 * 243 * PARAMETERS: Node1 - Child node 244 * Node2 - Possible parent node 245 * 246 * RETURN: Boolean 247 * 248 * DESCRIPTION: Returns TRUE if Node1 is a descendant of Node2. Otherwise, 249 * return FALSE. Note, we assume a NULL Node2 element to be the 250 * topmost (root) scope. All nodes are descendants of the root. 251 * Note: Nodes at the same level (siblings) are not considered 252 * descendants. 253 * 254 ******************************************************************************/ 255 256 BOOLEAN 257 UtNodeIsDescendantOf ( 258 ACPI_NAMESPACE_NODE *Node1, 259 ACPI_NAMESPACE_NODE *Node2) 260 { 261 262 if (Node1 == Node2) 263 { 264 return (FALSE); 265 } 266 267 if (!Node2) 268 { 269 return (TRUE); /* All nodes descend from the root */ 270 } 271 272 /* Walk upward until the root is reached or parent is found */ 273 274 while (Node1) 275 { 276 if (Node1 == Node2) 277 { 278 return (TRUE); 279 } 280 281 Node1 = Node1->Parent; 282 } 283 284 return (FALSE); 285 } 286 287 288 /******************************************************************************* 289 * 290 * FUNCTION: UtGetParentMethod 291 * 292 * PARAMETERS: Node - Namespace node for any object 293 * 294 * RETURN: Namespace node for the parent method 295 * NULL - object is not within a method 296 * 297 * DESCRIPTION: Find the parent (owning) method node for a namespace object 298 * 299 ******************************************************************************/ 300 301 void * 302 UtGetParentMethod ( 303 ACPI_NAMESPACE_NODE *Node) 304 { 305 ACPI_NAMESPACE_NODE *ParentNode; 306 307 308 if (!Node) 309 { 310 return (NULL); 311 } 312 313 /* Walk upward until a method is found, or the root is reached */ 314 315 ParentNode = Node->Parent; 316 while (ParentNode) 317 { 318 if (ParentNode->Type == ACPI_TYPE_METHOD) 319 { 320 return (ParentNode); 321 } 322 323 ParentNode = ParentNode->Parent; 324 } 325 326 return (NULL); /* Object is not within a control method */ 327 } 328 329 330 /******************************************************************************* 331 * 332 * FUNCTION: UtDisplaySupportedTables 333 * 334 * PARAMETERS: None 335 * 336 * RETURN: None 337 * 338 * DESCRIPTION: Print all supported ACPI table names. 339 * 340 ******************************************************************************/ 341 342 void 343 UtDisplaySupportedTables ( 344 void) 345 { 346 const AH_TABLE *TableData; 347 UINT32 i; 348 349 350 printf ("\nACPI tables supported by iASL version %8.8X:\n" 351 " (Compiler, Disassembler, Template Generator)\n\n", 352 ACPI_CA_VERSION); 353 354 /* All ACPI tables with the common table header */ 355 356 printf ("\n Supported ACPI tables:\n"); 357 for (TableData = Gbl_AcpiSupportedTables, i = 1; 358 TableData->Signature; TableData++, i++) 359 { 360 printf ("%8u) %s %s\n", i, 361 TableData->Signature, TableData->Description); 362 } 363 } 364 365 366 /******************************************************************************* 367 * 368 * FUNCTION: UtDisplayConstantOpcodes 369 * 370 * PARAMETERS: None 371 * 372 * RETURN: None 373 * 374 * DESCRIPTION: Print AML opcodes that can be used in constant expressions. 375 * 376 ******************************************************************************/ 377 378 void 379 UtDisplayConstantOpcodes ( 380 void) 381 { 382 UINT32 i; 383 384 385 printf ("Constant expression opcode information\n\n"); 386 387 for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++) 388 { 389 if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT) 390 { 391 printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name); 392 } 393 } 394 } 395 396 397 /******************************************************************************* 398 * 399 * FUNCTION: UtBeginEvent 400 * 401 * PARAMETERS: Name - Ascii name of this event 402 * 403 * RETURN: Event number (integer index) 404 * 405 * DESCRIPTION: Saves the current time with this event 406 * 407 ******************************************************************************/ 408 409 UINT8 410 UtBeginEvent ( 411 char *Name) 412 { 413 414 if (AslGbl_NextEvent >= ASL_NUM_EVENTS) 415 { 416 AcpiOsPrintf ("Ran out of compiler event structs!\n"); 417 return (AslGbl_NextEvent); 418 } 419 420 /* Init event with current (start) time */ 421 422 AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer (); 423 AslGbl_Events[AslGbl_NextEvent].EventName = Name; 424 AslGbl_Events[AslGbl_NextEvent].Valid = TRUE; 425 return (AslGbl_NextEvent++); 426 } 427 428 429 /******************************************************************************* 430 * 431 * FUNCTION: UtEndEvent 432 * 433 * PARAMETERS: Event - Event number (integer index) 434 * 435 * RETURN: None 436 * 437 * DESCRIPTION: Saves the current time (end time) with this event 438 * 439 ******************************************************************************/ 440 441 void 442 UtEndEvent ( 443 UINT8 Event) 444 { 445 446 if (Event >= ASL_NUM_EVENTS) 447 { 448 return; 449 } 450 451 /* Insert end time for event */ 452 453 AslGbl_Events[Event].EndTime = AcpiOsGetTimer (); 454 } 455 456 457 /******************************************************************************* 458 * 459 * FUNCTION: DbgPrint 460 * 461 * PARAMETERS: Type - Type of output 462 * Fmt - Printf format string 463 * ... - variable printf list 464 * 465 * RETURN: None 466 * 467 * DESCRIPTION: Conditional print statement. Prints to stderr only if the 468 * debug flag is set. 469 * 470 ******************************************************************************/ 471 472 void 473 DbgPrint ( 474 UINT32 Type, 475 char *Fmt, 476 ...) 477 { 478 va_list Args; 479 480 481 if (!Gbl_DebugFlag) 482 { 483 return; 484 } 485 486 if ((Type == ASL_PARSE_OUTPUT) && 487 (!(AslCompilerdebug))) 488 { 489 return; 490 } 491 492 va_start (Args, Fmt); 493 (void) vfprintf (stderr, Fmt, Args); 494 va_end (Args); 495 return; 496 } 497 498 499 /******************************************************************************* 500 * 501 * FUNCTION: UtSetParseOpName 502 * 503 * PARAMETERS: Op - Parse op to be named. 504 * 505 * RETURN: None 506 * 507 * DESCRIPTION: Insert the ascii name of the parse opcode 508 * 509 ******************************************************************************/ 510 511 void 512 UtSetParseOpName ( 513 ACPI_PARSE_OBJECT *Op) 514 { 515 516 AcpiUtSafeStrncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode), 517 ACPI_MAX_PARSEOP_NAME); 518 } 519 520 521 /******************************************************************************* 522 * 523 * FUNCTION: UtDisplaySummary 524 * 525 * PARAMETERS: FileID - ID of outpout file 526 * 527 * RETURN: None 528 * 529 * DESCRIPTION: Display compilation statistics 530 * 531 ******************************************************************************/ 532 533 void 534 UtDisplaySummary ( 535 UINT32 FileId) 536 { 537 UINT32 i; 538 539 540 if (FileId != ASL_FILE_STDOUT) 541 { 542 /* Compiler name and version number */ 543 544 FlPrintFile (FileId, "%s version %X [%s]\n\n", 545 ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, ACPI_DATE); 546 } 547 548 /* Summary of main input and output files */ 549 550 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 551 { 552 FlPrintFile (FileId, 553 "%-14s %s - %u lines, %u bytes, %u fields\n", 554 "Table Input:", 555 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, 556 Gbl_InputByteCount, Gbl_InputFieldCount); 557 558 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) 559 { 560 FlPrintFile (FileId, 561 "%-14s %s - %u bytes\n", 562 "Binary Output:", 563 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength); 564 } 565 } 566 else 567 { 568 FlPrintFile (FileId, 569 "%-14s %s - %u lines, %u bytes, %u keywords\n", 570 "ASL Input:", 571 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, 572 Gbl_OriginalInputFileSize, TotalKeywords); 573 574 /* AML summary */ 575 576 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) 577 { 578 if (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) 579 { 580 FlPrintFile (FileId, 581 "%-14s %s - %u bytes, %u named objects, " 582 "%u executable opcodes\n", 583 "AML Output:", 584 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, 585 FlGetFileSize (ASL_FILE_AML_OUTPUT), 586 TotalNamedObjects, TotalExecutableOpcodes); 587 } 588 } 589 } 590 591 /* Display summary of any optional files */ 592 593 for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++) 594 { 595 if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle) 596 { 597 continue; 598 } 599 600 /* .SRC is a temp file unless specifically requested */ 601 602 if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag)) 603 { 604 continue; 605 } 606 607 /* .PRE is the preprocessor intermediate file */ 608 609 if ((i == ASL_FILE_PREPROCESSOR) && (!Gbl_KeepPreprocessorTempFile)) 610 { 611 continue; 612 } 613 614 FlPrintFile (FileId, "%14s %s - %u bytes\n", 615 Gbl_Files[i].ShortDescription, 616 Gbl_Files[i].Filename, FlGetFileSize (i)); 617 } 618 619 /* Error summary */ 620 621 FlPrintFile (FileId, 622 "\nCompilation complete. %u Errors, %u Warnings, %u Remarks", 623 Gbl_ExceptionCount[ASL_ERROR], 624 Gbl_ExceptionCount[ASL_WARNING] + 625 Gbl_ExceptionCount[ASL_WARNING2] + 626 Gbl_ExceptionCount[ASL_WARNING3], 627 Gbl_ExceptionCount[ASL_REMARK]); 628 629 if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA) 630 { 631 FlPrintFile (FileId, ", %u Optimizations", 632 Gbl_ExceptionCount[ASL_OPTIMIZATION]); 633 634 if (TotalFolds) 635 { 636 FlPrintFile (FileId, ", %u Constants Folded", TotalFolds); 637 } 638 } 639 640 FlPrintFile (FileId, "\n"); 641 } 642 643 644 /******************************************************************************* 645 * 646 * FUNCTION: UtCheckIntegerRange 647 * 648 * PARAMETERS: Op - Integer parse node 649 * LowValue - Smallest allowed value 650 * HighValue - Largest allowed value 651 * 652 * RETURN: Op if OK, otherwise NULL 653 * 654 * DESCRIPTION: Check integer for an allowable range 655 * 656 ******************************************************************************/ 657 658 ACPI_PARSE_OBJECT * 659 UtCheckIntegerRange ( 660 ACPI_PARSE_OBJECT *Op, 661 UINT32 LowValue, 662 UINT32 HighValue) 663 { 664 665 if (!Op) 666 { 667 return (NULL); 668 } 669 670 if ((Op->Asl.Value.Integer < LowValue) || 671 (Op->Asl.Value.Integer > HighValue)) 672 { 673 sprintf (MsgBuffer, "0x%X, allowable: 0x%X-0x%X", 674 (UINT32) Op->Asl.Value.Integer, LowValue, HighValue); 675 676 AslError (ASL_ERROR, ASL_MSG_RANGE, Op, MsgBuffer); 677 return (NULL); 678 } 679 680 return (Op); 681 } 682 683 684 /******************************************************************************* 685 * 686 * FUNCTION: UtInternalizeName 687 * 688 * PARAMETERS: ExternalName - Name to convert 689 * ConvertedName - Where the converted name is returned 690 * 691 * RETURN: Status 692 * 693 * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name 694 * 695 ******************************************************************************/ 696 697 ACPI_STATUS 698 UtInternalizeName ( 699 char *ExternalName, 700 char **ConvertedName) 701 { 702 ACPI_NAMESTRING_INFO Info; 703 ACPI_STATUS Status; 704 705 706 if (!ExternalName) 707 { 708 return (AE_OK); 709 } 710 711 /* Get the length of the new internal name */ 712 713 Info.ExternalName = ExternalName; 714 AcpiNsGetInternalNameLength (&Info); 715 716 /* We need a segment to store the internal name */ 717 718 Info.InternalName = UtLocalCacheCalloc (Info.Length); 719 720 /* Build the name */ 721 722 Status = AcpiNsBuildInternalName (&Info); 723 if (ACPI_FAILURE (Status)) 724 { 725 return (Status); 726 } 727 728 *ConvertedName = Info.InternalName; 729 return (AE_OK); 730 } 731 732 733 /******************************************************************************* 734 * 735 * FUNCTION: UtPadNameWithUnderscores 736 * 737 * PARAMETERS: NameSeg - Input nameseg 738 * PaddedNameSeg - Output padded nameseg 739 * 740 * RETURN: Padded nameseg. 741 * 742 * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full 743 * ACPI_NAME. 744 * 745 ******************************************************************************/ 746 747 static void 748 UtPadNameWithUnderscores ( 749 char *NameSeg, 750 char *PaddedNameSeg) 751 { 752 UINT32 i; 753 754 755 for (i = 0; (i < ACPI_NAME_SIZE); i++) 756 { 757 if (*NameSeg) 758 { 759 *PaddedNameSeg = *NameSeg; 760 NameSeg++; 761 } 762 else 763 { 764 *PaddedNameSeg = '_'; 765 } 766 767 PaddedNameSeg++; 768 } 769 } 770 771 772 /******************************************************************************* 773 * 774 * FUNCTION: UtAttachNameseg 775 * 776 * PARAMETERS: Op - Parent parse node 777 * Name - Full ExternalName 778 * 779 * RETURN: None; Sets the NameSeg field in parent node 780 * 781 * DESCRIPTION: Extract the last nameseg of the ExternalName and store it 782 * in the NameSeg field of the Op. 783 * 784 ******************************************************************************/ 785 786 static void 787 UtAttachNameseg ( 788 ACPI_PARSE_OBJECT *Op, 789 char *Name) 790 { 791 char *NameSeg; 792 char PaddedNameSeg[4]; 793 794 795 if (!Name) 796 { 797 return; 798 } 799 800 /* Look for the last dot in the namepath */ 801 802 NameSeg = strrchr (Name, '.'); 803 if (NameSeg) 804 { 805 /* Found last dot, we have also found the final nameseg */ 806 807 NameSeg++; 808 UtPadNameWithUnderscores (NameSeg, PaddedNameSeg); 809 } 810 else 811 { 812 /* No dots in the namepath, there is only a single nameseg. */ 813 /* Handle prefixes */ 814 815 while (ACPI_IS_ROOT_PREFIX (*Name) || 816 ACPI_IS_PARENT_PREFIX (*Name)) 817 { 818 Name++; 819 } 820 821 /* Remaining string should be one single nameseg */ 822 823 UtPadNameWithUnderscores (Name, PaddedNameSeg); 824 } 825 826 ACPI_MOVE_NAME (Op->Asl.NameSeg, PaddedNameSeg); 827 } 828 829 830 /******************************************************************************* 831 * 832 * FUNCTION: UtAttachNamepathToOwner 833 * 834 * PARAMETERS: Op - Parent parse node 835 * NameOp - Node that contains the name 836 * 837 * RETURN: Sets the ExternalName and Namepath in the parent node 838 * 839 * DESCRIPTION: Store the name in two forms in the parent node: The original 840 * (external) name, and the internalized name that is used within 841 * the ACPI namespace manager. 842 * 843 ******************************************************************************/ 844 845 void 846 UtAttachNamepathToOwner ( 847 ACPI_PARSE_OBJECT *Op, 848 ACPI_PARSE_OBJECT *NameOp) 849 { 850 ACPI_STATUS Status; 851 852 853 /* Full external path */ 854 855 Op->Asl.ExternalName = NameOp->Asl.Value.String; 856 857 /* Save the NameOp for possible error reporting later */ 858 859 Op->Asl.ParentMethod = (void *) NameOp; 860 861 /* Last nameseg of the path */ 862 863 UtAttachNameseg (Op, Op->Asl.ExternalName); 864 865 /* Create internalized path */ 866 867 Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath); 868 if (ACPI_FAILURE (Status)) 869 { 870 /* TBD: abort on no memory */ 871 } 872 } 873 874 875 /******************************************************************************* 876 * 877 * FUNCTION: UtDoConstant 878 * 879 * PARAMETERS: String - Hex/Decimal/Octal 880 * 881 * RETURN: Converted Integer 882 * 883 * DESCRIPTION: Convert a string to an integer, with overflow/error checking. 884 * 885 ******************************************************************************/ 886 887 UINT64 888 UtDoConstant ( 889 char *String) 890 { 891 ACPI_STATUS Status; 892 UINT64 ConvertedInteger; 893 char ErrBuf[64]; 894 895 896 Status = AcpiUtStrtoul64 (String, &ConvertedInteger); 897 if (ACPI_FAILURE (Status)) 898 { 899 sprintf (ErrBuf, "While creating 64-bit constant: %s\n", 900 AcpiFormatException (Status)); 901 902 AslCommonError (ASL_ERROR, ASL_MSG_SYNTAX, Gbl_CurrentLineNumber, 903 Gbl_LogicalLineNumber, Gbl_CurrentLineOffset, 904 Gbl_CurrentColumn, Gbl_Files[ASL_FILE_INPUT].Filename, ErrBuf); 905 } 906 907 return (ConvertedInteger); 908 } 909