1 /****************************************************************************** 2 * 3 * Module Name: aslutils -- compiler utilities 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2016, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #include "aslcompiler.h" 45 #include "aslcompiler.y.h" 46 #include "acdisasm.h" 47 #include "acnamesp.h" 48 #include "amlcode.h" 49 #include "acapps.h" 50 #include <sys/stat.h> 51 52 53 #define _COMPONENT ACPI_COMPILER 54 ACPI_MODULE_NAME ("aslutils") 55 56 57 /* Local prototypes */ 58 59 static void 60 UtPadNameWithUnderscores ( 61 char *NameSeg, 62 char *PaddedNameSeg); 63 64 static void 65 UtAttachNameseg ( 66 ACPI_PARSE_OBJECT *Op, 67 char *Name); 68 69 70 /******************************************************************************* 71 * 72 * FUNCTION: UtIsBigEndianMachine 73 * 74 * PARAMETERS: None 75 * 76 * RETURN: TRUE if machine is big endian 77 * FALSE if machine is little endian 78 * 79 * DESCRIPTION: Detect whether machine is little endian or big endian. 80 * 81 ******************************************************************************/ 82 83 UINT8 84 UtIsBigEndianMachine ( 85 void) 86 { 87 union { 88 UINT32 Integer; 89 UINT8 Bytes[4]; 90 } Overlay = {0xFF000000}; 91 92 93 return (Overlay.Bytes[0]); /* Returns 0xFF (TRUE) for big endian */ 94 } 95 96 97 /****************************************************************************** 98 * 99 * FUNCTION: UtQueryForOverwrite 100 * 101 * PARAMETERS: Pathname - Output filename 102 * 103 * RETURN: TRUE if file does not exist or overwrite is authorized 104 * 105 * DESCRIPTION: Query for file overwrite if it already exists. 106 * 107 ******************************************************************************/ 108 109 BOOLEAN 110 UtQueryForOverwrite ( 111 char *Pathname) 112 { 113 struct stat StatInfo; 114 115 116 if (!stat (Pathname, &StatInfo)) 117 { 118 fprintf (stderr, "Target file \"%s\" already exists, overwrite? [y|n] ", 119 Pathname); 120 121 if (getchar () != 'y') 122 { 123 return (FALSE); 124 } 125 } 126 127 return (TRUE); 128 } 129 130 131 /******************************************************************************* 132 * 133 * FUNCTION: UtDisplaySupportedTables 134 * 135 * PARAMETERS: None 136 * 137 * RETURN: None 138 * 139 * DESCRIPTION: Print all supported ACPI table names. 140 * 141 ******************************************************************************/ 142 143 void 144 UtDisplaySupportedTables ( 145 void) 146 { 147 const AH_TABLE *TableData; 148 UINT32 i; 149 150 151 printf ("\nACPI tables supported by iASL version %8.8X:\n" 152 " (Compiler, Disassembler, Template Generator)\n\n", 153 ACPI_CA_VERSION); 154 155 /* All ACPI tables with the common table header */ 156 157 printf ("\n Supported ACPI tables:\n"); 158 for (TableData = AcpiSupportedTables, i = 1; 159 TableData->Signature; TableData++, i++) 160 { 161 printf ("%8u) %s %s\n", i, 162 TableData->Signature, TableData->Description); 163 } 164 } 165 166 167 /******************************************************************************* 168 * 169 * FUNCTION: UtDisplayConstantOpcodes 170 * 171 * PARAMETERS: None 172 * 173 * RETURN: None 174 * 175 * DESCRIPTION: Print AML opcodes that can be used in constant expressions. 176 * 177 ******************************************************************************/ 178 179 void 180 UtDisplayConstantOpcodes ( 181 void) 182 { 183 UINT32 i; 184 185 186 printf ("Constant expression opcode information\n\n"); 187 188 for (i = 0; i < sizeof (AcpiGbl_AmlOpInfo) / sizeof (ACPI_OPCODE_INFO); i++) 189 { 190 if (AcpiGbl_AmlOpInfo[i].Flags & AML_CONSTANT) 191 { 192 printf ("%s\n", AcpiGbl_AmlOpInfo[i].Name); 193 } 194 } 195 } 196 197 198 /******************************************************************************* 199 * 200 * FUNCTION: UtLocalCalloc 201 * 202 * PARAMETERS: Size - Bytes to be allocated 203 * 204 * RETURN: Pointer to the allocated memory. Guaranteed to be valid. 205 * 206 * DESCRIPTION: Allocate zero-initialized memory. Aborts the compile on an 207 * allocation failure, on the assumption that nothing more can be 208 * accomplished. 209 * 210 ******************************************************************************/ 211 212 void * 213 UtLocalCalloc ( 214 UINT32 Size) 215 { 216 void *Allocated; 217 218 219 Allocated = ACPI_ALLOCATE_ZEROED (Size); 220 if (!Allocated) 221 { 222 AslCommonError (ASL_ERROR, ASL_MSG_MEMORY_ALLOCATION, 223 Gbl_CurrentLineNumber, Gbl_LogicalLineNumber, 224 Gbl_InputByteCount, Gbl_CurrentColumn, 225 Gbl_Files[ASL_FILE_INPUT].Filename, NULL); 226 227 CmCleanupAndExit (); 228 exit (1); 229 } 230 231 TotalAllocations++; 232 TotalAllocated += Size; 233 return (Allocated); 234 } 235 236 /******************************************************************************* 237 * 238 * FUNCTION: UtLocalFree 239 * 240 * PARAMETERS: Allocated - Pointer to be released 241 * PARAMETERS: Size - Bytes to be released 242 * 243 * RETURN: None 244 * 245 * DESCRIPTION: Free memory previously allocated 246 * 247 ******************************************************************************/ 248 void 249 UtLocalFree ( 250 void *Allocated, UINT32 Size) 251 { 252 ACPI_FREE (Allocated); 253 TotalAllocations--; 254 TotalAllocated -= Size; 255 } 256 257 /******************************************************************************* 258 * 259 * FUNCTION: UtBeginEvent 260 * 261 * PARAMETERS: Name - Ascii name of this event 262 * 263 * RETURN: Event number (integer index) 264 * 265 * DESCRIPTION: Saves the current time with this event 266 * 267 ******************************************************************************/ 268 269 UINT8 270 UtBeginEvent ( 271 char *Name) 272 { 273 274 if (AslGbl_NextEvent >= ASL_NUM_EVENTS) 275 { 276 AcpiOsPrintf ("Ran out of compiler event structs!\n"); 277 return (AslGbl_NextEvent); 278 } 279 280 /* Init event with current (start) time */ 281 282 AslGbl_Events[AslGbl_NextEvent].StartTime = AcpiOsGetTimer (); 283 AslGbl_Events[AslGbl_NextEvent].EventName = Name; 284 AslGbl_Events[AslGbl_NextEvent].Valid = TRUE; 285 return (AslGbl_NextEvent++); 286 } 287 288 289 /******************************************************************************* 290 * 291 * FUNCTION: UtEndEvent 292 * 293 * PARAMETERS: Event - Event number (integer index) 294 * 295 * RETURN: None 296 * 297 * DESCRIPTION: Saves the current time (end time) with this event 298 * 299 ******************************************************************************/ 300 301 void 302 UtEndEvent ( 303 UINT8 Event) 304 { 305 306 if (Event >= ASL_NUM_EVENTS) 307 { 308 return; 309 } 310 311 /* Insert end time for event */ 312 313 AslGbl_Events[Event].EndTime = AcpiOsGetTimer (); 314 } 315 316 317 /******************************************************************************* 318 * 319 * FUNCTION: DbgPrint 320 * 321 * PARAMETERS: Type - Type of output 322 * Fmt - Printf format string 323 * ... - variable printf list 324 * 325 * RETURN: None 326 * 327 * DESCRIPTION: Conditional print statement. Prints to stderr only if the 328 * debug flag is set. 329 * 330 ******************************************************************************/ 331 332 void 333 DbgPrint ( 334 UINT32 Type, 335 char *Fmt, 336 ...) 337 { 338 va_list Args; 339 340 341 if (!Gbl_DebugFlag) 342 { 343 return; 344 } 345 346 if ((Type == ASL_PARSE_OUTPUT) && 347 (!(AslCompilerdebug))) 348 { 349 return; 350 } 351 352 va_start (Args, Fmt); 353 (void) vfprintf (stderr, Fmt, Args); 354 va_end (Args); 355 return; 356 } 357 358 359 /******************************************************************************* 360 * 361 * FUNCTION: UtSetParseOpName 362 * 363 * PARAMETERS: Op - Parse op to be named. 364 * 365 * RETURN: None 366 * 367 * DESCRIPTION: Insert the ascii name of the parse opcode 368 * 369 ******************************************************************************/ 370 371 void 372 UtSetParseOpName ( 373 ACPI_PARSE_OBJECT *Op) 374 { 375 376 strncpy (Op->Asl.ParseOpName, UtGetOpName (Op->Asl.ParseOpcode), 377 ACPI_MAX_PARSEOP_NAME); 378 } 379 380 381 /******************************************************************************* 382 * 383 * FUNCTION: UtDisplaySummary 384 * 385 * PARAMETERS: FileID - ID of outpout file 386 * 387 * RETURN: None 388 * 389 * DESCRIPTION: Display compilation statistics 390 * 391 ******************************************************************************/ 392 393 void 394 UtDisplaySummary ( 395 UINT32 FileId) 396 { 397 UINT32 i; 398 399 400 if (FileId != ASL_FILE_STDOUT) 401 { 402 /* Compiler name and version number */ 403 404 FlPrintFile (FileId, "%s version %X%s [%s]\n\n", 405 ASL_COMPILER_NAME, (UINT32) ACPI_CA_VERSION, ACPI_WIDTH, ACPI_DATE); 406 } 407 408 /* Summary of main input and output files */ 409 410 if (Gbl_FileType == ASL_INPUT_TYPE_ASCII_DATA) 411 { 412 FlPrintFile (FileId, 413 "%-14s %s - %u lines, %u bytes, %u fields\n", 414 "Table Input:", 415 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, 416 Gbl_InputByteCount, Gbl_InputFieldCount); 417 418 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) 419 { 420 FlPrintFile (FileId, 421 "%-14s %s - %u bytes\n", 422 "Binary Output:", 423 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, Gbl_TableLength); 424 } 425 } 426 else 427 { 428 FlPrintFile (FileId, 429 "%-14s %s - %u lines, %u bytes, %u keywords\n", 430 "ASL Input:", 431 Gbl_Files[ASL_FILE_INPUT].Filename, Gbl_CurrentLineNumber, 432 Gbl_OriginalInputFileSize, TotalKeywords); 433 434 /* AML summary */ 435 436 if ((Gbl_ExceptionCount[ASL_ERROR] == 0) || (Gbl_IgnoreErrors)) 437 { 438 if (Gbl_Files[ASL_FILE_AML_OUTPUT].Handle) 439 { 440 FlPrintFile (FileId, 441 "%-14s %s - %u bytes, %u named objects, " 442 "%u executable opcodes\n", 443 "AML Output:", 444 Gbl_Files[ASL_FILE_AML_OUTPUT].Filename, 445 FlGetFileSize (ASL_FILE_AML_OUTPUT), 446 TotalNamedObjects, TotalExecutableOpcodes); 447 } 448 } 449 } 450 451 /* Display summary of any optional files */ 452 453 for (i = ASL_FILE_SOURCE_OUTPUT; i <= ASL_MAX_FILE_TYPE; i++) 454 { 455 if (!Gbl_Files[i].Filename || !Gbl_Files[i].Handle) 456 { 457 continue; 458 } 459 460 /* .SRC is a temp file unless specifically requested */ 461 462 if ((i == ASL_FILE_SOURCE_OUTPUT) && (!Gbl_SourceOutputFlag)) 463 { 464 continue; 465 } 466 467 /* .PRE is the preprocessor intermediate file */ 468 469 if ((i == ASL_FILE_PREPROCESSOR) && (!Gbl_KeepPreprocessorTempFile)) 470 { 471 continue; 472 } 473 474 FlPrintFile (FileId, "%14s %s - %u bytes\n", 475 Gbl_Files[i].ShortDescription, 476 Gbl_Files[i].Filename, FlGetFileSize (i)); 477 } 478 479 /* Error summary */ 480 481 FlPrintFile (FileId, 482 "\nCompilation complete. %u Errors, %u Warnings, %u Remarks", 483 Gbl_ExceptionCount[ASL_ERROR], 484 Gbl_ExceptionCount[ASL_WARNING] + 485 Gbl_ExceptionCount[ASL_WARNING2] + 486 Gbl_ExceptionCount[ASL_WARNING3], 487 Gbl_ExceptionCount[ASL_REMARK]); 488 489 if (Gbl_FileType != ASL_INPUT_TYPE_ASCII_DATA) 490 { 491 FlPrintFile (FileId, ", %u Optimizations", 492 Gbl_ExceptionCount[ASL_OPTIMIZATION]); 493 494 if (TotalFolds) 495 { 496 FlPrintFile (FileId, ", %u Constants Folded", TotalFolds); 497 } 498 } 499 500 FlPrintFile (FileId, "\n"); 501 } 502 503 504 /******************************************************************************* 505 * 506 * FUNCTION: UtCheckIntegerRange 507 * 508 * PARAMETERS: Op - Integer parse node 509 * LowValue - Smallest allowed value 510 * HighValue - Largest allowed value 511 * 512 * RETURN: Op if OK, otherwise NULL 513 * 514 * DESCRIPTION: Check integer for an allowable range 515 * 516 ******************************************************************************/ 517 518 ACPI_PARSE_OBJECT * 519 UtCheckIntegerRange ( 520 ACPI_PARSE_OBJECT *Op, 521 UINT32 LowValue, 522 UINT32 HighValue) 523 { 524 525 if (!Op) 526 { 527 return (NULL); 528 } 529 530 if ((Op->Asl.Value.Integer < LowValue) || 531 (Op->Asl.Value.Integer > HighValue)) 532 { 533 snprintf (MsgBuffer, sizeof(MsgBuffer), "0x%X, allowable: 0x%X-0x%X", 534 (UINT32) Op->Asl.Value.Integer, LowValue, HighValue); 535 536 AslError (ASL_ERROR, ASL_MSG_RANGE, Op, MsgBuffer); 537 return (NULL); 538 } 539 540 return (Op); 541 } 542 543 544 /******************************************************************************* 545 * 546 * FUNCTION: UtStringCacheCalloc 547 * 548 * PARAMETERS: Length - Size of buffer requested 549 * 550 * RETURN: Pointer to the buffer. Aborts on allocation failure 551 * 552 * DESCRIPTION: Allocate a string buffer. Bypass the local 553 * dynamic memory manager for performance reasons (This has a 554 * major impact on the speed of the compiler.) 555 * 556 ******************************************************************************/ 557 558 char * 559 UtStringCacheCalloc ( 560 UINT32 Length) 561 { 562 char *Buffer; 563 ASL_CACHE_INFO *Cache; 564 UINT32 CacheSize = ASL_STRING_CACHE_SIZE; 565 566 567 if (Length > CacheSize) 568 { 569 CacheSize = Length; 570 571 if (Gbl_StringCacheList) 572 { 573 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize); 574 575 /* Link new cache buffer just following head of list */ 576 577 Cache->Next = Gbl_StringCacheList->Next; 578 Gbl_StringCacheList->Next = Cache; 579 580 /* Leave cache management pointers alone as they pertain to head */ 581 582 Gbl_StringCount++; 583 Gbl_StringSize += Length; 584 585 return (Cache->Buffer); 586 } 587 } 588 589 if ((Gbl_StringCacheNext + Length) >= Gbl_StringCacheLast) 590 { 591 /* Allocate a new buffer */ 592 593 Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize); 594 595 /* Link new cache buffer to head of list */ 596 597 Cache->Next = Gbl_StringCacheList; 598 Gbl_StringCacheList = Cache; 599 600 /* Setup cache management pointers */ 601 602 Gbl_StringCacheNext = Cache->Buffer; 603 Gbl_StringCacheLast = Gbl_StringCacheNext + CacheSize; 604 } 605 606 Gbl_StringCount++; 607 Gbl_StringSize += Length; 608 609 Buffer = Gbl_StringCacheNext; 610 Gbl_StringCacheNext += Length; 611 return (Buffer); 612 } 613 614 615 /****************************************************************************** 616 * 617 * FUNCTION: UtExpandLineBuffers 618 * 619 * PARAMETERS: None. Updates global line buffer pointers. 620 * 621 * RETURN: None. Reallocates the global line buffers 622 * 623 * DESCRIPTION: Called if the current line buffer becomes filled. Reallocates 624 * all global line buffers and updates Gbl_LineBufferSize. NOTE: 625 * Also used for the initial allocation of the buffers, when 626 * all of the buffer pointers are NULL. Initial allocations are 627 * of size ASL_DEFAULT_LINE_BUFFER_SIZE 628 * 629 *****************************************************************************/ 630 631 void 632 UtExpandLineBuffers ( 633 void) 634 { 635 UINT32 NewSize; 636 637 638 /* Attempt to double the size of all line buffers */ 639 640 NewSize = Gbl_LineBufferSize * 2; 641 if (Gbl_CurrentLineBuffer) 642 { 643 DbgPrint (ASL_DEBUG_OUTPUT, 644 "Increasing line buffer size from %u to %u\n", 645 Gbl_LineBufferSize, NewSize); 646 } 647 648 Gbl_CurrentLineBuffer = realloc (Gbl_CurrentLineBuffer, NewSize); 649 Gbl_LineBufPtr = Gbl_CurrentLineBuffer; 650 if (!Gbl_CurrentLineBuffer) 651 { 652 goto ErrorExit; 653 } 654 655 Gbl_MainTokenBuffer = realloc (Gbl_MainTokenBuffer, NewSize); 656 if (!Gbl_MainTokenBuffer) 657 { 658 goto ErrorExit; 659 } 660 661 Gbl_MacroTokenBuffer = realloc (Gbl_MacroTokenBuffer, NewSize); 662 if (!Gbl_MacroTokenBuffer) 663 { 664 goto ErrorExit; 665 } 666 667 Gbl_ExpressionTokenBuffer = realloc (Gbl_ExpressionTokenBuffer, NewSize); 668 if (!Gbl_ExpressionTokenBuffer) 669 { 670 goto ErrorExit; 671 } 672 673 Gbl_LineBufferSize = NewSize; 674 return; 675 676 677 /* On error above, simply issue error messages and abort, cannot continue */ 678 679 ErrorExit: 680 printf ("Could not increase line buffer size from %u to %u\n", 681 Gbl_LineBufferSize, Gbl_LineBufferSize * 2); 682 683 AslError (ASL_ERROR, ASL_MSG_BUFFER_ALLOCATION, 684 NULL, NULL); 685 AslAbort (); 686 } 687 688 689 /****************************************************************************** 690 * 691 * FUNCTION: UtFreeLineBuffers 692 * 693 * PARAMETERS: None 694 * 695 * RETURN: None 696 * 697 * DESCRIPTION: Free all line buffers 698 * 699 *****************************************************************************/ 700 701 void 702 UtFreeLineBuffers ( 703 void) 704 { 705 706 free (Gbl_CurrentLineBuffer); 707 free (Gbl_MainTokenBuffer); 708 free (Gbl_MacroTokenBuffer); 709 free (Gbl_ExpressionTokenBuffer); 710 } 711 712 713 /******************************************************************************* 714 * 715 * FUNCTION: UtInternalizeName 716 * 717 * PARAMETERS: ExternalName - Name to convert 718 * ConvertedName - Where the converted name is returned 719 * 720 * RETURN: Status 721 * 722 * DESCRIPTION: Convert an external (ASL) name to an internal (AML) name 723 * 724 ******************************************************************************/ 725 726 ACPI_STATUS 727 UtInternalizeName ( 728 char *ExternalName, 729 char **ConvertedName) 730 { 731 ACPI_NAMESTRING_INFO Info; 732 ACPI_STATUS Status; 733 734 735 if (!ExternalName) 736 { 737 return (AE_OK); 738 } 739 740 /* Get the length of the new internal name */ 741 742 Info.ExternalName = ExternalName; 743 AcpiNsGetInternalNameLength (&Info); 744 745 /* We need a segment to store the internal name */ 746 747 Info.InternalName = UtStringCacheCalloc (Info.Length); 748 if (!Info.InternalName) 749 { 750 return (AE_NO_MEMORY); 751 } 752 753 /* Build the name */ 754 755 Status = AcpiNsBuildInternalName (&Info); 756 if (ACPI_FAILURE (Status)) 757 { 758 return (Status); 759 } 760 761 *ConvertedName = Info.InternalName; 762 return (AE_OK); 763 } 764 765 766 /******************************************************************************* 767 * 768 * FUNCTION: UtPadNameWithUnderscores 769 * 770 * PARAMETERS: NameSeg - Input nameseg 771 * PaddedNameSeg - Output padded nameseg 772 * 773 * RETURN: Padded nameseg. 774 * 775 * DESCRIPTION: Pads a NameSeg with underscores if necessary to form a full 776 * ACPI_NAME. 777 * 778 ******************************************************************************/ 779 780 static void 781 UtPadNameWithUnderscores ( 782 char *NameSeg, 783 char *PaddedNameSeg) 784 { 785 UINT32 i; 786 787 788 for (i = 0; (i < ACPI_NAME_SIZE); i++) 789 { 790 if (*NameSeg) 791 { 792 *PaddedNameSeg = *NameSeg; 793 NameSeg++; 794 } 795 else 796 { 797 *PaddedNameSeg = '_'; 798 } 799 800 PaddedNameSeg++; 801 } 802 } 803 804 805 /******************************************************************************* 806 * 807 * FUNCTION: UtAttachNameseg 808 * 809 * PARAMETERS: Op - Parent parse node 810 * Name - Full ExternalName 811 * 812 * RETURN: None; Sets the NameSeg field in parent node 813 * 814 * DESCRIPTION: Extract the last nameseg of the ExternalName and store it 815 * in the NameSeg field of the Op. 816 * 817 ******************************************************************************/ 818 819 static void 820 UtAttachNameseg ( 821 ACPI_PARSE_OBJECT *Op, 822 char *Name) 823 { 824 char *NameSeg; 825 char PaddedNameSeg[4]; 826 827 828 if (!Name) 829 { 830 return; 831 } 832 833 /* Look for the last dot in the namepath */ 834 835 NameSeg = strrchr (Name, '.'); 836 if (NameSeg) 837 { 838 /* Found last dot, we have also found the final nameseg */ 839 840 NameSeg++; 841 UtPadNameWithUnderscores (NameSeg, PaddedNameSeg); 842 } 843 else 844 { 845 /* No dots in the namepath, there is only a single nameseg. */ 846 /* Handle prefixes */ 847 848 while (ACPI_IS_ROOT_PREFIX (*Name) || 849 ACPI_IS_PARENT_PREFIX (*Name)) 850 { 851 Name++; 852 } 853 854 /* Remaining string should be one single nameseg */ 855 856 UtPadNameWithUnderscores (Name, PaddedNameSeg); 857 } 858 859 ACPI_MOVE_NAME (Op->Asl.NameSeg, PaddedNameSeg); 860 } 861 862 863 /******************************************************************************* 864 * 865 * FUNCTION: UtAttachNamepathToOwner 866 * 867 * PARAMETERS: Op - Parent parse node 868 * NameOp - Node that contains the name 869 * 870 * RETURN: Sets the ExternalName and Namepath in the parent node 871 * 872 * DESCRIPTION: Store the name in two forms in the parent node: The original 873 * (external) name, and the internalized name that is used within 874 * the ACPI namespace manager. 875 * 876 ******************************************************************************/ 877 878 void 879 UtAttachNamepathToOwner ( 880 ACPI_PARSE_OBJECT *Op, 881 ACPI_PARSE_OBJECT *NameOp) 882 { 883 ACPI_STATUS Status; 884 885 886 /* Full external path */ 887 888 Op->Asl.ExternalName = NameOp->Asl.Value.String; 889 890 /* Save the NameOp for possible error reporting later */ 891 892 Op->Asl.ParentMethod = (void *) NameOp; 893 894 /* Last nameseg of the path */ 895 896 UtAttachNameseg (Op, Op->Asl.ExternalName); 897 898 /* Create internalized path */ 899 900 Status = UtInternalizeName (NameOp->Asl.Value.String, &Op->Asl.Namepath); 901 if (ACPI_FAILURE (Status)) 902 { 903 /* TBD: abort on no memory */ 904 } 905 } 906 907 908 /******************************************************************************* 909 * 910 * FUNCTION: UtDoConstant 911 * 912 * PARAMETERS: String - Hex, Octal, or Decimal string 913 * 914 * RETURN: Converted Integer 915 * 916 * DESCRIPTION: Convert a string to an integer, with error checking. 917 * 918 ******************************************************************************/ 919 920 UINT64 921 UtDoConstant ( 922 char *String) 923 { 924 ACPI_STATUS Status; 925 UINT64 Converted; 926 char ErrBuf[64]; 927 928 929 Status = AcpiUtStrtoul64 (String, ACPI_ANY_BASE, 930 ACPI_MAX64_BYTE_WIDTH, &Converted); 931 932 if (ACPI_FAILURE (Status)) 933 { 934 snprintf (ErrBuf, sizeof(ErrBuf), "%s %s\n", "Conversion error:", 935 AcpiFormatException (Status)); 936 AslCompilererror (ErrBuf); 937 } 938 939 return (Converted); 940 } 941 942 943 #ifdef _OBSOLETE_FUNCTIONS 944 /* Removed 01/2016 */ 945 946 /******************************************************************************* 947 * 948 * FUNCTION: UtConvertByteToHex 949 * 950 * PARAMETERS: RawByte - Binary data 951 * Buffer - Pointer to where the hex bytes will be 952 * stored 953 * 954 * RETURN: Ascii hex byte is stored in Buffer. 955 * 956 * DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed 957 * with "0x" 958 * 959 ******************************************************************************/ 960 961 void 962 UtConvertByteToHex ( 963 UINT8 RawByte, 964 UINT8 *Buffer) 965 { 966 967 Buffer[0] = '0'; 968 Buffer[1] = 'x'; 969 970 Buffer[2] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 4); 971 Buffer[3] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 0); 972 } 973 974 975 /******************************************************************************* 976 * 977 * FUNCTION: UtConvertByteToAsmHex 978 * 979 * PARAMETERS: RawByte - Binary data 980 * Buffer - Pointer to where the hex bytes will be 981 * stored 982 * 983 * RETURN: Ascii hex byte is stored in Buffer. 984 * 985 * DESCRIPTION: Perform hex-to-ascii translation. The return data is prefixed 986 * with '0', and a trailing 'h' is added. 987 * 988 ******************************************************************************/ 989 990 void 991 UtConvertByteToAsmHex ( 992 UINT8 RawByte, 993 UINT8 *Buffer) 994 { 995 996 Buffer[0] = '0'; 997 Buffer[1] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 4); 998 Buffer[2] = (UINT8) AcpiUtHexToAsciiChar (RawByte, 0); 999 Buffer[3] = 'h'; 1000 } 1001 #endif /* OBSOLETE_FUNCTIONS */ 1002