Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

973 lines
22 KiB

  1. /*** unasm.c - Unassemble AML back to ASL
  2. *
  3. * Copyright (c) 1996,1998 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created: 10/01/97
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #include "pch.h"
  10. //Local function prototype
  11. VOID LOCAL Indent(PUCHAR pbOp, int iLevel);
  12. UCHAR LOCAL FindOpClass(UCHAR bOp, POPMAP pOpTable);
  13. PASLTERM LOCAL FindOpTerm(ULONG dwOpcode);
  14. PASLTERM LOCAL FindKeywordTerm(char cKWGroup, UCHAR bData);
  15. LONG LOCAL UnAsmOpcode(PUCHAR *ppbOp);
  16. LONG LOCAL UnAsmDataObj(PUCHAR *ppbOp);
  17. LONG LOCAL UnAsmNameObj(PUCHAR *ppbOp, PNSOBJ pns, char c);
  18. LONG LOCAL UnAsmNameTail(PUCHAR *ppbOp, PSZ pszBuff, int iLen);
  19. LONG LOCAL UnAsmTermObj(PASLTERM pterm, PUCHAR *ppbOp);
  20. LONG LOCAL UnAsmArgs(PSZ pszUnAsmArgTypes, PSZ pszArgActions, PUCHAR *ppbOp,
  21. PNSOBJ pns);
  22. LONG LOCAL UnAsmSuperName(PUCHAR *ppbOp);
  23. LONG LOCAL UnAsmDataList(PUCHAR *ppbOp, PUCHAR pbEnd);
  24. LONG LOCAL UnAsmPkgList(PUCHAR *ppbOp, PUCHAR pbEnd);
  25. LONG LOCAL UnAsmFieldList(PUCHAR *ppbOp, PUCHAR pbEnd);
  26. LONG LOCAL UnAsmField(PUCHAR *ppbOp, PULONG pdwBitPos);
  27. /***LP UnAsmScope - Unassemble a scope
  28. *
  29. * ENTRY
  30. * ppbOp -> Current Opcode pointer
  31. * pbEnd -> end of scope
  32. * uipbOp - Op address
  33. * pnsScope - Scope object
  34. * iLevel - level of indentation
  35. * icLines - 1: unasm one line; 0: unasm all; -1: internal
  36. *
  37. * EXIT-SUCCESS
  38. * returns UNASMERR_NONE
  39. * EXIT-FAILURE
  40. * returns negative error code
  41. */
  42. LONG LOCAL UnAsmScope(PUCHAR *ppbOp, PUCHAR pbEnd, ULONG_PTR uipbOp,
  43. PNSOBJ pnsScope, int iLevel, int icLines)
  44. {
  45. LONG rc = UNASMERR_NONE;
  46. int icLinesLeft = icLines;
  47. if (uipbOp != 0)
  48. {
  49. guipbOpXlate = uipbOp - (ULONG_PTR)(*ppbOp);
  50. }
  51. if (pnsScope != NULL)
  52. {
  53. gpnsCurUnAsmScope = pnsScope;
  54. }
  55. if (iLevel != -1)
  56. {
  57. giLevel = iLevel;
  58. }
  59. if (icLines < 0)
  60. {
  61. Indent(*ppbOp, giLevel);
  62. PRINTF("{");
  63. giLevel++;
  64. }
  65. else if (icLines == 0)
  66. {
  67. icLinesLeft = -1;
  68. }
  69. while (*ppbOp < pbEnd)
  70. {
  71. Indent(*ppbOp, giLevel);
  72. if ((rc = UnAsmOpcode(ppbOp)) == UNASMERR_NONE)
  73. {
  74. if (icLinesLeft < 0)
  75. {
  76. continue;
  77. }
  78. if (--icLinesLeft == 0)
  79. {
  80. break;
  81. }
  82. }
  83. else
  84. {
  85. break;
  86. }
  87. }
  88. if ((rc == UNASMERR_NONE) && (icLines < 0))
  89. {
  90. giLevel--;
  91. Indent(*ppbOp, giLevel);
  92. PRINTF("}");
  93. }
  94. return rc;
  95. } //UnAsmScope
  96. /***LP Indent - Print indent level
  97. *
  98. * ENTRY
  99. * pbOp -> opcode
  100. * iLevel - indent level
  101. *
  102. * EXIT
  103. * None
  104. */
  105. VOID LOCAL Indent(PUCHAR pbOp, int iLevel)
  106. {
  107. int i;
  108. PRINTF("\n%08x: ", pbOp + guipbOpXlate);
  109. for (i = 0; i < iLevel; ++i)
  110. {
  111. PRINTF("| ");
  112. }
  113. } //Indent
  114. /***LP FindOpClass - Find opcode class of extended opcode
  115. *
  116. * ENTRY
  117. * bOp - opcode
  118. * pOpTable -> opcode table
  119. *
  120. * EXIT-SUCCESS
  121. * returns opcode class
  122. * EXIT-FAILURE
  123. * returns OPCLASS_INVALID
  124. */
  125. UCHAR LOCAL FindOpClass(UCHAR bOp, POPMAP pOpTable)
  126. {
  127. UCHAR bOpClass = OPCLASS_INVALID;
  128. while (pOpTable->bOpClass != 0)
  129. {
  130. if (bOp == pOpTable->bExOp)
  131. {
  132. bOpClass = pOpTable->bOpClass;
  133. break;
  134. }
  135. else
  136. {
  137. pOpTable++;
  138. }
  139. }
  140. return bOpClass;
  141. } //FindOpClass
  142. /***LP FindOpTerm - Find opcode in TermTable
  143. *
  144. * ENTRY
  145. * dwOpcode - opcode
  146. *
  147. * EXIT-SUCCESS
  148. * returns TermTable entry pointer
  149. * EXIT-FAILURE
  150. * returns NULL
  151. */
  152. PASLTERM LOCAL FindOpTerm(ULONG dwOpcode)
  153. {
  154. PASLTERM pterm = NULL;
  155. int i;
  156. for (i = 0; TermTable[i].pszID != NULL; ++i)
  157. {
  158. if ((TermTable[i].dwOpcode == dwOpcode) &&
  159. (TermTable[i].dwfTermClass &
  160. (UTC_CONST_NAME | UTC_SHORT_NAME | UTC_NAMESPACE_MODIFIER |
  161. UTC_DATA_OBJECT | UTC_NAMED_OBJECT | UTC_OPCODE_TYPE1 |
  162. UTC_OPCODE_TYPE2)))
  163. {
  164. break;
  165. }
  166. }
  167. if (TermTable[i].pszID != NULL)
  168. {
  169. pterm = &TermTable[i];
  170. }
  171. return pterm;
  172. } //FindOpTerm
  173. /***LP FindKeywordTerm - Find keyword in TermTable
  174. *
  175. * ENTRY
  176. * cKWGroup - keyword group
  177. * bData - data to match keyword
  178. *
  179. * EXIT-SUCCESS
  180. * returns TermTable entry pointer
  181. * EXIT-FAILURE
  182. * returns NULL
  183. */
  184. PASLTERM LOCAL FindKeywordTerm(char cKWGroup, UCHAR bData)
  185. {
  186. PASLTERM pterm = NULL;
  187. int i;
  188. for (i = 0; TermTable[i].pszID != NULL; ++i)
  189. {
  190. if ((TermTable[i].dwfTermClass == UTC_KEYWORD) &&
  191. (TermTable[i].pszArgActions[0] == cKWGroup) &&
  192. ((bData & (UCHAR)(TermTable[i].dwTermData >> 8)) ==
  193. (UCHAR)(TermTable[i].dwTermData & 0xff)))
  194. {
  195. break;
  196. }
  197. }
  198. if (TermTable[i].pszID != NULL)
  199. {
  200. pterm = &TermTable[i];
  201. }
  202. return pterm;
  203. } //FindKeywordTerm
  204. /***LP UnAsmOpcode - Unassemble an Opcode
  205. *
  206. * ENTRY
  207. * ppbOp -> Opcode pointer
  208. *
  209. * EXIT-SUCCESS
  210. * returns UNASMERR_NONE
  211. * EXIT-FAILURE
  212. * returns negative error code
  213. */
  214. LONG LOCAL UnAsmOpcode(PUCHAR *ppbOp)
  215. {
  216. LONG rc = UNASMERR_NONE;
  217. ULONG dwOpcode;
  218. UCHAR bOp;
  219. PASLTERM pterm;
  220. char szUnAsmArgTypes[MAX_ARGS + 1];
  221. int i;
  222. if (**ppbOp == OP_EXT_PREFIX)
  223. {
  224. (*ppbOp)++;
  225. dwOpcode = (((ULONG)**ppbOp) << 8) | OP_EXT_PREFIX;
  226. bOp = FindOpClass(**ppbOp, ExOpClassTable);
  227. }
  228. else
  229. {
  230. dwOpcode = (ULONG)(**ppbOp);
  231. bOp = OpClassTable[**ppbOp];
  232. }
  233. switch (bOp)
  234. {
  235. case OPCLASS_DATA_OBJ:
  236. rc = UnAsmDataObj(ppbOp);
  237. break;
  238. case OPCLASS_NAME_OBJ:
  239. {
  240. NSOBJ NSObj = {0};
  241. if (((rc = UnAsmNameObj(ppbOp, &NSObj, NSTYPE_UNKNOWN)) ==
  242. UNASMERR_NONE) &&
  243. (NSObj.ObjData.dwDataType == OBJTYPE_METHOD))
  244. {
  245. PMETHODOBJ pm = (PMETHODOBJ)GetObjBuff(&NSObj.ObjData);
  246. int iNumArgs;
  247. if (pm != NULL)
  248. {
  249. iNumArgs = pm->bMethodFlags & METHOD_NUMARG_MASK;
  250. for (i = 0; i < iNumArgs; ++i)
  251. {
  252. szUnAsmArgTypes[i] = 'C';
  253. }
  254. szUnAsmArgTypes[i] = '\0';
  255. rc = UnAsmArgs(szUnAsmArgTypes, NULL, ppbOp, NULL);
  256. LocalFree(pm);
  257. }
  258. }
  259. break;
  260. }
  261. case OPCLASS_ARG_OBJ:
  262. case OPCLASS_LOCAL_OBJ:
  263. case OPCLASS_CODE_OBJ:
  264. case OPCLASS_CONST_OBJ:
  265. if ((pterm = FindOpTerm(dwOpcode)) == NULL)
  266. {
  267. DBG_ERROR(("UnAsmOpcode: invalid opcode 0x%x", dwOpcode));
  268. rc = UNASMERR_FATAL;
  269. }
  270. else
  271. {
  272. (*ppbOp)++;
  273. rc = UnAsmTermObj(pterm, ppbOp);
  274. }
  275. break;
  276. default:
  277. DBG_ERROR(("UnAsmOpcode: invalid opcode class %d", bOp));
  278. rc = UNASMERR_FATAL;
  279. }
  280. return rc;
  281. } //UnAsmOpcode
  282. /***LP UnAsmDataObj - Unassemble data object
  283. *
  284. * ENTRY
  285. * ppbOp -> opcode pointer
  286. *
  287. * EXIT-SUCCESS
  288. * returns UNASMERR_NONE
  289. * EXIT-FAILURE
  290. * returns negative error code
  291. */
  292. LONG LOCAL UnAsmDataObj(PUCHAR *ppbOp)
  293. {
  294. LONG rc = UNASMERR_NONE;
  295. UCHAR bOp = **ppbOp;
  296. PSZ psz;
  297. (*ppbOp)++;
  298. switch (bOp)
  299. {
  300. case OP_BYTE:
  301. PRINTF("0x%x", **ppbOp);
  302. *ppbOp += sizeof(UCHAR);
  303. break;
  304. case OP_WORD:
  305. PRINTF("0x%x", *((PUSHORT)*ppbOp));
  306. *ppbOp += sizeof(USHORT);
  307. break;
  308. case OP_DWORD:
  309. PRINTF("0x%x", *((PULONG)*ppbOp));
  310. *ppbOp += sizeof(ULONG);
  311. break;
  312. case OP_STRING:
  313. PRINTF("\"");
  314. for (psz = (PSZ)*ppbOp; *psz != '\0'; psz++)
  315. {
  316. if (*psz == '\\')
  317. {
  318. PRINTF("\\");
  319. }
  320. PRINTF("%c", *psz);
  321. }
  322. PRINTF("\"");
  323. *ppbOp += STRLEN((PSZ)*ppbOp) + 1;
  324. break;
  325. default:
  326. DBG_ERROR(("UnAsmDataObj: unexpected opcode 0x%x", bOp));
  327. rc = UNASMERR_INVALID_OPCODE;
  328. }
  329. return rc;
  330. } //UnAsmDataObj
  331. /***LP UnAsmNameObj - Unassemble name object
  332. *
  333. * ENTRY
  334. * ppbOp -> opcode pointer
  335. * pns -> to hold object found or created
  336. * c - object type
  337. *
  338. * EXIT-SUCCESS
  339. * returns UNASMERR_NONE
  340. * EXIT-FAILURE
  341. * returns negative error code
  342. */
  343. LONG LOCAL UnAsmNameObj(PUCHAR *ppbOp, PNSOBJ pns, char c)
  344. {
  345. LONG rc = UNASMERR_NONE;
  346. char szName[MAX_NAME_LEN + 1];
  347. int iLen = 0;
  348. szName[0] = '\0';
  349. if (**ppbOp == OP_ROOT_PREFIX)
  350. {
  351. szName[iLen] = '\\';
  352. iLen++;
  353. (*ppbOp)++;
  354. rc = UnAsmNameTail(ppbOp, szName, iLen);
  355. }
  356. else if (**ppbOp == OP_PARENT_PREFIX)
  357. {
  358. szName[iLen] = '^';
  359. iLen++;
  360. (*ppbOp)++;
  361. while ((**ppbOp == OP_PARENT_PREFIX) && (iLen < MAX_NAME_LEN))
  362. {
  363. szName[iLen] = '^';
  364. iLen++;
  365. (*ppbOp)++;
  366. }
  367. if (**ppbOp == OP_PARENT_PREFIX)
  368. {
  369. DBG_ERROR(("UnAsmNameObj: name too long - \"%s\"", szName));
  370. rc = UNASMERR_FATAL;
  371. }
  372. else
  373. {
  374. rc = UnAsmNameTail(ppbOp, szName, iLen);
  375. }
  376. }
  377. else
  378. {
  379. rc = UnAsmNameTail(ppbOp, szName, iLen);
  380. }
  381. if (rc == UNASMERR_NONE)
  382. {
  383. ULONG_PTR uipns = 0;
  384. NSOBJ NSObj;
  385. PRINTF("%s", szName);
  386. rc = GetNSObj(szName, gpnsCurUnAsmScope, &uipns, &NSObj, 0);
  387. if (rc == UNASMERR_NONE)
  388. {
  389. if (pns != NULL)
  390. {
  391. MEMCPY(pns, &NSObj, sizeof(NSObj));
  392. }
  393. if ((c == NSTYPE_SCOPE) && (uipns != 0))
  394. {
  395. gpnsCurUnAsmScope = pns;
  396. }
  397. }
  398. else
  399. {
  400. rc = UNASMERR_NONE;
  401. }
  402. }
  403. return rc;
  404. } //UnAsmNameObj
  405. /***LP UnAsmNameTail - Parse AML name tail
  406. *
  407. * ENTRY
  408. * ppbOp -> opcode pointer
  409. * pszBuff -> to hold parsed name
  410. * iLen - index to tail of pszBuff
  411. *
  412. * EXIT-SUCCESS
  413. * returns UNASMERR_NONE
  414. * EXIT-FAILURE
  415. * returns negative error code
  416. */
  417. LONG LOCAL UnAsmNameTail(PUCHAR *ppbOp, PSZ pszBuff, int iLen)
  418. {
  419. LONG rc = UNASMERR_NONE;
  420. int icNameSegs = 0;
  421. //
  422. // We do not check for invalid NameSeg characters here and assume that
  423. // the compiler does its job not generating it.
  424. //
  425. if (**ppbOp == '\0')
  426. {
  427. //
  428. // There is no NameTail (i.e. either NULL name or name with just
  429. // prefixes.
  430. //
  431. (*ppbOp)++;
  432. }
  433. else if (**ppbOp == OP_MULTI_NAME_PREFIX)
  434. {
  435. (*ppbOp)++;
  436. icNameSegs = (int)**ppbOp;
  437. (*ppbOp)++;
  438. }
  439. else if (**ppbOp == OP_DUAL_NAME_PREFIX)
  440. {
  441. (*ppbOp)++;
  442. icNameSegs = 2;
  443. }
  444. else
  445. icNameSegs = 1;
  446. while ((icNameSegs > 0) && (iLen + sizeof(NAMESEG) < MAX_NAME_LEN))
  447. {
  448. STRCPYN(&pszBuff[iLen], (PSZ)(*ppbOp), sizeof(NAMESEG));
  449. iLen += sizeof(NAMESEG);
  450. *ppbOp += sizeof(NAMESEG);
  451. icNameSegs--;
  452. if ((icNameSegs > 0) && (iLen + 1 < MAX_NAME_LEN))
  453. {
  454. pszBuff[iLen] = '.';
  455. iLen++;
  456. }
  457. }
  458. if (icNameSegs > 0)
  459. {
  460. DBG_ERROR(("UnAsmNameTail: name too long - %s", pszBuff));
  461. rc = UNASMERR_FATAL;
  462. }
  463. else
  464. {
  465. pszBuff[iLen] = '\0';
  466. }
  467. return rc;
  468. } //UnAsmNameTail
  469. /***LP UnAsmTermObj - Unassemble term object
  470. *
  471. * ENTRY
  472. * pterm -> term table entry
  473. * ppbOp -> opcode pointer
  474. *
  475. * EXIT-SUCCESS
  476. * returns UNASMERR_NONE
  477. * EXIT-FAILURE
  478. * returns negative error code
  479. */
  480. LONG LOCAL UnAsmTermObj(PASLTERM pterm, PUCHAR *ppbOp)
  481. {
  482. LONG rc = UNASMERR_NONE;
  483. PUCHAR pbEnd = NULL;
  484. PNSOBJ pnsScopeSave = gpnsCurUnAsmScope;
  485. NSOBJ NSObj = {0};
  486. PRINTF("%s", pterm->pszID);
  487. if (pterm->dwfTerm & TF_PACKAGE_LEN)
  488. {
  489. ParsePackageLen(ppbOp, &pbEnd);
  490. }
  491. if (pterm->pszUnAsmArgTypes != NULL)
  492. {
  493. rc = UnAsmArgs(pterm->pszUnAsmArgTypes, pterm->pszArgActions, ppbOp,
  494. &NSObj);
  495. }
  496. if (rc == UNASMERR_NONE)
  497. {
  498. if (pterm->dwfTerm & TF_DATA_LIST)
  499. {
  500. rc = UnAsmDataList(ppbOp, pbEnd);
  501. }
  502. else if (pterm->dwfTerm & TF_PACKAGE_LIST)
  503. {
  504. rc = UnAsmPkgList(ppbOp, pbEnd);
  505. }
  506. else if (pterm->dwfTerm & TF_FIELD_LIST)
  507. {
  508. rc = UnAsmFieldList(ppbOp, pbEnd);
  509. }
  510. else if (pterm->dwfTerm & TF_PACKAGE_LEN)
  511. {
  512. if ((pterm->dwfTerm & TF_CHANGE_CHILDSCOPE) &&
  513. (NSObj.ObjData.dwDataType != 0))
  514. {
  515. gpnsCurUnAsmScope = &NSObj;
  516. }
  517. rc = UnAsmScope(ppbOp, pbEnd, 0, NULL, -1, -1);
  518. }
  519. }
  520. gpnsCurUnAsmScope = pnsScopeSave;
  521. return rc;
  522. } //UnAsmTermObj
  523. /***LP UnAsmArgs - Unassemble arguments
  524. *
  525. * ENTRY
  526. * pszUnArgTypes -> UnAsm ArgTypes string
  527. * pszArgActions -> Arg Action types
  528. * ppbOp -> opcode pointer
  529. * pns -> to hold created object
  530. *
  531. * EXIT-SUCCESS
  532. * returns UNASMERR_NONE
  533. * EXIT-FAILURE
  534. * returns negative error code
  535. */
  536. LONG LOCAL UnAsmArgs(PSZ pszUnAsmArgTypes, PSZ pszArgActions, PUCHAR *ppbOp,
  537. PNSOBJ pns)
  538. {
  539. LONG rc = UNASMERR_NONE;
  540. static UCHAR bArgData = 0;
  541. int iNumArgs, i;
  542. PASLTERM pterm;
  543. iNumArgs = STRLEN(pszUnAsmArgTypes);
  544. PRINTF("(");
  545. for (i = 0; i < iNumArgs; ++i)
  546. {
  547. if (i != 0)
  548. {
  549. PRINTF(", ");
  550. }
  551. switch (pszUnAsmArgTypes[i])
  552. {
  553. case 'N':
  554. ASSERT(pszArgActions != NULL);
  555. rc = UnAsmNameObj(ppbOp, pns, pszArgActions[i]);
  556. break;
  557. case 'O':
  558. if ((**ppbOp == OP_BUFFER) || (**ppbOp == OP_PACKAGE) ||
  559. (OpClassTable[**ppbOp] == OPCLASS_CONST_OBJ))
  560. {
  561. pterm = FindOpTerm((ULONG)(**ppbOp));
  562. ASSERT(pterm != NULL);
  563. (*ppbOp)++;
  564. rc = UnAsmTermObj(pterm, ppbOp);
  565. }
  566. else
  567. {
  568. rc = UnAsmDataObj(ppbOp);
  569. }
  570. break;
  571. case 'C':
  572. rc = UnAsmOpcode(ppbOp);
  573. break;
  574. case 'B':
  575. PRINTF("0x%x", **ppbOp);
  576. *ppbOp += sizeof(UCHAR);
  577. break;
  578. case 'K':
  579. case 'k':
  580. if (pszUnAsmArgTypes[i] == 'K')
  581. {
  582. bArgData = **ppbOp;
  583. }
  584. if ((pszArgActions != NULL) && (pszArgActions[i] == '!'))
  585. {
  586. PRINTF("0x%x", **ppbOp & 0x07);
  587. }
  588. else
  589. {
  590. pterm = FindKeywordTerm(pszArgActions[i], bArgData);
  591. ASSERT(pterm != NULL);
  592. PRINTF("%s", pterm->pszID);
  593. }
  594. if (pszUnAsmArgTypes[i] == 'K')
  595. {
  596. *ppbOp += sizeof(UCHAR);
  597. }
  598. break;
  599. case 'W':
  600. PRINTF("0x%x", *((PUSHORT)*ppbOp));
  601. *ppbOp += sizeof(USHORT);
  602. break;
  603. case 'D':
  604. PRINTF("0x%x", *((PULONG)*ppbOp));
  605. *ppbOp += sizeof(ULONG);
  606. break;
  607. case 'S':
  608. ASSERT(pszArgActions != NULL);
  609. rc = UnAsmSuperName(ppbOp);
  610. break;
  611. default:
  612. DBG_ERROR(("UnAsmOpcode: invalid ArgType '%c'",
  613. pszUnAsmArgTypes[i]));
  614. rc = UNASMERR_FATAL;
  615. }
  616. }
  617. PRINTF(")");
  618. return rc;
  619. } //UnAsmArgs
  620. /***LP UnAsmSuperName - Unassemble supername
  621. *
  622. * ENTRY
  623. * ppbOp -> opcode pointer
  624. *
  625. * EXIT-SUCCESS
  626. * returns UNASMERR_NONE
  627. * EXIT-FAILURE
  628. * returns negative error code
  629. */
  630. LONG LOCAL UnAsmSuperName(PUCHAR *ppbOp)
  631. {
  632. LONG rc = UNASMERR_NONE;
  633. if (**ppbOp == 0)
  634. {
  635. (*ppbOp)++;
  636. }
  637. else if ((**ppbOp == OP_EXT_PREFIX) && (*(*ppbOp + 1) == EXOP_DEBUG))
  638. {
  639. PRINTF("Debug");
  640. *ppbOp += 2;
  641. }
  642. else if (OpClassTable[**ppbOp] == OPCLASS_NAME_OBJ)
  643. {
  644. rc = UnAsmNameObj(ppbOp, NULL, NSTYPE_UNKNOWN);
  645. }
  646. else if ((**ppbOp == OP_INDEX) ||
  647. (OpClassTable[**ppbOp] == OPCLASS_ARG_OBJ) ||
  648. (OpClassTable[**ppbOp] == OPCLASS_LOCAL_OBJ))
  649. {
  650. rc = UnAsmOpcode(ppbOp);
  651. }
  652. else
  653. {
  654. DBG_ERROR(("UnAsmSuperName: invalid SuperName - 0x%02x", **ppbOp));
  655. rc = UNASMERR_FATAL;
  656. }
  657. return rc;
  658. } //UnAsmSuperName
  659. /***LP UnAsmDataList - Unassemble data list
  660. *
  661. * ENTRY
  662. * ppbOp -> opcode pointer
  663. * pbEnd -> end of list
  664. *
  665. * EXIT-SUCCESS
  666. * returns UNASMERR_NONE
  667. * EXIT-FAILURE
  668. * returns negative error code
  669. */
  670. LONG LOCAL UnAsmDataList(PUCHAR *ppbOp, PUCHAR pbEnd)
  671. {
  672. LONG rc = UNASMERR_NONE;
  673. int i;
  674. Indent(*ppbOp, giLevel);
  675. PRINTF("{");
  676. while (*ppbOp < pbEnd)
  677. {
  678. Indent(*ppbOp, 0);
  679. PRINTF("0x%02x", **ppbOp);
  680. (*ppbOp)++;
  681. for (i = 1; (*ppbOp < pbEnd) && (i < 8); ++i)
  682. {
  683. PRINTF(", 0x%02x", **ppbOp);
  684. (*ppbOp)++;
  685. }
  686. if (*ppbOp < pbEnd)
  687. {
  688. PRINTF(",");
  689. }
  690. }
  691. Indent(*ppbOp, giLevel);
  692. PRINTF("}");
  693. return rc;
  694. } //UnAsmDataList
  695. /***LP UnAsmPkgList - Unassemble package list
  696. *
  697. * ENTRY
  698. * ppbOp -> opcode pointer
  699. * pbEnd -> end of list
  700. *
  701. * EXIT-SUCCESS
  702. * returns UNASMERR_NONE
  703. * EXIT-FAILURE
  704. * returns negative error code
  705. */
  706. LONG LOCAL UnAsmPkgList(PUCHAR *ppbOp, PUCHAR pbEnd)
  707. {
  708. LONG rc = UNASMERR_NONE;
  709. PASLTERM pterm;
  710. Indent(*ppbOp, giLevel);
  711. PRINTF("{");
  712. giLevel++;
  713. while (*ppbOp < pbEnd)
  714. {
  715. Indent(*ppbOp, giLevel);
  716. if ((**ppbOp == OP_BUFFER) || (**ppbOp == OP_PACKAGE) ||
  717. (OpClassTable[**ppbOp] == OPCLASS_CONST_OBJ))
  718. {
  719. pterm = FindOpTerm((ULONG)(**ppbOp));
  720. ASSERT(pterm != NULL);
  721. (*ppbOp)++;
  722. rc = UnAsmTermObj(pterm, ppbOp);
  723. }
  724. else if (OpClassTable[**ppbOp] == OPCLASS_NAME_OBJ)
  725. {
  726. rc = UnAsmNameObj(ppbOp, NULL, NSTYPE_UNKNOWN);
  727. }
  728. else
  729. {
  730. rc = UnAsmDataObj(ppbOp);
  731. }
  732. if (rc != UNASMERR_NONE)
  733. {
  734. break;
  735. }
  736. else if (*ppbOp < pbEnd)
  737. {
  738. PRINTF(",");
  739. }
  740. }
  741. if (rc == UNASMERR_NONE)
  742. {
  743. giLevel--;
  744. Indent(*ppbOp, giLevel);
  745. PRINTF("}");
  746. }
  747. return rc;
  748. } //UnAsmPkgList
  749. /***LP UnAsmFieldList - Unassemble field list
  750. *
  751. * ENTRY
  752. * ppbOp -> opcode pointer
  753. * pbEnd -> end of list
  754. *
  755. * EXIT-SUCCESS
  756. * returns UNASMERR_NONE
  757. * EXIT-FAILURE
  758. * returns negative error code
  759. */
  760. LONG LOCAL UnAsmFieldList(PUCHAR *ppbOp, PUCHAR pbEnd)
  761. {
  762. LONG rc = UNASMERR_NONE;
  763. ULONG dwBitPos = 0;
  764. Indent(*ppbOp, giLevel);
  765. PRINTF("{");
  766. giLevel++;
  767. while (*ppbOp < pbEnd)
  768. {
  769. Indent(*ppbOp, giLevel);
  770. if ((rc = UnAsmField(ppbOp, &dwBitPos)) == UNASMERR_NONE)
  771. {
  772. if (*ppbOp < pbEnd)
  773. {
  774. PRINTF(",");
  775. }
  776. }
  777. else
  778. {
  779. break;
  780. }
  781. }
  782. if (rc == UNASMERR_NONE)
  783. {
  784. giLevel--;
  785. Indent(*ppbOp, giLevel);
  786. PRINTF("}");
  787. }
  788. return rc;
  789. } //UnAsmFieldList
  790. /***LP UnAsmField - Unassemble field
  791. *
  792. * ENTRY
  793. * ppbOp -> opcode pointer
  794. * pdwBitPos -> to hold cumulative bit position
  795. *
  796. * EXIT-SUCCESS
  797. * returns UNASMERR_NONE
  798. * EXIT-FAILURE
  799. * returns negative error code
  800. */
  801. LONG LOCAL UnAsmField(PUCHAR *ppbOp, PULONG pdwBitPos)
  802. {
  803. LONG rc = UNASMERR_NONE;
  804. if (**ppbOp == 0x01)
  805. {
  806. PASLTERM pterm = NULL;
  807. (*ppbOp)++;
  808. pterm = FindKeywordTerm('A', **ppbOp);
  809. if (pterm != NULL) {
  810. PRINTF("AccessAs(%s, 0x%x)", pterm->pszID, *(*ppbOp + 1));
  811. }
  812. *ppbOp += 2;
  813. }
  814. else
  815. {
  816. char szNameSeg[sizeof(NAMESEG) + 1];
  817. ULONG dwcbBits;
  818. if (**ppbOp == 0)
  819. {
  820. szNameSeg[0] = '\0';
  821. (*ppbOp)++;
  822. }
  823. else
  824. {
  825. STRCPYN(szNameSeg, (PSZ)*ppbOp, sizeof(NAMESEG));
  826. szNameSeg[4] = '\0';
  827. *ppbOp += sizeof(NAMESEG);
  828. }
  829. dwcbBits = ParsePackageLen(ppbOp, NULL);
  830. if (szNameSeg[0] == '\0')
  831. {
  832. if ((dwcbBits > 32) && (((*pdwBitPos + dwcbBits) % 8) == 0))
  833. {
  834. PRINTF("Offset(0x%x)", (*pdwBitPos + dwcbBits)/8);
  835. }
  836. else
  837. {
  838. PRINTF(", %d", dwcbBits);
  839. }
  840. }
  841. else
  842. {
  843. PRINTF("%s, %d", szNameSeg, dwcbBits);
  844. }
  845. *pdwBitPos += dwcbBits;
  846. }
  847. return rc;
  848. } //UnAsmField