1 /****************************************************************************** 2 * 3 * Module Name: psobject - Support for parse objects 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2017, 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/include/acpi.h> 153 #include <contrib/dev/acpica/include/accommon.h> 154 #include <contrib/dev/acpica/include/acparser.h> 155 #include <contrib/dev/acpica/include/amlcode.h> 156 #include <contrib/dev/acpica/include/acconvert.h> 157 158 #define _COMPONENT ACPI_PARSER 159 ACPI_MODULE_NAME ("psobject") 160 161 162 /* Local prototypes */ 163 164 static ACPI_STATUS 165 AcpiPsGetAmlOpcode ( 166 ACPI_WALK_STATE *WalkState); 167 168 169 /******************************************************************************* 170 * 171 * FUNCTION: AcpiPsGetAmlOpcode 172 * 173 * PARAMETERS: WalkState - Current state 174 * 175 * RETURN: Status 176 * 177 * DESCRIPTION: Extract the next AML opcode from the input stream. 178 * 179 ******************************************************************************/ 180 181 static ACPI_STATUS 182 AcpiPsGetAmlOpcode ( 183 ACPI_WALK_STATE *WalkState) 184 { 185 UINT32 AmlOffset; 186 187 188 ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState); 189 190 191 WalkState->Aml = WalkState->ParserState.Aml; 192 WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState)); 193 194 /* 195 * First cut to determine what we have found: 196 * 1) A valid AML opcode 197 * 2) A name string 198 * 3) An unknown/invalid opcode 199 */ 200 WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode); 201 202 switch (WalkState->OpInfo->Class) 203 { 204 case AML_CLASS_ASCII: 205 case AML_CLASS_PREFIX: 206 /* 207 * Starts with a valid prefix or ASCII char, this is a name 208 * string. Convert the bare name string to a namepath. 209 */ 210 WalkState->Opcode = AML_INT_NAMEPATH_OP; 211 WalkState->ArgTypes = ARGP_NAMESTRING; 212 break; 213 214 case AML_CLASS_UNKNOWN: 215 216 /* The opcode is unrecognized. Complain and skip unknown opcodes */ 217 218 if (WalkState->PassNumber == 2) 219 { 220 AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml, 221 WalkState->ParserState.AmlStart); 222 223 ACPI_ERROR ((AE_INFO, 224 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring", 225 WalkState->Opcode, 226 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER)))); 227 228 ACPI_DUMP_BUFFER ((WalkState->ParserState.Aml - 16), 48); 229 230 #ifdef ACPI_ASL_COMPILER 231 /* 232 * This is executed for the disassembler only. Output goes 233 * to the disassembled ASL output file. 234 */ 235 AcpiOsPrintf ( 236 "/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n", 237 WalkState->Opcode, 238 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER))); 239 240 ACPI_ERROR ((AE_INFO, 241 "Aborting disassembly, AML byte code is corrupt")); 242 243 /* Dump the context surrounding the invalid opcode */ 244 245 AcpiUtDumpBuffer (((UINT8 *) WalkState->ParserState.Aml - 16), 246 48, DB_BYTE_DISPLAY, 247 (AmlOffset + sizeof (ACPI_TABLE_HEADER) - 16)); 248 AcpiOsPrintf (" */\n"); 249 250 /* 251 * Just abort the disassembly, cannot continue because the 252 * parser is essentially lost. The disassembler can then 253 * randomly fail because an ill-constructed parse tree 254 * can result. 255 */ 256 return_ACPI_STATUS (AE_AML_BAD_OPCODE); 257 #endif 258 } 259 260 /* Increment past one-byte or two-byte opcode */ 261 262 WalkState->ParserState.Aml++; 263 if (WalkState->Opcode > 0xFF) /* Can only happen if first byte is 0x5B */ 264 { 265 WalkState->ParserState.Aml++; 266 } 267 268 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 269 270 default: 271 272 /* Found opcode info, this is a normal opcode */ 273 274 WalkState->ParserState.Aml += 275 AcpiPsGetOpcodeSize (WalkState->Opcode); 276 WalkState->ArgTypes = WalkState->OpInfo->ParseArgs; 277 break; 278 } 279 280 return_ACPI_STATUS (AE_OK); 281 } 282 283 284 /******************************************************************************* 285 * 286 * FUNCTION: AcpiPsBuildNamedOp 287 * 288 * PARAMETERS: WalkState - Current state 289 * AmlOpStart - Begin of named Op in AML 290 * UnnamedOp - Early Op (not a named Op) 291 * Op - Returned Op 292 * 293 * RETURN: Status 294 * 295 * DESCRIPTION: Parse a named Op 296 * 297 ******************************************************************************/ 298 299 ACPI_STATUS 300 AcpiPsBuildNamedOp ( 301 ACPI_WALK_STATE *WalkState, 302 UINT8 *AmlOpStart, 303 ACPI_PARSE_OBJECT *UnnamedOp, 304 ACPI_PARSE_OBJECT **Op) 305 { 306 ACPI_STATUS Status = AE_OK; 307 ACPI_PARSE_OBJECT *Arg = NULL; 308 309 310 ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState); 311 312 313 UnnamedOp->Common.Value.Arg = NULL; 314 UnnamedOp->Common.ArgListLength = 0; 315 UnnamedOp->Common.AmlOpcode = WalkState->Opcode; 316 317 /* 318 * Get and append arguments until we find the node that contains 319 * the name (the type ARGP_NAME). 320 */ 321 while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) && 322 (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME)) 323 { 324 ASL_CV_CAPTURE_COMMENTS (WalkState); 325 Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState), 326 GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg); 327 if (ACPI_FAILURE (Status)) 328 { 329 return_ACPI_STATUS (Status); 330 } 331 332 AcpiPsAppendArg (UnnamedOp, Arg); 333 INCREMENT_ARG_LIST (WalkState->ArgTypes); 334 } 335 336 /* are there any inline comments associated with the NameSeg?? If so, save this. */ 337 338 ASL_CV_CAPTURE_COMMENTS (WalkState); 339 340 #ifdef ACPI_ASL_COMPILER 341 if (AcpiGbl_CurrentInlineComment != NULL) 342 { 343 UnnamedOp->Common.NameComment = AcpiGbl_CurrentInlineComment; 344 AcpiGbl_CurrentInlineComment = NULL; 345 } 346 #endif 347 348 /* 349 * Make sure that we found a NAME and didn't run out of arguments 350 */ 351 if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes)) 352 { 353 return_ACPI_STATUS (AE_AML_NO_OPERAND); 354 } 355 356 /* We know that this arg is a name, move to next arg */ 357 358 INCREMENT_ARG_LIST (WalkState->ArgTypes); 359 360 /* 361 * Find the object. This will either insert the object into 362 * the namespace or simply look it up 363 */ 364 WalkState->Op = NULL; 365 366 Status = WalkState->DescendingCallback (WalkState, Op); 367 if (ACPI_FAILURE (Status)) 368 { 369 if (Status != AE_CTRL_TERMINATE) 370 { 371 ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog")); 372 } 373 return_ACPI_STATUS (Status); 374 } 375 376 if (!*Op) 377 { 378 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 379 } 380 381 Status = AcpiPsNextParseState (WalkState, *Op, Status); 382 if (ACPI_FAILURE (Status)) 383 { 384 if (Status == AE_CTRL_PENDING) 385 { 386 Status = AE_CTRL_PARSE_PENDING; 387 } 388 return_ACPI_STATUS (Status); 389 } 390 391 AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg); 392 393 #ifdef ACPI_ASL_COMPILER 394 395 /* save any comments that might be associated with UnnamedOp. */ 396 397 (*Op)->Common.InlineComment = UnnamedOp->Common.InlineComment; 398 (*Op)->Common.EndNodeComment = UnnamedOp->Common.EndNodeComment; 399 (*Op)->Common.CloseBraceComment = UnnamedOp->Common.CloseBraceComment; 400 (*Op)->Common.NameComment = UnnamedOp->Common.NameComment; 401 (*Op)->Common.CommentList = UnnamedOp->Common.CommentList; 402 (*Op)->Common.EndBlkComment = UnnamedOp->Common.EndBlkComment; 403 (*Op)->Common.CvFilename = UnnamedOp->Common.CvFilename; 404 (*Op)->Common.CvParentFilename = UnnamedOp->Common.CvParentFilename; 405 (*Op)->Named.Aml = UnnamedOp->Common.Aml; 406 407 UnnamedOp->Common.InlineComment = NULL; 408 UnnamedOp->Common.EndNodeComment = NULL; 409 UnnamedOp->Common.CloseBraceComment = NULL; 410 UnnamedOp->Common.NameComment = NULL; 411 UnnamedOp->Common.CommentList = NULL; 412 UnnamedOp->Common.EndBlkComment = NULL; 413 #endif 414 415 if ((*Op)->Common.AmlOpcode == AML_REGION_OP || 416 (*Op)->Common.AmlOpcode == AML_DATA_REGION_OP) 417 { 418 /* 419 * Defer final parsing of an OperationRegion body, because we don't 420 * have enough info in the first pass to parse it correctly (i.e., 421 * there may be method calls within the TermArg elements of the body.) 422 * 423 * However, we must continue parsing because the opregion is not a 424 * standalone package -- we don't know where the end is at this point. 425 * 426 * (Length is unknown until parse of the body complete) 427 */ 428 (*Op)->Named.Data = AmlOpStart; 429 (*Op)->Named.Length = 0; 430 } 431 432 return_ACPI_STATUS (AE_OK); 433 } 434 435 436 /******************************************************************************* 437 * 438 * FUNCTION: AcpiPsCreateOp 439 * 440 * PARAMETERS: WalkState - Current state 441 * AmlOpStart - Op start in AML 442 * NewOp - Returned Op 443 * 444 * RETURN: Status 445 * 446 * DESCRIPTION: Get Op from AML 447 * 448 ******************************************************************************/ 449 450 ACPI_STATUS 451 AcpiPsCreateOp ( 452 ACPI_WALK_STATE *WalkState, 453 UINT8 *AmlOpStart, 454 ACPI_PARSE_OBJECT **NewOp) 455 { 456 ACPI_STATUS Status = AE_OK; 457 ACPI_PARSE_OBJECT *Op; 458 ACPI_PARSE_OBJECT *NamedOp = NULL; 459 ACPI_PARSE_OBJECT *ParentScope; 460 UINT8 ArgumentCount; 461 const ACPI_OPCODE_INFO *OpInfo; 462 463 464 ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState); 465 466 467 Status = AcpiPsGetAmlOpcode (WalkState); 468 if (Status == AE_CTRL_PARSE_CONTINUE) 469 { 470 return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE); 471 } 472 if (ACPI_FAILURE (Status)) 473 { 474 return_ACPI_STATUS (Status); 475 } 476 477 /* Create Op structure and append to parent's argument list */ 478 479 WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode); 480 Op = AcpiPsAllocOp (WalkState->Opcode, AmlOpStart); 481 if (!Op) 482 { 483 return_ACPI_STATUS (AE_NO_MEMORY); 484 } 485 486 if (WalkState->OpInfo->Flags & AML_NAMED) 487 { 488 Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp); 489 AcpiPsFreeOp (Op); 490 if (ACPI_FAILURE (Status)) 491 { 492 return_ACPI_STATUS (Status); 493 } 494 495 *NewOp = NamedOp; 496 return_ACPI_STATUS (AE_OK); 497 } 498 499 /* Not a named opcode, just allocate Op and append to parent */ 500 501 if (WalkState->OpInfo->Flags & AML_CREATE) 502 { 503 /* 504 * Backup to beginning of CreateXXXfield declaration 505 * BodyLength is unknown until we parse the body 506 */ 507 Op->Named.Data = AmlOpStart; 508 Op->Named.Length = 0; 509 } 510 511 if (WalkState->Opcode == AML_BANK_FIELD_OP) 512 { 513 /* 514 * Backup to beginning of BankField declaration 515 * BodyLength is unknown until we parse the body 516 */ 517 Op->Named.Data = AmlOpStart; 518 Op->Named.Length = 0; 519 } 520 521 ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState)); 522 AcpiPsAppendArg (ParentScope, Op); 523 524 if (ParentScope) 525 { 526 OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode); 527 if (OpInfo->Flags & AML_HAS_TARGET) 528 { 529 ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type); 530 if (ParentScope->Common.ArgListLength > ArgumentCount) 531 { 532 Op->Common.Flags |= ACPI_PARSEOP_TARGET; 533 } 534 } 535 536 /* 537 * Special case for both Increment() and Decrement(), where 538 * the lone argument is both a source and a target. 539 */ 540 else if ((ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) || 541 (ParentScope->Common.AmlOpcode == AML_DECREMENT_OP)) 542 { 543 Op->Common.Flags |= ACPI_PARSEOP_TARGET; 544 } 545 } 546 547 if (WalkState->DescendingCallback != NULL) 548 { 549 /* 550 * Find the object. This will either insert the object into 551 * the namespace or simply look it up 552 */ 553 WalkState->Op = *NewOp = Op; 554 555 Status = WalkState->DescendingCallback (WalkState, &Op); 556 Status = AcpiPsNextParseState (WalkState, Op, Status); 557 if (Status == AE_CTRL_PENDING) 558 { 559 Status = AE_CTRL_PARSE_PENDING; 560 } 561 } 562 563 return_ACPI_STATUS (Status); 564 } 565 566 567 /******************************************************************************* 568 * 569 * FUNCTION: AcpiPsCompleteOp 570 * 571 * PARAMETERS: WalkState - Current state 572 * Op - Returned Op 573 * Status - Parse status before complete Op 574 * 575 * RETURN: Status 576 * 577 * DESCRIPTION: Complete Op 578 * 579 ******************************************************************************/ 580 581 ACPI_STATUS 582 AcpiPsCompleteOp ( 583 ACPI_WALK_STATE *WalkState, 584 ACPI_PARSE_OBJECT **Op, 585 ACPI_STATUS Status) 586 { 587 ACPI_STATUS Status2; 588 589 590 ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState); 591 592 593 /* 594 * Finished one argument of the containing scope 595 */ 596 WalkState->ParserState.Scope->ParseScope.ArgCount--; 597 598 /* Close this Op (will result in parse subtree deletion) */ 599 600 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 601 if (ACPI_FAILURE (Status2)) 602 { 603 return_ACPI_STATUS (Status2); 604 } 605 606 *Op = NULL; 607 608 switch (Status) 609 { 610 case AE_OK: 611 612 break; 613 614 case AE_CTRL_TRANSFER: 615 616 /* We are about to transfer to a called method */ 617 618 WalkState->PrevOp = NULL; 619 WalkState->PrevArgTypes = WalkState->ArgTypes; 620 return_ACPI_STATUS (Status); 621 622 case AE_CTRL_END: 623 624 AcpiPsPopScope (&(WalkState->ParserState), Op, 625 &WalkState->ArgTypes, &WalkState->ArgCount); 626 627 if (*Op) 628 { 629 WalkState->Op = *Op; 630 WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode); 631 WalkState->Opcode = (*Op)->Common.AmlOpcode; 632 633 Status = WalkState->AscendingCallback (WalkState); 634 Status = AcpiPsNextParseState (WalkState, *Op, Status); 635 636 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 637 if (ACPI_FAILURE (Status2)) 638 { 639 return_ACPI_STATUS (Status2); 640 } 641 } 642 643 Status = AE_OK; 644 break; 645 646 case AE_CTRL_BREAK: 647 case AE_CTRL_CONTINUE: 648 649 /* Pop off scopes until we find the While */ 650 651 while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP)) 652 { 653 AcpiPsPopScope (&(WalkState->ParserState), Op, 654 &WalkState->ArgTypes, &WalkState->ArgCount); 655 } 656 657 /* Close this iteration of the While loop */ 658 659 WalkState->Op = *Op; 660 WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode); 661 WalkState->Opcode = (*Op)->Common.AmlOpcode; 662 663 Status = WalkState->AscendingCallback (WalkState); 664 Status = AcpiPsNextParseState (WalkState, *Op, Status); 665 666 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 667 if (ACPI_FAILURE (Status2)) 668 { 669 return_ACPI_STATUS (Status2); 670 } 671 672 Status = AE_OK; 673 break; 674 675 case AE_CTRL_TERMINATE: 676 677 /* Clean up */ 678 do 679 { 680 if (*Op) 681 { 682 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 683 if (ACPI_FAILURE (Status2)) 684 { 685 return_ACPI_STATUS (Status2); 686 } 687 688 AcpiUtDeleteGenericState ( 689 AcpiUtPopGenericState (&WalkState->ControlState)); 690 } 691 692 AcpiPsPopScope (&(WalkState->ParserState), Op, 693 &WalkState->ArgTypes, &WalkState->ArgCount); 694 695 } while (*Op); 696 697 return_ACPI_STATUS (AE_OK); 698 699 default: /* All other non-AE_OK status */ 700 701 do 702 { 703 if (*Op) 704 { 705 Status2 = AcpiPsCompleteThisOp (WalkState, *Op); 706 if (ACPI_FAILURE (Status2)) 707 { 708 return_ACPI_STATUS (Status2); 709 } 710 } 711 712 AcpiPsPopScope (&(WalkState->ParserState), Op, 713 &WalkState->ArgTypes, &WalkState->ArgCount); 714 715 } while (*Op); 716 717 718 #if 0 719 /* 720 * TBD: Cleanup parse ops on error 721 */ 722 if (*Op == NULL) 723 { 724 AcpiPsPopScope (ParserState, Op, 725 &WalkState->ArgTypes, &WalkState->ArgCount); 726 } 727 #endif 728 WalkState->PrevOp = NULL; 729 WalkState->PrevArgTypes = WalkState->ArgTypes; 730 return_ACPI_STATUS (Status); 731 } 732 733 /* This scope complete? */ 734 735 if (AcpiPsHasCompletedScope (&(WalkState->ParserState))) 736 { 737 AcpiPsPopScope (&(WalkState->ParserState), Op, 738 &WalkState->ArgTypes, &WalkState->ArgCount); 739 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op)); 740 } 741 else 742 { 743 *Op = NULL; 744 } 745 746 return_ACPI_STATUS (AE_OK); 747 } 748 749 750 /******************************************************************************* 751 * 752 * FUNCTION: AcpiPsCompleteFinalOp 753 * 754 * PARAMETERS: WalkState - Current state 755 * Op - Current Op 756 * Status - Current parse status before complete last 757 * Op 758 * 759 * RETURN: Status 760 * 761 * DESCRIPTION: Complete last Op. 762 * 763 ******************************************************************************/ 764 765 ACPI_STATUS 766 AcpiPsCompleteFinalOp ( 767 ACPI_WALK_STATE *WalkState, 768 ACPI_PARSE_OBJECT *Op, 769 ACPI_STATUS Status) 770 { 771 ACPI_STATUS Status2; 772 773 774 ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState); 775 776 777 /* 778 * Complete the last Op (if not completed), and clear the scope stack. 779 * It is easily possible to end an AML "package" with an unbounded number 780 * of open scopes (such as when several ASL blocks are closed with 781 * sequential closing braces). We want to terminate each one cleanly. 782 */ 783 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op)); 784 do 785 { 786 if (Op) 787 { 788 if (WalkState->AscendingCallback != NULL) 789 { 790 WalkState->Op = Op; 791 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode); 792 WalkState->Opcode = Op->Common.AmlOpcode; 793 794 Status = WalkState->AscendingCallback (WalkState); 795 Status = AcpiPsNextParseState (WalkState, Op, Status); 796 if (Status == AE_CTRL_PENDING) 797 { 798 Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK); 799 if (ACPI_FAILURE (Status)) 800 { 801 return_ACPI_STATUS (Status); 802 } 803 } 804 805 if (Status == AE_CTRL_TERMINATE) 806 { 807 Status = AE_OK; 808 809 /* Clean up */ 810 do 811 { 812 if (Op) 813 { 814 Status2 = AcpiPsCompleteThisOp (WalkState, Op); 815 if (ACPI_FAILURE (Status2)) 816 { 817 return_ACPI_STATUS (Status2); 818 } 819 } 820 821 AcpiPsPopScope (&(WalkState->ParserState), &Op, 822 &WalkState->ArgTypes, &WalkState->ArgCount); 823 824 } while (Op); 825 826 return_ACPI_STATUS (Status); 827 } 828 829 else if (ACPI_FAILURE (Status)) 830 { 831 /* First error is most important */ 832 833 (void) AcpiPsCompleteThisOp (WalkState, Op); 834 return_ACPI_STATUS (Status); 835 } 836 } 837 838 Status2 = AcpiPsCompleteThisOp (WalkState, Op); 839 if (ACPI_FAILURE (Status2)) 840 { 841 return_ACPI_STATUS (Status2); 842 } 843 } 844 845 AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes, 846 &WalkState->ArgCount); 847 848 } while (Op); 849 850 return_ACPI_STATUS (Status); 851 } 852