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