1 /****************************************************************************** 2 * 3 * Module Name: asltransform - Parse tree transforms 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2019, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include <contrib/dev/acpica/compiler/aslcompiler.h> 153 #include "aslcompiler.y.h" 154 155 #define _COMPONENT ACPI_COMPILER 156 ACPI_MODULE_NAME ("asltransform") 157 158 /* Local prototypes */ 159 160 static void 161 TrTransformSubtree ( 162 ACPI_PARSE_OBJECT *Op); 163 164 static char * 165 TrAmlGetNextTempName ( 166 ACPI_PARSE_OBJECT *Op, 167 UINT8 *TempCount); 168 169 static void 170 TrAmlInitLineNumbers ( 171 ACPI_PARSE_OBJECT *Op, 172 ACPI_PARSE_OBJECT *Neighbor); 173 174 static void 175 TrAmlInitNode ( 176 ACPI_PARSE_OBJECT *Op, 177 UINT16 ParseOpcode); 178 179 static void 180 TrAmlSetSubtreeParent ( 181 ACPI_PARSE_OBJECT *Op, 182 ACPI_PARSE_OBJECT *Parent); 183 184 static void 185 TrAmlInsertPeer ( 186 ACPI_PARSE_OBJECT *Op, 187 ACPI_PARSE_OBJECT *NewPeer); 188 189 static void 190 TrDoDefinitionBlock ( 191 ACPI_PARSE_OBJECT *Op); 192 193 static void 194 TrDoSwitch ( 195 ACPI_PARSE_OBJECT *StartNode); 196 197 198 /******************************************************************************* 199 * 200 * FUNCTION: TrAmlGetNextTempName 201 * 202 * PARAMETERS: Op - Current parse op 203 * TempCount - Current temporary counter. Was originally 204 * per-module; Currently per method, could be 205 * expanded to per-scope. 206 * 207 * RETURN: A pointer to name (allocated here). 208 * 209 * DESCRIPTION: Generate an ACPI name of the form _T_x. These names are 210 * reserved for use by the ASL compiler. (_T_0 through _T_Z) 211 * 212 ******************************************************************************/ 213 214 static char * 215 TrAmlGetNextTempName ( 216 ACPI_PARSE_OBJECT *Op, 217 UINT8 *TempCount) 218 { 219 char *TempName; 220 221 222 if (*TempCount >= (10 + 26)) /* 0-35 valid: 0-9 and A-Z for TempName[3] */ 223 { 224 /* Too many temps */ 225 226 AslError (ASL_ERROR, ASL_MSG_TOO_MANY_TEMPS, Op, NULL); 227 return (NULL); 228 } 229 230 TempName = UtLocalCalloc (5); 231 232 if (*TempCount < 10) /* 0-9 */ 233 { 234 TempName[3] = (char) (*TempCount + '0'); 235 } 236 else /* 10-35: A-Z */ 237 { 238 TempName[3] = (char) (*TempCount + ('A' - 10)); 239 } 240 241 (*TempCount)++; 242 243 /* First three characters are always "_T_" */ 244 245 TempName[0] = '_'; 246 TempName[1] = 'T'; 247 TempName[2] = '_'; 248 249 return (TempName); 250 } 251 252 253 /******************************************************************************* 254 * 255 * FUNCTION: TrAmlInitLineNumbers 256 * 257 * PARAMETERS: Op - Op to be initialized 258 * Neighbor - Op used for initialization values 259 * 260 * RETURN: None 261 * 262 * DESCRIPTION: Initialized the various line numbers for a parse node. 263 * 264 ******************************************************************************/ 265 266 static void 267 TrAmlInitLineNumbers ( 268 ACPI_PARSE_OBJECT *Op, 269 ACPI_PARSE_OBJECT *Neighbor) 270 { 271 272 Op->Asl.EndLine = Neighbor->Asl.EndLine; 273 Op->Asl.EndLogicalLine = Neighbor->Asl.EndLogicalLine; 274 Op->Asl.LineNumber = Neighbor->Asl.LineNumber; 275 Op->Asl.LogicalByteOffset = Neighbor->Asl.LogicalByteOffset; 276 Op->Asl.LogicalLineNumber = Neighbor->Asl.LogicalLineNumber; 277 } 278 279 280 /******************************************************************************* 281 * 282 * FUNCTION: TrAmlInitNode 283 * 284 * PARAMETERS: Op - Op to be initialized 285 * ParseOpcode - Opcode for this node 286 * 287 * RETURN: None 288 * 289 * DESCRIPTION: Initialize a node with the parse opcode and opcode name. 290 * 291 ******************************************************************************/ 292 293 static void 294 TrAmlInitNode ( 295 ACPI_PARSE_OBJECT *Op, 296 UINT16 ParseOpcode) 297 { 298 299 Op->Asl.ParseOpcode = ParseOpcode; 300 UtSetParseOpName (Op); 301 } 302 303 304 /******************************************************************************* 305 * 306 * FUNCTION: TrAmlSetSubtreeParent 307 * 308 * PARAMETERS: Op - First node in a list of peer nodes 309 * Parent - Parent of the subtree 310 * 311 * RETURN: None 312 * 313 * DESCRIPTION: Set the parent for all peer nodes in a subtree 314 * 315 ******************************************************************************/ 316 317 static void 318 TrAmlSetSubtreeParent ( 319 ACPI_PARSE_OBJECT *Op, 320 ACPI_PARSE_OBJECT *Parent) 321 { 322 ACPI_PARSE_OBJECT *Next; 323 324 325 Next = Op; 326 while (Next) 327 { 328 Next->Asl.Parent = Parent; 329 Next = Next->Asl.Next; 330 } 331 } 332 333 334 /******************************************************************************* 335 * 336 * FUNCTION: TrAmlInsertPeer 337 * 338 * PARAMETERS: Op - First node in a list of peer nodes 339 * NewPeer - Peer node to insert 340 * 341 * RETURN: None 342 * 343 * DESCRIPTION: Insert a new peer node into a list of peers. 344 * 345 ******************************************************************************/ 346 347 static void 348 TrAmlInsertPeer ( 349 ACPI_PARSE_OBJECT *Op, 350 ACPI_PARSE_OBJECT *NewPeer) 351 { 352 353 NewPeer->Asl.Next = Op->Asl.Next; 354 Op->Asl.Next = NewPeer; 355 } 356 357 358 /******************************************************************************* 359 * 360 * FUNCTION: TrAmlTransformWalkBegin 361 * 362 * PARAMETERS: ASL_WALK_CALLBACK 363 * 364 * RETURN: None 365 * 366 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML 367 * operands. 368 * 369 ******************************************************************************/ 370 371 ACPI_STATUS 372 TrAmlTransformWalkBegin ( 373 ACPI_PARSE_OBJECT *Op, 374 UINT32 Level, 375 void *Context) 376 { 377 378 TrTransformSubtree (Op); 379 return (AE_OK); 380 } 381 382 383 /******************************************************************************* 384 * 385 * FUNCTION: TrAmlTransformWalkEnd 386 * 387 * PARAMETERS: ASL_WALK_CALLBACK 388 * 389 * RETURN: None 390 * 391 * DESCRIPTION: Parse tree walk to generate both the AML opcodes and the AML 392 * operands. 393 * 394 ******************************************************************************/ 395 396 ACPI_STATUS 397 TrAmlTransformWalkEnd ( 398 ACPI_PARSE_OBJECT *Op, 399 UINT32 Level, 400 void *Context) 401 { 402 403 /* Save possible Externals list in the DefintionBlock Op */ 404 405 if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK) 406 { 407 Op->Asl.Value.Arg = AslGbl_ExternalsListHead; 408 AslGbl_ExternalsListHead = NULL; 409 } 410 411 return (AE_OK); 412 } 413 414 415 /******************************************************************************* 416 * 417 * FUNCTION: TrTransformSubtree 418 * 419 * PARAMETERS: Op - The parent parse node 420 * 421 * RETURN: None 422 * 423 * DESCRIPTION: Prepare nodes to be output as AML data and operands. The more 424 * complex AML opcodes require processing of the child nodes 425 * (arguments/operands). 426 * 427 ******************************************************************************/ 428 429 static void 430 TrTransformSubtree ( 431 ACPI_PARSE_OBJECT *Op) 432 { 433 ACPI_PARSE_OBJECT *MethodOp; 434 435 436 if (Op->Asl.AmlOpcode == AML_RAW_DATA_BYTE) 437 { 438 return; 439 } 440 441 switch (Op->Asl.ParseOpcode) 442 { 443 case PARSEOP_DEFINITION_BLOCK: 444 445 TrDoDefinitionBlock (Op); 446 break; 447 448 case PARSEOP_SWITCH: 449 450 TrDoSwitch (Op); 451 break; 452 453 case PARSEOP_METHOD: 454 /* 455 * TBD: Zero the tempname (_T_x) count. Probably shouldn't be a global, 456 * however 457 */ 458 AslGbl_TempCount = 0; 459 break; 460 461 case PARSEOP_EXTERNAL: 462 463 ExDoExternal (Op); 464 break; 465 466 case PARSEOP___METHOD__: 467 468 /* Transform to a string op containing the parent method name */ 469 470 Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL; 471 UtSetParseOpName (Op); 472 473 /* Find the parent control method op */ 474 475 MethodOp = Op; 476 while (MethodOp) 477 { 478 if (MethodOp->Asl.ParseOpcode == PARSEOP_METHOD) 479 { 480 /* First child contains the method name */ 481 482 MethodOp = MethodOp->Asl.Child; 483 Op->Asl.Value.String = MethodOp->Asl.Value.String; 484 return; 485 } 486 487 MethodOp = MethodOp->Asl.Parent; 488 } 489 490 /* At the root, invocation not within a control method */ 491 492 Op->Asl.Value.String = "\\"; 493 break; 494 495 case PARSEOP_UNLOAD: 496 497 AslError (ASL_WARNING, ASL_MSG_UNLOAD, Op, NULL); 498 break; 499 500 case PARSEOP_SLEEP: 501 502 /* Remark for very long sleep values */ 503 504 if (Op->Asl.Child->Asl.Value.Integer > 1000) 505 { 506 AslError (ASL_REMARK, ASL_MSG_LONG_SLEEP, Op, NULL); 507 } 508 break; 509 510 case PARSEOP_PROCESSOR: 511 512 AslError (ASL_WARNING, ASL_MSG_LEGACY_PROCESSOR_OP, Op, Op->Asl.ExternalName); 513 514 break; 515 516 default: 517 518 /* Nothing to do here for other opcodes */ 519 520 break; 521 } 522 } 523 524 525 /******************************************************************************* 526 * 527 * FUNCTION: TrDoDefinitionBlock 528 * 529 * PARAMETERS: Op - Parse node 530 * 531 * RETURN: None 532 * 533 * DESCRIPTION: Find the end of the definition block and set a global to this 534 * node. It is used by the compiler to insert compiler-generated 535 * names at the root level of the namespace. 536 * 537 ******************************************************************************/ 538 539 static void 540 TrDoDefinitionBlock ( 541 ACPI_PARSE_OBJECT *Op) 542 { 543 ACPI_PARSE_OBJECT *Next; 544 UINT32 i; 545 546 547 /* Reset external list when starting a definition block */ 548 549 AslGbl_ExternalsListHead = NULL; 550 551 Next = Op->Asl.Child; 552 for (i = 0; i < 5; i++) 553 { 554 Next = Next->Asl.Next; 555 if (i == 0) 556 { 557 /* 558 * This is the table signature. Only the DSDT can be assumed 559 * to be at the root of the namespace; Therefore, namepath 560 * optimization can only be performed on the DSDT. 561 */ 562 if (!ACPI_COMPARE_NAMESEG (Next->Asl.Value.String, ACPI_SIG_DSDT)) 563 { 564 AslGbl_ReferenceOptimizationFlag = FALSE; 565 } 566 } 567 } 568 569 AslGbl_FirstLevelInsertionNode = Next; 570 } 571 572 573 /******************************************************************************* 574 * 575 * FUNCTION: TrDoSwitch 576 * 577 * PARAMETERS: StartNode - Parse node for SWITCH 578 * 579 * RETURN: None 580 * 581 * DESCRIPTION: Translate ASL SWITCH statement to if/else pairs. There is 582 * no actual AML opcode for SWITCH -- it must be simulated. 583 * 584 ******************************************************************************/ 585 586 static void 587 TrDoSwitch ( 588 ACPI_PARSE_OBJECT *StartNode) 589 { 590 ACPI_PARSE_OBJECT *Next; 591 ACPI_PARSE_OBJECT *CaseOp = NULL; 592 ACPI_PARSE_OBJECT *CaseBlock = NULL; 593 ACPI_PARSE_OBJECT *DefaultOp = NULL; 594 ACPI_PARSE_OBJECT *CurrentParentNode; 595 ACPI_PARSE_OBJECT *Conditional = NULL; 596 ACPI_PARSE_OBJECT *Predicate; 597 ACPI_PARSE_OBJECT *Peer; 598 ACPI_PARSE_OBJECT *NewOp; 599 ACPI_PARSE_OBJECT *NewOp2; 600 ACPI_PARSE_OBJECT *MethodOp; 601 ACPI_PARSE_OBJECT *StoreOp; 602 ACPI_PARSE_OBJECT *BreakOp; 603 ACPI_PARSE_OBJECT *BufferOp; 604 char *PredicateValueName; 605 UINT16 Index; 606 UINT32 Btype; 607 608 609 /* Start node is the Switch() node */ 610 611 CurrentParentNode = StartNode; 612 613 /* Create a new temp name of the form _T_x */ 614 615 PredicateValueName = TrAmlGetNextTempName (StartNode, &AslGbl_TempCount); 616 if (!PredicateValueName) 617 { 618 return; 619 } 620 621 /* First child is the Switch() predicate */ 622 623 Next = StartNode->Asl.Child; 624 625 /* 626 * Examine the return type of the Switch Value - 627 * must be Integer/Buffer/String 628 */ 629 Index = (UINT16) (Next->Asl.ParseOpcode - ASL_PARSE_OPCODE_BASE); 630 Btype = AslKeywordMapping[Index].AcpiBtype; 631 if ((Btype != ACPI_BTYPE_INTEGER) && 632 (Btype != ACPI_BTYPE_STRING) && 633 (Btype != ACPI_BTYPE_BUFFER)) 634 { 635 AslError (ASL_WARNING, ASL_MSG_SWITCH_TYPE, Next, NULL); 636 Btype = ACPI_BTYPE_INTEGER; 637 } 638 639 /* CASE statements start at next child */ 640 641 Peer = Next->Asl.Next; 642 while (Peer) 643 { 644 Next = Peer; 645 Peer = Next->Asl.Next; 646 647 if (Next->Asl.ParseOpcode == PARSEOP_CASE) 648 { 649 if (CaseOp) 650 { 651 /* Add an ELSE to complete the previous CASE */ 652 653 NewOp = TrCreateLeafOp (PARSEOP_ELSE); 654 NewOp->Asl.Parent = Conditional->Asl.Parent; 655 TrAmlInitLineNumbers (NewOp, NewOp->Asl.Parent); 656 657 /* Link ELSE node as a peer to the previous IF */ 658 659 TrAmlInsertPeer (Conditional, NewOp); 660 CurrentParentNode = NewOp; 661 } 662 663 CaseOp = Next; 664 Conditional = CaseOp; 665 CaseBlock = CaseOp->Asl.Child->Asl.Next; 666 Conditional->Asl.Child->Asl.Next = NULL; 667 Predicate = CaseOp->Asl.Child; 668 669 if ((Predicate->Asl.ParseOpcode == PARSEOP_PACKAGE) || 670 (Predicate->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)) 671 { 672 /* 673 * Convert the package declaration to this form: 674 * 675 * If (LNotEqual (Match (Package(<size>){<data>}, 676 * MEQ, _T_x, MTR, Zero, Zero), Ones)) 677 */ 678 NewOp2 = TrCreateLeafOp (PARSEOP_MATCHTYPE_MEQ); 679 Predicate->Asl.Next = NewOp2; 680 TrAmlInitLineNumbers (NewOp2, Conditional); 681 682 NewOp = NewOp2; 683 NewOp2 = TrCreateValuedLeafOp (PARSEOP_NAMESTRING, 684 (UINT64) ACPI_TO_INTEGER (PredicateValueName)); 685 NewOp->Asl.Next = NewOp2; 686 TrAmlInitLineNumbers (NewOp2, Predicate); 687 688 NewOp = NewOp2; 689 NewOp2 = TrCreateLeafOp (PARSEOP_MATCHTYPE_MTR); 690 NewOp->Asl.Next = NewOp2; 691 TrAmlInitLineNumbers (NewOp2, Predicate); 692 693 NewOp = NewOp2; 694 NewOp2 = TrCreateLeafOp (PARSEOP_ZERO); 695 NewOp->Asl.Next = NewOp2; 696 TrAmlInitLineNumbers (NewOp2, Predicate); 697 698 NewOp = NewOp2; 699 NewOp2 = TrCreateLeafOp (PARSEOP_ZERO); 700 NewOp->Asl.Next = NewOp2; 701 TrAmlInitLineNumbers (NewOp2, Predicate); 702 703 NewOp2 = TrCreateLeafOp (PARSEOP_MATCH); 704 NewOp2->Asl.Child = Predicate; /* PARSEOP_PACKAGE */ 705 TrAmlInitLineNumbers (NewOp2, Conditional); 706 TrAmlSetSubtreeParent (Predicate, NewOp2); 707 708 NewOp = NewOp2; 709 NewOp2 = TrCreateLeafOp (PARSEOP_ONES); 710 NewOp->Asl.Next = NewOp2; 711 TrAmlInitLineNumbers (NewOp2, Conditional); 712 713 NewOp2 = TrCreateLeafOp (PARSEOP_LEQUAL); 714 NewOp2->Asl.Child = NewOp; 715 NewOp->Asl.Parent = NewOp2; 716 TrAmlInitLineNumbers (NewOp2, Conditional); 717 TrAmlSetSubtreeParent (NewOp, NewOp2); 718 719 NewOp = NewOp2; 720 NewOp2 = TrCreateLeafOp (PARSEOP_LNOT); 721 NewOp2->Asl.Child = NewOp; 722 NewOp2->Asl.Parent = Conditional; 723 NewOp->Asl.Parent = NewOp2; 724 TrAmlInitLineNumbers (NewOp2, Conditional); 725 726 Conditional->Asl.Child = NewOp2; 727 NewOp2->Asl.Next = CaseBlock; 728 } 729 else 730 { 731 /* 732 * Integer and Buffer case. 733 * 734 * Change CaseOp() to: If (LEqual (SwitchValue, CaseValue)) {...} 735 * Note: SwitchValue is first to allow the CaseValue to be implicitly 736 * converted to the type of SwitchValue if necessary. 737 * 738 * CaseOp->Child is the case value 739 * CaseOp->Child->Peer is the beginning of the case block 740 */ 741 NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESTRING, 742 (UINT64) ACPI_TO_INTEGER (PredicateValueName)); 743 NewOp->Asl.Next = Predicate; 744 TrAmlInitLineNumbers (NewOp, Predicate); 745 746 NewOp2 = TrCreateLeafOp (PARSEOP_LEQUAL); 747 NewOp2->Asl.Parent = Conditional; 748 NewOp2->Asl.Child = NewOp; 749 TrAmlInitLineNumbers (NewOp2, Conditional); 750 751 TrAmlSetSubtreeParent (NewOp, NewOp2); 752 753 Predicate = NewOp2; 754 Predicate->Asl.Next = CaseBlock; 755 756 TrAmlSetSubtreeParent (Predicate, Conditional); 757 Conditional->Asl.Child = Predicate; 758 } 759 760 /* Reinitialize the CASE node to an IF node */ 761 762 TrAmlInitNode (Conditional, PARSEOP_IF); 763 764 /* 765 * The first CASE(IF) is not nested under an ELSE. 766 * All other CASEs are children of a parent ELSE. 767 */ 768 if (CurrentParentNode == StartNode) 769 { 770 Conditional->Asl.Next = NULL; 771 } 772 else 773 { 774 /* 775 * The IF is a child of previous IF/ELSE. It 776 * is therefore without peer. 777 */ 778 CurrentParentNode->Asl.Child = Conditional; 779 Conditional->Asl.Parent = CurrentParentNode; 780 Conditional->Asl.Next = NULL; 781 } 782 } 783 else if (Next->Asl.ParseOpcode == PARSEOP_DEFAULT) 784 { 785 if (DefaultOp) 786 { 787 /* 788 * More than one Default 789 * (Parser does not catch this, must check here) 790 */ 791 AslError (ASL_ERROR, ASL_MSG_MULTIPLE_DEFAULT, Next, NULL); 792 } 793 else 794 { 795 /* Save the DEFAULT node for later, after CASEs */ 796 797 DefaultOp = Next; 798 } 799 } 800 else 801 { 802 /* Unknown peer opcode */ 803 804 AcpiOsPrintf ("Unknown parse opcode for switch statement: %s (%u)\n", 805 Next->Asl.ParseOpName, Next->Asl.ParseOpcode); 806 } 807 } 808 809 /* Add the default case at the end of the if/else construct */ 810 811 if (DefaultOp) 812 { 813 /* If no CASE statements, this is an error - see below */ 814 815 if (CaseOp) 816 { 817 /* Convert the DEFAULT node to an ELSE */ 818 819 TrAmlInitNode (DefaultOp, PARSEOP_ELSE); 820 DefaultOp->Asl.Parent = Conditional->Asl.Parent; 821 822 /* Link ELSE node as a peer to the previous IF */ 823 824 TrAmlInsertPeer (Conditional, DefaultOp); 825 } 826 } 827 828 if (!CaseOp) 829 { 830 AslError (ASL_ERROR, ASL_MSG_NO_CASES, StartNode, NULL); 831 } 832 833 834 /* 835 * Create a Name(_T_x, ...) statement. This statement must appear at the 836 * method level, in case a loop surrounds the switch statement and could 837 * cause the name to be created twice (error). 838 */ 839 840 /* Create the Name node */ 841 842 Predicate = StartNode->Asl.Child; 843 NewOp = TrCreateLeafOp (PARSEOP_NAME); 844 TrAmlInitLineNumbers (NewOp, StartNode); 845 846 /* Find the parent method */ 847 848 Next = StartNode; 849 while ((Next->Asl.ParseOpcode != PARSEOP_METHOD) && 850 (Next->Asl.ParseOpcode != PARSEOP_DEFINITION_BLOCK)) 851 { 852 Next = Next->Asl.Parent; 853 } 854 MethodOp = Next; 855 856 NewOp->Asl.CompileFlags |= OP_COMPILER_EMITTED; 857 NewOp->Asl.Parent = Next; 858 859 /* Insert name after the method name and arguments */ 860 861 Next = Next->Asl.Child; /* Name */ 862 Next = Next->Asl.Next; /* NumArgs */ 863 Next = Next->Asl.Next; /* SerializeRule */ 864 865 /* 866 * If method is not Serialized, we must make is so, because of the way 867 * that Switch() must be implemented -- we cannot allow multiple threads 868 * to execute this method concurrently since we need to create local 869 * temporary name(s). 870 */ 871 if (Next->Asl.ParseOpcode != PARSEOP_SERIALIZERULE_SERIAL) 872 { 873 AslError (ASL_REMARK, ASL_MSG_SERIALIZED, MethodOp, 874 "Due to use of Switch operator"); 875 Next->Asl.ParseOpcode = PARSEOP_SERIALIZERULE_SERIAL; 876 } 877 878 Next = Next->Asl.Next; /* SyncLevel */ 879 Next = Next->Asl.Next; /* ReturnType */ 880 Next = Next->Asl.Next; /* ParameterTypes */ 881 882 TrAmlInsertPeer (Next, NewOp); 883 TrAmlInitLineNumbers (NewOp, Next); 884 885 /* Create the NameSeg child for the Name node */ 886 887 NewOp2 = TrCreateValuedLeafOp (PARSEOP_NAMESEG, 888 (UINT64) ACPI_TO_INTEGER (PredicateValueName)); 889 TrAmlInitLineNumbers (NewOp2, NewOp); 890 NewOp2->Asl.CompileFlags |= OP_IS_NAME_DECLARATION; 891 NewOp->Asl.Child = NewOp2; 892 893 /* Create the initial value for the Name. Btype was already validated above */ 894 895 switch (Btype) 896 { 897 case ACPI_BTYPE_INTEGER: 898 899 NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_ZERO, 900 (UINT64) 0); 901 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp); 902 break; 903 904 case ACPI_BTYPE_STRING: 905 906 NewOp2->Asl.Next = TrCreateValuedLeafOp (PARSEOP_STRING_LITERAL, 907 (UINT64) ACPI_TO_INTEGER ("")); 908 TrAmlInitLineNumbers (NewOp2->Asl.Next, NewOp); 909 break; 910 911 case ACPI_BTYPE_BUFFER: 912 913 (void) TrLinkPeerOp (NewOp2, TrCreateValuedLeafOp (PARSEOP_BUFFER, 914 (UINT64) 0)); 915 Next = NewOp2->Asl.Next; 916 TrAmlInitLineNumbers (Next, NewOp2); 917 918 (void) TrLinkOpChildren (Next, 1, TrCreateValuedLeafOp (PARSEOP_ZERO, 919 (UINT64) 1)); 920 TrAmlInitLineNumbers (Next->Asl.Child, Next); 921 922 BufferOp = TrCreateValuedLeafOp (PARSEOP_DEFAULT_ARG, (UINT64) 0); 923 TrAmlInitLineNumbers (BufferOp, Next->Asl.Child); 924 (void) TrLinkPeerOp (Next->Asl.Child, BufferOp); 925 926 TrAmlSetSubtreeParent (Next->Asl.Child, Next); 927 break; 928 929 default: 930 931 break; 932 } 933 934 TrAmlSetSubtreeParent (NewOp2, NewOp); 935 936 /* 937 * Transform the Switch() into a While(One)-Break node. 938 * And create a Store() node which will be used to save the 939 * Switch() value. The store is of the form: Store (Value, _T_x) 940 * where _T_x is the temp variable. 941 */ 942 TrAmlInitNode (StartNode, PARSEOP_WHILE); 943 NewOp = TrCreateLeafOp (PARSEOP_ONE); 944 TrAmlInitLineNumbers (NewOp, StartNode); 945 NewOp->Asl.Next = Predicate->Asl.Next; 946 NewOp->Asl.Parent = StartNode; 947 StartNode->Asl.Child = NewOp; 948 949 /* Create a Store() node */ 950 951 StoreOp = TrCreateLeafOp (PARSEOP_STORE); 952 TrAmlInitLineNumbers (StoreOp, NewOp); 953 StoreOp->Asl.Parent = StartNode; 954 TrAmlInsertPeer (NewOp, StoreOp); 955 956 /* Complete the Store subtree */ 957 958 StoreOp->Asl.Child = Predicate; 959 Predicate->Asl.Parent = StoreOp; 960 961 NewOp = TrCreateValuedLeafOp (PARSEOP_NAMESEG, 962 (UINT64) ACPI_TO_INTEGER (PredicateValueName)); 963 TrAmlInitLineNumbers (NewOp, StoreOp); 964 NewOp->Asl.Parent = StoreOp; 965 Predicate->Asl.Next = NewOp; 966 967 /* Create a Break() node and insert it into the end of While() */ 968 969 Conditional = StartNode->Asl.Child; 970 while (Conditional->Asl.Next) 971 { 972 Conditional = Conditional->Asl.Next; 973 } 974 975 BreakOp = TrCreateLeafOp (PARSEOP_BREAK); 976 TrAmlInitLineNumbers (BreakOp, NewOp); 977 BreakOp->Asl.Parent = StartNode; 978 TrAmlInsertPeer (Conditional, BreakOp); 979 } 980