- Timestamp:
- Feb 5, 2025 6:38:43 PM (3 months ago)
- svn:sync-xref-src-repo-rev:
- 167381
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/acpi/acpi-ast.cpp
r108060 r108087 91 91 92 92 93 DECLHIDDEN(int) rtAcpiAstNodeTransform(PRTACPIASTNODE pAstNd, PRTERRINFO pErrInfo) 94 { 95 #if 0 96 /* Walk all arguments containing AST nodes first. */ 97 for (uint8_t i = 0; i < pAstNd->cArgs; i++) 98 { 99 if ( pAstNd->aArgs[i].enmType == kAcpiAstArgType_AstNode 100 && pAstNd->aArgs[i].u.pAstNd) 101 { 102 int rc = rtAcpiAstNodeTransform(pAstNd->aArgs[i].u.pAstNd, pErrInfo); 103 if (RT_FAILURE(rc)) 104 return rc; 105 } 106 } 107 108 if (pAstNd->fFlags & RTACPI_AST_NODE_F_NEW_SCOPE) 109 { 110 PRTACPIASTNODE pIt/*, pItPrev*/; 111 /* Do transformations on the nodes first. */ 112 RTListForEach(&pAstNd->LstScopeNodes, pIt, RTACPIASTNODE, NdAst) 113 { 114 int rc = rtAcpiAstNodeTransform(pIt, pErrInfo); 115 if (RT_FAILURE(rc)) 116 return rc; 117 } 118 119 /* Now do transformations on our level. */ 120 RTListForEachReverseSafe(&pAstNd->LstScopeNodes, pIt, pItPrev, RTACPIASTNODE, NdAst) 121 { 122 /* 123 * If there is an If AST node followed by Else we move the Else branch as the last 124 * statement in the If because when emitting to AML the Else is enclosed in the If 125 * package. 126 */ 127 if ( pIt->enmOp == kAcpiAstNodeOp_Else 128 && pItPrev 129 && pItPrev->enmOp == kAcpiAstNodeOp_If) 130 { 131 RTListNodeRemove(&pIt->NdAst); 132 RTListAppend(&pItPrev->LstScopeNodes, &pIt->NdAst); 133 } 134 } 135 } 136 #else 137 RT_NOREF(pAstNd, pErrInfo); 138 #endif 139 140 return VINF_SUCCESS; 141 } 142 143 144 /** 145 * Evaluates the given AST node to an integer if possible. 146 * 147 * @returns IPRT status code. 148 * @param pAstNd The AST node to evaluate. 149 * @param pu64 Where to store the integer on success. 150 */ 151 static int rtAcpiAstNodeEvaluateToInteger(PCRTACPIASTNODE pAstNd, uint64_t *pu64) 152 { 153 /* Easy way out?. */ 154 if (pAstNd->enmOp == kAcpiAstNodeOp_Number) 155 { 156 *pu64 = pAstNd->u64; 157 return VINF_SUCCESS; 158 } 159 160 if (pAstNd->enmOp == kAcpiAstNodeOp_One) 161 { 162 *pu64 = 1; 163 return VINF_SUCCESS; 164 } 165 166 if (pAstNd->enmOp == kAcpiAstNodeOp_Zero) 167 { 168 *pu64 = 0; 169 return VINF_SUCCESS; 170 } 171 172 /** @todo */ 173 return VERR_NOT_IMPLEMENTED; 174 } 175 176 93 177 static int rtAcpiAstDumpAstList(PCRTLISTANCHOR pLst, RTACPITBL hAcpiTbl) 94 178 { … … 107 191 DECLHIDDEN(int) rtAcpiAstDumpToTbl(PCRTACPIASTNODE pAstNd, RTACPITBL hAcpiTbl) 108 192 { 109 int rc ;193 int rc = VINF_SUCCESS; 110 194 111 195 switch (pAstNd->enmOp) 112 196 { 197 case kAcpiAstNodeOp_Identifier: 198 { 199 rc = RTAcpiTblNameStringAppend(hAcpiTbl, pAstNd->pszIde); 200 if (RT_SUCCESS(rc)) 201 { 202 for (uint8_t i = 0; i < pAstNd->cArgs; i++) 203 { 204 Assert(pAstNd->aArgs[i].enmType == kAcpiAstArgType_AstNode); 205 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[i].u.pAstNd, hAcpiTbl); 206 if (RT_FAILURE(rc)) 207 break; 208 } 209 } 210 break; 211 } 212 case kAcpiAstNodeOp_StringLiteral: 213 rc = RTAcpiTblStringAppend(hAcpiTbl, pAstNd->pszStrLit); 214 break; 215 case kAcpiAstNodeOp_Number: 216 rc = RTAcpiTblIntegerAppend(hAcpiTbl, pAstNd->u64); 217 break; 113 218 case kAcpiAstNodeOp_Scope: 114 219 { … … 168 273 rc = RTAcpiTblMethodStart(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString, 169 274 pAstNd->aArgs[1].u.u8, 170 pAstNd->aArgs[ 1].u.f ? RTACPI_METHOD_F_SERIALIZED : RTACPI_METHOD_F_NOT_SERIALIZED,171 pAstNd->aArgs[ 1].u.u8);275 pAstNd->aArgs[2].u.f ? RTACPI_METHOD_F_SERIALIZED : RTACPI_METHOD_F_NOT_SERIALIZED, 276 pAstNd->aArgs[3].u.u8); 172 277 if (RT_SUCCESS(rc)) 173 278 { … … 179 284 break; 180 285 } 286 case kAcpiAstNodeOp_Device: 287 { 288 AssertBreakStmt( pAstNd->cArgs == 1 289 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString, 290 rc = VERR_INTERNAL_ERROR); 291 rc = RTAcpiTblDeviceStart(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString); 292 if (RT_SUCCESS(rc)) 293 { 294 /* Walk all the other AST nodes. */ 295 rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl); 296 if (RT_SUCCESS(rc)) 297 rc = RTAcpiTblDeviceFinalize(hAcpiTbl); 298 } 299 break; 300 } 301 case kAcpiAstNodeOp_If: 302 { 303 AssertBreakStmt( pAstNd->cArgs == 1 304 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode, 305 rc = VERR_INTERNAL_ERROR); 306 rc = RTAcpiTblIfStart(hAcpiTbl); 307 if (RT_SUCCESS(rc)) 308 { 309 /* Predicate. */ 310 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[0].u.pAstNd, hAcpiTbl); 311 if (RT_SUCCESS(rc)) 312 { 313 /* Walk all the other AST nodes. */ 314 rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl); 315 if (RT_SUCCESS(rc)) 316 rc = RTAcpiTblIfFinalize(hAcpiTbl); 317 } 318 } 319 break; 320 } 321 case kAcpiAstNodeOp_Else: 322 { 323 AssertBreakStmt(pAstNd->cArgs == 0, rc = VERR_INTERNAL_ERROR); 324 rc = RTAcpiTblElseStart(hAcpiTbl); 325 if (RT_SUCCESS(rc)) 326 { 327 /* Walk all the other AST nodes. */ 328 rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl); 329 if (RT_SUCCESS(rc)) 330 rc = RTAcpiTblElseFinalize(hAcpiTbl); 331 } 332 break; 333 } 334 case kAcpiAstNodeOp_LAnd: 335 case kAcpiAstNodeOp_LEqual: 336 case kAcpiAstNodeOp_LGreater: 337 case kAcpiAstNodeOp_LGreaterEqual: 338 case kAcpiAstNodeOp_LLess: 339 case kAcpiAstNodeOp_LLessEqual: 340 case kAcpiAstNodeOp_LNotEqual: 341 { 342 AssertBreakStmt( pAstNd->cArgs == 2 343 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode 344 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_AstNode, 345 rc = VERR_INTERNAL_ERROR); 346 RTACPIBINARYOP enmOp; 347 switch (pAstNd->enmOp) 348 { 349 case kAcpiAstNodeOp_LAnd: enmOp = kAcpiBinaryOp_LAnd; break; 350 case kAcpiAstNodeOp_LEqual: enmOp = kAcpiBinaryOp_LEqual; break; 351 case kAcpiAstNodeOp_LGreater: enmOp = kAcpiBinaryOp_LGreater; break; 352 case kAcpiAstNodeOp_LGreaterEqual: enmOp = kAcpiBinaryOp_LGreaterEqual; break; 353 case kAcpiAstNodeOp_LLess: enmOp = kAcpiBinaryOp_LLess; break; 354 case kAcpiAstNodeOp_LLessEqual: enmOp = kAcpiBinaryOp_LLessEqual; break; 355 case kAcpiAstNodeOp_LNotEqual: enmOp = kAcpiBinaryOp_LNotEqual; break; 356 default: 357 AssertReleaseFailed(); /* Impossible */ 358 return VERR_INTERNAL_ERROR; 359 } 360 361 rc = RTAcpiTblBinaryOpAppend(hAcpiTbl, enmOp); 362 if (RT_SUCCESS(rc)) 363 { 364 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[0].u.pAstNd, hAcpiTbl); 365 if (RT_SUCCESS(rc)) 366 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[1].u.pAstNd, hAcpiTbl); 367 } 368 break; 369 } 370 case kAcpiAstNodeOp_LNot: 371 AssertFailed(); /** @todo */ 372 break; 373 case kAcpiAstNodeOp_Zero: 374 { 375 AssertBreakStmt(pAstNd->cArgs == 0, rc = VERR_INTERNAL_ERROR); 376 rc = RTAcpiTblIntegerAppend(hAcpiTbl, 0); 377 break; 378 } 379 case kAcpiAstNodeOp_One: 380 { 381 AssertBreakStmt(pAstNd->cArgs == 0, rc = VERR_INTERNAL_ERROR); 382 rc = RTAcpiTblIntegerAppend(hAcpiTbl, 1); 383 break; 384 } 385 case kAcpiAstNodeOp_Return: 386 { 387 AssertBreakStmt( pAstNd->cArgs == 1 388 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode, 389 rc = VERR_INTERNAL_ERROR); 390 rc = RTAcpiTblStmtSimpleAppend(hAcpiTbl, kAcpiStmt_Return); 391 if (RT_SUCCESS(rc)) 392 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[0].u.pAstNd, hAcpiTbl); 393 break; 394 } 395 case kAcpiAstNodeOp_Unicode: 396 { 397 AssertBreakStmt( pAstNd->cArgs == 1 398 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode 399 && pAstNd->aArgs[0].u.pAstNd->enmOp == kAcpiAstNodeOp_StringLiteral, 400 rc = VERR_INTERNAL_ERROR); 401 402 rc = RTAcpiTblStringAppendAsUtf16(hAcpiTbl, pAstNd->aArgs[0].u.pAstNd->pszStrLit); 403 break; 404 } 405 case kAcpiAstNodeOp_OperationRegion: 406 { 407 AssertBreakStmt( pAstNd->cArgs == 4 408 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString 409 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_RegionSpace 410 && pAstNd->aArgs[2].enmType == kAcpiAstArgType_AstNode 411 && pAstNd->aArgs[3].enmType == kAcpiAstArgType_AstNode, 412 rc = VERR_INTERNAL_ERROR); 413 414 rc = RTAcpiTblOpRegionAppendEx(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString, pAstNd->aArgs[1].u.enmRegionSpace); 415 if (RT_SUCCESS(rc)) 416 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[2].u.pAstNd, hAcpiTbl); 417 if (RT_SUCCESS(rc)) 418 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[3].u.pAstNd, hAcpiTbl); 419 break; 420 } 421 case kAcpiAstNodeOp_Field: 422 { 423 AssertBreakStmt( pAstNd->cArgs == 4 424 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString 425 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_FieldAcc 426 && pAstNd->aArgs[2].enmType == kAcpiAstArgType_Bool 427 && pAstNd->aArgs[3].enmType == kAcpiAstArgType_FieldUpdate, 428 rc = VERR_INTERNAL_ERROR); 429 430 rc = RTAcpiTblFieldAppend(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString, pAstNd->aArgs[1].u.enmFieldAcc, 431 pAstNd->aArgs[2].u.f, pAstNd->aArgs[3].u.enmFieldUpdate, pAstNd->Fields.paFields, 432 pAstNd->Fields.cFields); 433 break; 434 } 435 case kAcpiAstNodeOp_Name: 436 { 437 AssertBreakStmt( pAstNd->cArgs == 2 438 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_NameString 439 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_AstNode, 440 rc = VERR_INTERNAL_ERROR); 441 442 rc = RTAcpiTblNameAppend(hAcpiTbl, pAstNd->aArgs[0].u.pszNameString); 443 if (RT_SUCCESS(rc)) 444 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[1].u.pAstNd, hAcpiTbl); 445 break; 446 } 447 case kAcpiAstNodeOp_ResourceTemplate: 448 rc = RTAcpiTblResourceAppend(hAcpiTbl, pAstNd->hAcpiRes); 449 break; 450 case kAcpiAstNodeOp_Arg0: 451 case kAcpiAstNodeOp_Arg1: 452 case kAcpiAstNodeOp_Arg2: 453 case kAcpiAstNodeOp_Arg3: 454 case kAcpiAstNodeOp_Arg4: 455 case kAcpiAstNodeOp_Arg5: 456 case kAcpiAstNodeOp_Arg6: 457 rc = RTAcpiTblArgOpAppend(hAcpiTbl, pAstNd->enmOp - kAcpiAstNodeOp_Arg0); 458 break; 459 case kAcpiAstNodeOp_Local0: 460 case kAcpiAstNodeOp_Local1: 461 case kAcpiAstNodeOp_Local2: 462 case kAcpiAstNodeOp_Local3: 463 case kAcpiAstNodeOp_Local4: 464 case kAcpiAstNodeOp_Local5: 465 case kAcpiAstNodeOp_Local6: 466 case kAcpiAstNodeOp_Local7: 467 rc = RTAcpiTblLocalOpAppend(hAcpiTbl, pAstNd->enmOp - kAcpiAstNodeOp_Local0); 468 break; 469 case kAcpiAstNodeOp_Package: 470 { 471 AssertBreakStmt( pAstNd->cArgs == 1 472 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode, 473 rc = VERR_INTERNAL_ERROR); 474 475 /* Try to gather the number of elements. */ 476 uint64_t cElems = 0; 477 if (pAstNd->aArgs[0].u.pAstNd) 478 { 479 /* Try resolving to a constant expression. */ 480 rc = rtAcpiAstNodeEvaluateToInteger(pAstNd->aArgs[0].u.pAstNd, &cElems); 481 if (RT_FAILURE(rc)) 482 break; 483 } 484 else 485 { 486 /* Count elements. */ 487 PRTACPIASTNODE pIt; 488 RTListForEach(&pAstNd->LstScopeNodes, pIt, RTACPIASTNODE, NdAst) 489 { 490 cElems++; 491 } 492 } 493 if (RT_SUCCESS(rc)) 494 { 495 if (cElems > 255) 496 { 497 rc = VERR_BUFFER_OVERFLOW; 498 break; 499 } 500 501 rc = RTAcpiTblPackageStart(hAcpiTbl, (uint8_t)cElems); 502 if (RT_SUCCESS(rc)) 503 rc = rtAcpiAstDumpAstList(&pAstNd->LstScopeNodes, hAcpiTbl); 504 if (RT_SUCCESS(rc)) 505 rc = RTAcpiTblPackageFinalize(hAcpiTbl); 506 } 507 break; 508 } 509 case kAcpiAstNodeOp_Buffer: 510 { 511 AssertBreakStmt( pAstNd->cArgs == 1 512 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode, 513 rc = VERR_INTERNAL_ERROR); 514 515 /* Try to gather the number of elements. */ 516 uint64_t cElems = 0; 517 if (pAstNd->aArgs[0].u.pAstNd) 518 { 519 /* Try resolving to a constant expression. */ 520 rc = rtAcpiAstNodeEvaluateToInteger(pAstNd->aArgs[0].u.pAstNd, &cElems); 521 if (RT_FAILURE(rc)) 522 break; 523 } 524 else 525 { 526 /* Count elements. */ 527 PRTACPIASTNODE pIt; 528 RTListForEach(&pAstNd->LstScopeNodes, pIt, RTACPIASTNODE, NdAst) 529 { 530 cElems++; 531 } 532 } 533 534 if (RT_SUCCESS(rc)) 535 { 536 uint8_t *pb = (uint8_t *)RTMemAlloc(cElems); 537 if (pb) 538 { 539 uint64_t i = 0; 540 PRTACPIASTNODE pIt; 541 RTListForEach(&pAstNd->LstScopeNodes, pIt, RTACPIASTNODE, NdAst) 542 { 543 /* Try resolving to a constant expression. */ 544 uint64_t u64 = 0; 545 rc = rtAcpiAstNodeEvaluateToInteger(pIt, &u64); 546 if (RT_FAILURE(rc)) 547 break; 548 if (u64 > UINT8_MAX) 549 { 550 rc = VERR_BUFFER_OVERFLOW; 551 break; 552 } 553 554 pb[i++] = (uint8_t)u64; 555 } 556 557 if (RT_SUCCESS(rc)) 558 rc = RTAcpiTblBufferAppend(hAcpiTbl, pb, cElems); 559 RTMemFree(pb); 560 } 561 else 562 rc = VERR_NO_MEMORY; 563 } 564 break; 565 } 566 case kAcpiAstNodeOp_ToUuid: 567 { 568 AssertBreakStmt( pAstNd->cArgs == 1 569 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode 570 && pAstNd->aArgs[0].u.pAstNd->enmOp == kAcpiAstNodeOp_StringLiteral, 571 rc = VERR_INTERNAL_ERROR); 572 rc = RTAcpiTblUuidAppendFromStr(hAcpiTbl, pAstNd->aArgs[0].u.pAstNd->pszStrLit); 573 break; 574 } 575 case kAcpiAstNodeOp_Break: 576 { 577 AssertBreakStmt(pAstNd->cArgs == 0, rc = VERR_INTERNAL_ERROR); 578 rc = RTAcpiTblStmtSimpleAppend(hAcpiTbl, kAcpiStmt_Break); 579 break; 580 } 581 case kAcpiAstNodeOp_Continue: 582 { 583 AssertBreakStmt(pAstNd->cArgs == 0, rc = VERR_INTERNAL_ERROR); 584 rc = RTAcpiTblStmtSimpleAppend(hAcpiTbl, kAcpiStmt_Continue); 585 break; 586 } 587 case kAcpiAstNodeOp_DerefOf: 588 { 589 AssertBreakStmt( pAstNd->cArgs == 1 590 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode, 591 rc = VERR_INTERNAL_ERROR); 592 rc = RTAcpiTblStmtSimpleAppend(hAcpiTbl, kAcpiStmt_DerefOf); 593 if (RT_SUCCESS(rc)) 594 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[0].u.pAstNd, hAcpiTbl); 595 break; 596 } 597 case kAcpiAstNodeOp_Store: 598 { 599 AssertBreakStmt( pAstNd->cArgs == 2 600 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode 601 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_AstNode, 602 rc = VERR_INTERNAL_ERROR); 603 rc = RTAcpiTblStmtSimpleAppend(hAcpiTbl, kAcpiStmt_Store); 604 if (RT_SUCCESS(rc)) 605 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[0].u.pAstNd, hAcpiTbl); 606 if (RT_SUCCESS(rc)) 607 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[1].u.pAstNd, hAcpiTbl); 608 break; 609 } 610 case kAcpiAstNodeOp_Not: 611 { 612 AssertBreakStmt( pAstNd->cArgs == 2 613 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode 614 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_AstNode, 615 rc = VERR_INTERNAL_ERROR); 616 rc = RTAcpiTblStmtSimpleAppend(hAcpiTbl, kAcpiStmt_Store); 617 if (RT_SUCCESS(rc)) 618 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[0].u.pAstNd, hAcpiTbl); 619 if (RT_SUCCESS(rc)) 620 { 621 if (pAstNd->aArgs[2].u.pAstNd) 622 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[1].u.pAstNd, hAcpiTbl); 623 else 624 rc = RTAcpiTblNullNameAppend(hAcpiTbl); 625 } 626 break; 627 } 628 case kAcpiAstNodeOp_Index: 629 case kAcpiAstNodeOp_Add: 630 case kAcpiAstNodeOp_Subtract: 631 case kAcpiAstNodeOp_And: 632 case kAcpiAstNodeOp_Nand: 633 case kAcpiAstNodeOp_Or: 634 case kAcpiAstNodeOp_Xor: 635 { 636 AssertBreakStmt( pAstNd->cArgs == 3 637 && pAstNd->aArgs[0].enmType == kAcpiAstArgType_AstNode 638 && pAstNd->aArgs[1].enmType == kAcpiAstArgType_AstNode 639 && pAstNd->aArgs[2].enmType == kAcpiAstArgType_AstNode, 640 rc = VERR_INTERNAL_ERROR); 641 642 RTACPISTMT enmStmt; 643 switch (pAstNd->enmOp) 644 { 645 case kAcpiAstNodeOp_Index: enmStmt = kAcpiStmt_Index; break; 646 case kAcpiAstNodeOp_Add: enmStmt = kAcpiStmt_Add; break; 647 case kAcpiAstNodeOp_Subtract: enmStmt = kAcpiStmt_Subtract; break; 648 case kAcpiAstNodeOp_And: enmStmt = kAcpiStmt_And; break; 649 case kAcpiAstNodeOp_Nand: enmStmt = kAcpiStmt_Nand; break; 650 case kAcpiAstNodeOp_Or: enmStmt = kAcpiStmt_Or; break; 651 case kAcpiAstNodeOp_Xor: enmStmt = kAcpiStmt_Xor; break; 652 default: 653 AssertReleaseFailed(); /* Impossible */ 654 return VERR_INTERNAL_ERROR; 655 } 656 657 rc = RTAcpiTblStmtSimpleAppend(hAcpiTbl, enmStmt); 658 if (RT_SUCCESS(rc)) 659 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[0].u.pAstNd, hAcpiTbl); 660 if (RT_SUCCESS(rc)) 661 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[1].u.pAstNd, hAcpiTbl); 662 if (RT_SUCCESS(rc)) 663 { 664 if (pAstNd->aArgs[2].u.pAstNd) 665 rc = rtAcpiAstDumpToTbl(pAstNd->aArgs[2].u.pAstNd, hAcpiTbl); 666 else 667 rc = RTAcpiTblNullNameAppend(hAcpiTbl); 668 } 669 break; 670 } 671 case kAcpiAstNodeOp_Ones: 181 672 default: 182 673 AssertFailedStmt(rc = VERR_NOT_IMPLEMENTED); 183 674 } 184 675 676 AssertRC(rc); 185 677 return rc; 186 678 } -
trunk/src/VBox/Runtime/common/acpi/acpi-compiler.cpp
r108070 r108087 279 279 { RT_STR_TUPLE("INDEX"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Index }, 280 280 { RT_STR_TUPLE("STORE"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Store }, 281 { RT_STR_TUPLE("BREAK"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Break }, 282 { RT_STR_TUPLE("CONTINUE"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Continue }, 283 { RT_STR_TUPLE("ADD"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Add }, 284 { RT_STR_TUPLE("SUBTRACT"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Subtract }, 285 { RT_STR_TUPLE("AND"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_And }, 286 { RT_STR_TUPLE("NAND"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Nand }, 287 { RT_STR_TUPLE("OR"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Or }, 288 { RT_STR_TUPLE("XOR"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Xor }, 289 { RT_STR_TUPLE("NOT"), RTSCRIPTLEXTOKTYPE_KEYWORD, true, kAcpiAstNodeOp_Not }, 281 290 282 291 /* Keywords not in the operation parser table. */ … … 508 517 509 518 510 #if 0511 DECLINLINE(bool) rtAcpiAslLexerIsKeyword(PCRTACPIASLCU pThis, RTACPIASLTERMINAL enmTerm)512 {513 PCRTSCRIPTLEXTOKEN pTok;514 int rc = RTScriptLexQueryToken(pThis->hLexSource, &pTok);515 if (RT_FAILURE(rc))516 return false;517 518 if ( pTok->enmType == RTSCRIPTLEXTOKTYPE_KEYWORD519 && pTok->Type.Keyword.pKeyword->u64Val == (uint64_t)enmTerm)520 return true;521 522 return false;523 }524 #endif525 526 527 519 DECLINLINE(bool) rtAcpiAslLexerIsPunctuator(PCRTACPIASLCU pThis, RTACPIASLTERMINAL enmTerm) 528 520 { … … 1058 1050 1059 1051 /* Allocate the list to the node. */ 1060 pAstNd-> paFields = (PRTACPIFIELDENTRY)RTMemAllocZ(cFields * sizeof(aFieldEntries[0]));1061 if (!pAstNd-> paFields)1052 pAstNd->Fields.paFields = (PRTACPIFIELDENTRY)RTMemAllocZ(cFields * sizeof(aFieldEntries[0])); 1053 if (!pAstNd->Fields.paFields) 1062 1054 return RTErrInfoSetF(pThis->pErrInfo, VERR_NO_MEMORY, "Out of memory allocating field unit list with %u entries", cFields); 1063 1055 1064 1056 for (uint32_t i = 0; i < cFields; i++) 1065 pAstNd->paFields[i] = aFieldEntries[i]; 1066 1057 pAstNd->Fields.paFields[i] = aFieldEntries[i]; 1058 1059 pAstNd->Fields.cFields = cFields; 1067 1060 return VINF_SUCCESS; 1068 1061 } … … 1104 1097 switch (enmLockRule) 1105 1098 { 1106 case RTACPIASLTERMINAL_KEYWORD_LOCK: pAstNd->aArgs[ 1].u.f = true; break;1107 case RTACPIASLTERMINAL_KEYWORD_NO_LOCK: pAstNd->aArgs[ 1].u.f = false; break;1099 case RTACPIASLTERMINAL_KEYWORD_LOCK: pAstNd->aArgs[2].u.f = true; break; 1100 case RTACPIASLTERMINAL_KEYWORD_NO_LOCK: pAstNd->aArgs[2].u.f = false; break; 1108 1101 default: 1109 1102 AssertFailedReturn(VERR_INTERNAL_ERROR); … … 1114 1107 /* Must have an update rule defined. */ 1115 1108 RTACPIASL_PARSE_KEYWORD_LIST(enmUpdateRule, g_aenmUpdateRuleKeywords); 1116 pAstNd->aArgs[ 2].enmType = kAcpiAstArgType_FieldUpdate;1109 pAstNd->aArgs[3].enmType = kAcpiAstArgType_FieldUpdate; 1117 1110 switch (enmUpdateRule) 1118 1111 { 1119 case RTACPIASLTERMINAL_KEYWORD_PRESERVE: pAstNd->aArgs[ 2].u.enmFieldUpdate = kAcpiFieldUpdate_Preserve; break;1120 case RTACPIASLTERMINAL_KEYWORD_WRITE_AS_ONES: pAstNd->aArgs[ 2].u.enmFieldUpdate = kAcpiFieldUpdate_WriteAsOnes; break;1121 case RTACPIASLTERMINAL_KEYWORD_WRITE_AS_ZEROES: pAstNd->aArgs[ 2].u.enmFieldUpdate = kAcpiFieldUpdate_WriteAsZeroes; break;1112 case RTACPIASLTERMINAL_KEYWORD_PRESERVE: pAstNd->aArgs[3].u.enmFieldUpdate = kAcpiFieldUpdate_Preserve; break; 1113 case RTACPIASLTERMINAL_KEYWORD_WRITE_AS_ONES: pAstNd->aArgs[3].u.enmFieldUpdate = kAcpiFieldUpdate_WriteAsOnes; break; 1114 case RTACPIASLTERMINAL_KEYWORD_WRITE_AS_ZEROES: pAstNd->aArgs[3].u.enmFieldUpdate = kAcpiFieldUpdate_WriteAsZeroes; break; 1122 1115 default: 1123 1116 AssertFailedReturn(VERR_INTERNAL_ERROR); … … 1189 1182 1190 1183 RTACPIASL_PARSE_PUNCTUATOR(RTACPIASLTERMINAL_PUNCTUATOR_CLOSE_CURLY_BRACKET, '}'); 1191 return VINF_SUCCESS; 1184 rc = RTAcpiResourceSeal(hAcpiRes); 1185 if (RT_FAILURE(rc)) 1186 rc = RTErrInfoSetF(pThis->pErrInfo, rc, "Failed to seal the resource after being done parsing"); 1187 return rc; 1192 1188 } 1193 1189 … … 1343 1339 { \ 1344 1340 { kAcpiAstArgType_Invalid, { 0 } }, \ 1341 { kAcpiAstArgType_Invalid, { 0 } }, \ 1342 { kAcpiAstArgType_Invalid, { 0 } } \ 1343 } \ 1344 } 1345 1346 #define RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT(a_szKeyword, a_fFlags, a_enmArgType0, a_enmArgType1, a_enmArgTypeOpt0) \ 1347 { \ 1348 a_szKeyword, NULL, 2, 1, a_fFlags, \ 1349 { a_enmArgType0, \ 1350 a_enmArgType1, \ 1351 kAcpiAstArgType_Invalid, \ 1352 kAcpiAstArgType_Invalid, \ 1353 kAcpiAstArgType_Invalid}, \ 1354 { \ 1355 { a_enmArgTypeOpt0, { 0 } }, \ 1356 { kAcpiAstArgType_Invalid, { 0 } }, \ 1357 { kAcpiAstArgType_Invalid, { 0 } } \ 1358 } \ 1359 } 1360 1361 #define RTACPI_ASL_KEYWORD_DEFINE_1REQ_1OPT(a_szKeyword, a_fFlags, a_enmArgType0, a_enmArgTypeOpt0) \ 1362 { \ 1363 a_szKeyword, NULL, 1, 1, a_fFlags, \ 1364 { a_enmArgType0, \ 1365 kAcpiAstArgType_Invalid, \ 1366 kAcpiAstArgType_Invalid, \ 1367 kAcpiAstArgType_Invalid, \ 1368 kAcpiAstArgType_Invalid}, \ 1369 { \ 1370 { a_enmArgTypeOpt0, { 0 } }, \ 1345 1371 { kAcpiAstArgType_Invalid, { 0 } }, \ 1346 1372 { kAcpiAstArgType_Invalid, { 0 } } \ … … 1414 1440 /* kAcpiAstNodeOp_ToUUid */ RTACPI_ASL_KEYWORD_DEFINE_1REQ_0OPT("ToUUID", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode), 1415 1441 /* kAcpiAstNodeOp_DerefOf */ RTACPI_ASL_KEYWORD_DEFINE_1REQ_0OPT("DerefOf", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode), 1416 /* kAcpiAstNodeOp_Index */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_ 0OPT("Index", RTACPI_AST_NODE_F_DEFAULT,kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode),1442 /* kAcpiAstNodeOp_Index */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT("Index", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1417 1443 /* kAcpiAstNodeOp_Store */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_0OPT("Store", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1444 1445 /* kAcpiAstNodeOp_Break */ RTACPI_ASL_KEYWORD_DEFINE_0REQ_0OPT("Break", RTACPI_AST_NODE_F_DEFAULT), 1446 /* kAcpiAstNodeOp_Continue */ RTACPI_ASL_KEYWORD_DEFINE_0REQ_0OPT("Continue", RTACPI_AST_NODE_F_DEFAULT), 1447 /* kAcpiAstNodeOp_Add */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT("Add", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1448 /* kAcpiAstNodeOp_Subtract */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT("Subtract", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1449 /* kAcpiAstNodeOp_And */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT("And", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1450 /* kAcpiAstNodeOp_Nand */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT("Nand", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1451 /* kAcpiAstNodeOp_Or */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT("Or", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1452 /* kAcpiAstNodeOp_Xor */ RTACPI_ASL_KEYWORD_DEFINE_2REQ_1OPT("Xor", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1453 /* kAcpiAstNodeOp_Not */ RTACPI_ASL_KEYWORD_DEFINE_1REQ_1OPT("Not", RTACPI_AST_NODE_F_DEFAULT, kAcpiAstArgType_AstNode, kAcpiAstArgType_AstNode), 1418 1454 1419 1455 }; … … 1852 1888 { 1853 1889 /* 2. - Optimize AST (constant folding, etc). */ 1854 /** @todo */1855 1890 1856 1891 /* 3. - Traverse AST and output table. */ … … 1858 1893 RTListForEach(&pThis->LstStmts, pIt, RTACPIASTNODE, NdAst) 1859 1894 { 1895 rc = rtAcpiAstNodeTransform(pIt, pErrInfo); 1896 if (RT_FAILURE(rc)) 1897 break; 1898 1860 1899 rc = rtAcpiAstDumpToTbl(pIt, pThis->hAcpiTbl); 1861 1900 if (RT_FAILURE(rc)) -
trunk/src/VBox/Runtime/common/acpi/acpi.cpp
r108066 r108087 45 45 #include <iprt/mem.h> 46 46 #include <iprt/string.h> 47 #include <iprt/utf16.h> 47 48 #include <iprt/uuid.h> 48 49 … … 885 886 886 887 888 RTDECL(int) RTAcpiTblStringAppendAsUtf16(RTACPITBL hAcpiTbl, const char *psz) 889 { 890 PRTACPITBLINT pThis = hAcpiTbl; 891 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 892 AssertRCReturn(pThis->rcErr, pThis->rcErr); 893 894 PRTUTF16 pwsz = NULL; 895 size_t cwc = 0; 896 int rc = RTStrToUtf16Ex(psz, RTSTR_MAX, &pwsz, 0, &cwc); 897 if (RT_SUCCESS(rc)) 898 { 899 RTAcpiTblBufferAppend(hAcpiTbl, pwsz, (cwc + 1) * sizeof(*pwsz)); 900 RTUtf16Free(pwsz); 901 } 902 else 903 pThis->rcErr = rc; 904 return pThis->rcErr; 905 } 906 907 887 908 RTDECL(int) RTAcpiTblIntegerAppend(RTACPITBL hAcpiTbl, uint64_t u64) 888 909 { … … 1015 1036 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 1016 1037 1017 /* Makes only sense inside an IfOp package. */ 1018 AssertReturn(pThis->paPkgStack[pThis->idxPkgStackElem].bOp == ACPI_AML_BYTE_CODE_OP_IF, VERR_INVALID_STATE); 1019 1020 rtAcpiTblPkgStartExt(pThis, ACPI_AML_BYTE_CODE_OP_ELSE); 1038 rtAcpiTblPkgStart(pThis, ACPI_AML_BYTE_CODE_OP_ELSE); 1021 1039 return pThis->rcErr; 1022 1040 } -
trunk/src/VBox/Runtime/include/internal/acpi.h
r108068 r108087 83 83 { 84 84 uintptr_t uPtrInternal; 85 P CRTACPIASTNODEpAstNd;85 PRTACPIASTNODE pAstNd; 86 86 const char *pszNameString; 87 87 bool f; … … 156 156 kAcpiAstNodeOp_Index, 157 157 kAcpiAstNodeOp_Store, 158 kAcpiAstNodeOp_Break, 159 kAcpiAstNodeOp_Continue, 160 kAcpiAstNodeOp_Add, 161 kAcpiAstNodeOp_Subtract, 162 kAcpiAstNodeOp_And, 163 kAcpiAstNodeOp_Nand, 164 kAcpiAstNodeOp_Or, 165 kAcpiAstNodeOp_Xor, 166 kAcpiAstNodeOp_Not, 158 167 kAcpiAstNodeOp_32Bit_Hack = 0x7fffffff 159 168 } RTACPIASTNODEOP; … … 182 191 /** A number */ 183 192 uint64_t u64; 184 /** Pointer to the field unit list - freed with RTMemFree() when the node is freed. */ 185 PRTACPIFIELDENTRY paFields; 193 struct 194 { 195 /** Pointer to the field unit list - freed with RTMemFree() when the node is freed. */ 196 PRTACPIFIELDENTRY paFields; 197 /** Number of field entries. */ 198 uint32_t cFields; 199 } Fields; 186 200 /** The resource template. */ 187 201 RTACPIRES hAcpiRes; … … 221 235 222 236 /** 237 * Does a few transformations on the given AST node and its children where required. 238 * 239 * @returns IPRT status. 240 * @param pAstNd The AST node to transform. 241 * @param pErrInfo Some additional error information on failure. 242 * 243 * @note This currently only implements merging if ... else ... nodes but can be extended to 244 * also do some optimizations and proper checking. 245 */ 246 DECLHIDDEN(int) rtAcpiAstNodeTransform(PRTACPIASTNODE pAstNd, PRTERRINFO pErrInfo); 247 248 249 /** 223 250 * Dumps the given AST node and everything it references to the given ACPI table. 224 251 *
Note:
See TracChangeset
for help on using the changeset viewer.