Source code of Windows XP (NT5)
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.

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