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.

1503 lines
36 KiB

  1. /*** unasm.c - Unassemble AML file and convert to Intel .ASM file
  2. *
  3. * Copyright (c) 1996,1997 Microsoft Corporation
  4. * Author: Michael Tsang (MikeTs)
  5. * Created: 10/01/97
  6. *
  7. * MODIFICATION HISTORY
  8. */
  9. #include "aslp.h"
  10. /***LP UnAsmFile - Unassemble AML file
  11. *
  12. * ENTRY
  13. * pszAMLName -> AML file name
  14. * pfileOut -> ASM output file
  15. *
  16. * EXIT-SUCCESS
  17. * returns ASLERR_NONE
  18. * EXIT-FAILURE
  19. * returns negative error code
  20. */
  21. int LOCAL UnAsmFile(PSZ pszAMLName, FILE *pfileOut)
  22. {
  23. int rc = ASLERR_NONE;
  24. PBYTE pb = NULL;
  25. DWORD dwAddr = 0;
  26. int fhAML = 0;
  27. ULONG dwLen = 0;
  28. ENTER((1, "UnAsmFile(AMLName=%s,pfileOut=%p)\n",
  29. pszAMLName, pfileOut));
  30. ASSERT(pfileOut != NULL);
  31. if (gpszAMLFile != NULL)
  32. {
  33. if ((fhAML = _open(gpszAMLFile, _O_BINARY | _O_RDONLY)) == -1)
  34. {
  35. ERROR(("UnAsmFile: failed to open AML file - %s", gpszAMLFile));
  36. rc = ASLERR_OPEN_FILE;
  37. }
  38. else if ((pb = MEMALLOC(sizeof(DESCRIPTION_HEADER))) == NULL)
  39. {
  40. ERROR(("UnAsmFile: failed to allocate description header block"));
  41. rc = ASLERR_OUT_OF_MEM;
  42. }
  43. else if (_read(fhAML, pb, sizeof(DESCRIPTION_HEADER)) !=
  44. sizeof(DESCRIPTION_HEADER))
  45. {
  46. ERROR(("UnAsmFile: failed to read description header block"));
  47. rc = ASLERR_READ_FILE;
  48. }
  49. else if (_lseek(fhAML, 0, SEEK_SET) == -1)
  50. {
  51. ERROR(("UnAsmFile: failed seeking to beginning of AML file"));
  52. rc = ASLERR_SEEK_FILE;
  53. }
  54. else
  55. {
  56. dwLen = ((PDESCRIPTION_HEADER)pb)->Length;
  57. MEMFREE(pb);
  58. if ((pb = MEMALLOC(dwLen)) == NULL)
  59. {
  60. ERROR(("UnAsmFile: failed to allocate AML file buffer"));
  61. rc = ASLERR_OUT_OF_MEM;
  62. }
  63. else if (_read(fhAML, pb, dwLen) != (int)dwLen)
  64. {
  65. ERROR(("UnAsmFile: failed to read AML file"));
  66. rc = ASLERR_OUT_OF_MEM;
  67. }
  68. }
  69. }
  70. #ifdef __UNASM
  71. else
  72. {
  73. DWORD dwTableSig = (gdwfASL & ASLF_DUMP_NONASL)? *((PDWORD)pszAMLName):
  74. *((PDWORD)gpszTabSig);
  75. ASSERT(gpszTabSig != NULL);
  76. if ((pb = GetTableBySig(dwTableSig, &dwAddr)) != NULL)
  77. {
  78. dwLen = ((PDESCRIPTION_HEADER)pb)->Length;
  79. }
  80. else
  81. {
  82. rc = ASLERR_GET_TABLE;
  83. }
  84. }
  85. #endif
  86. if (rc == ASLERR_NONE)
  87. {
  88. rc = UnAsmAML(pszAMLName, dwAddr, pb, pfileOut);
  89. }
  90. if (pb != NULL)
  91. {
  92. MEMFREE(pb);
  93. }
  94. if (fhAML != 0)
  95. {
  96. _close(fhAML);
  97. }
  98. EXIT((1, "UnAsmFile=%d\n", rc));
  99. return rc;
  100. } //UnAsmFile
  101. /***LP BuildNameSpace - Do a NameSpace building pass
  102. *
  103. * ENTRY
  104. * pszAMLName -> AML file name
  105. * dwAddr - physical address of table
  106. * pb -> AML buffer
  107. *
  108. * EXIT-SUCCESS
  109. * returns ASLERR_NONE
  110. * EXIT-FAILURE
  111. * returns negative error code
  112. */
  113. int LOCAL BuildNameSpace(PSZ pszAMLName, DWORD dwAddr, PBYTE pb)
  114. {
  115. #define MAX_NUM_NAMES 4
  116. int rc = ASLERR_NONE;
  117. static PSZ pszNames[MAX_NUM_NAMES] = {NULL};
  118. static DWORD adwAddr[MAX_NUM_NAMES] = {0};
  119. int i;
  120. ENTER((2, "BuildNameSpace(AMLName=%s,Addr=%x,pb=%p)\n",
  121. pszAMLName, dwAddr, pb));
  122. for (i = 0; i < MAX_NUM_NAMES; ++i)
  123. {
  124. if (pszNames[i] == NULL)
  125. {
  126. DWORD dwLen = ((PDESCRIPTION_HEADER)pb)->Length;
  127. //
  128. // Do a pass to build NameSpace.
  129. //
  130. pszNames[i] = pszAMLName;
  131. adwAddr[i] = dwAddr;
  132. pb += sizeof(DESCRIPTION_HEADER);
  133. rc = UnAsmScope(&pb, pb + dwLen - sizeof(DESCRIPTION_HEADER), NULL);
  134. break;
  135. }
  136. else if ((strcmp(pszAMLName, pszNames[i]) == 0) &&
  137. (dwAddr == adwAddr[i]))
  138. {
  139. break;
  140. }
  141. }
  142. if (i >= MAX_NUM_NAMES)
  143. {
  144. ERROR(("BuildNameSpace: Too many AML tables"));
  145. rc = ASLERR_INTERNAL_ERROR;
  146. }
  147. EXIT((2, "BuildNameSpace=%d\n", rc));
  148. return rc;
  149. } //BuildNameSpace
  150. /***LP UnAsmAML - Unassemble AML buffer
  151. *
  152. * ENTRY
  153. * pszAMLName -> AML file name
  154. * dwAddr - physical address of table
  155. * pb -> AML buffer
  156. * pfileOut -> ASM output file
  157. *
  158. * EXIT-SUCCESS
  159. * returns ASLERR_NONE
  160. * EXIT-FAILURE
  161. * returns negative error code
  162. */
  163. int LOCAL UnAsmAML(PSZ pszAMLName, DWORD dwAddr, PBYTE pb, FILE *pfileOut)
  164. {
  165. int rc = ASLERR_NONE;
  166. PDESCRIPTION_HEADER pdh = (PDESCRIPTION_HEADER)pb;
  167. ENTER((2, "UnAsmAML(AMLName=%s,Addr=%x,pb=%p,pfileOut=%p)\n",
  168. pszAMLName, dwAddr, pb, pfileOut));
  169. ASSERT(gpnsNameSpaceRoot != NULL);
  170. gpnsCurrentOwner = NULL;
  171. gpnsCurrentScope = gpnsNameSpaceRoot;
  172. if (ComputeDataChkSum(pb, pdh->Length) != 0)
  173. {
  174. ERROR(("UnAsmAML: failed to verify AML checksum"));
  175. rc = ASLERR_CHECKSUM;
  176. }
  177. else if ((rc = BuildNameSpace(pszAMLName, dwAddr, pb)) == ASLERR_NONE)
  178. {
  179. gpbOpTop = gpbOpBegin = pb;
  180. if ((rc = UnAsmHeader(pszAMLName, pdh, pfileOut)) == ASLERR_NONE)
  181. {
  182. pb += sizeof(DESCRIPTION_HEADER);
  183. rc = UnAsmScope(&pb, pb + pdh->Length - sizeof(DESCRIPTION_HEADER),
  184. pfileOut);
  185. if ((rc == ASLERR_NONE) && (pfileOut != NULL))
  186. {
  187. fprintf(pfileOut, "\n");
  188. }
  189. }
  190. }
  191. EXIT((2, "UnAsmAML=%d\n", rc));
  192. return rc;
  193. } //UnAsmAML
  194. /***LP UnAsmHeader - Unassemble table header
  195. *
  196. * ENTRY
  197. * pszAMLName -> AML file name
  198. * pdh -> DESCRIPTION_HEADER
  199. * pfileOut -> ASM output file
  200. *
  201. * EXIT-SUCCESS
  202. * returns ASLERR_NONE
  203. * EXIT-FAILURE
  204. * returns negative error code
  205. */
  206. int LOCAL UnAsmHeader(PSZ pszAMLName, PDESCRIPTION_HEADER pdh, FILE *pfileOut)
  207. {
  208. int rc = ASLERR_NONE;
  209. char szSig[sizeof(pdh->Signature) + 1] = {0};
  210. char szOEMID[sizeof(pdh->OEMID) + 1] = {0};
  211. char szOEMTableID[sizeof(pdh->OEMTableID) + 1] = {0};
  212. char szCreatorID[sizeof(pdh->CreatorID) + 1] = {0};
  213. ENTER((2, "UnAsmHeader(AMLName=%s,pdh=%p,pfileOut=%p)\n",
  214. pszAMLName, pdh, pfileOut));
  215. if (pfileOut != NULL)
  216. {
  217. strncpy(szSig, (PSZ)&pdh->Signature, sizeof(pdh->Signature));
  218. strncpy(szOEMID, (PSZ)pdh->OEMID, sizeof(pdh->OEMID));
  219. strncpy(szOEMTableID, (PSZ)pdh->OEMTableID, sizeof(pdh->OEMTableID));
  220. strncpy(szCreatorID, (PSZ)pdh->CreatorID, sizeof(pdh->CreatorID));
  221. if ((gdwfASL & ASLF_GENASM) || !(gdwfASL & ASLF_GENSRC))
  222. {
  223. fprintf(pfileOut, "; ");
  224. }
  225. fprintf(pfileOut, "// CreatorID=%s\tCreatorRev=%x.%x.%d\n",
  226. szCreatorID, pdh->CreatorRev >> 24,
  227. (pdh->CreatorRev >> 16) & 0xff, pdh->CreatorRev & 0xffff);
  228. if ((gdwfASL & ASLF_GENASM) || !(gdwfASL & ASLF_GENSRC))
  229. {
  230. fprintf(pfileOut, "; ");
  231. }
  232. fprintf(pfileOut, "// FileLength=%d\tFileChkSum=0x%x\n\n",
  233. pdh->Length, pdh->Checksum);
  234. if ((gdwfASL & ASLF_GENASM) || !(gdwfASL & ASLF_GENSRC))
  235. {
  236. fprintf(pfileOut, "; ");
  237. }
  238. fprintf(pfileOut, "DefinitionBlock(\"%s\", \"%s\", 0x%02x, \"%s\", \"%s\", 0x%08x)",
  239. pszAMLName, szSig, pdh->Revision, szOEMID, szOEMTableID,
  240. pdh->OEMRevision);
  241. }
  242. EXIT((2, "UnAsmHeader=%d\n", rc));
  243. return rc;
  244. } //UnAsmHeader
  245. /***LP DumpBytes - Dump byte stream in ASM file
  246. *
  247. * ENTRY
  248. * pb -> buffer
  249. * dwLen - length to dump
  250. * pfileOut -> ASM output file
  251. *
  252. * EXIT
  253. * None
  254. */
  255. VOID LOCAL DumpBytes(PBYTE pb, DWORD dwLen, FILE *pfileOut)
  256. {
  257. int i;
  258. #define MAX_LINE_BYTES 8
  259. ENTER((2, "DumpBytes(pb=%p,Len=%x,pfileOut=%p)\n", pb, dwLen, pfileOut));
  260. while (dwLen > 0)
  261. {
  262. fprintf(pfileOut, "\tdb\t0%02xh", *pb);
  263. for (i = 1; i < MAX_LINE_BYTES; ++i)
  264. {
  265. if ((int)dwLen - i > 0)
  266. {
  267. fprintf(pfileOut, ", 0%02xh", pb[i]);
  268. }
  269. else
  270. {
  271. fprintf(pfileOut, " ");
  272. }
  273. }
  274. fprintf(pfileOut, "\t; ");
  275. for (i = 0; (dwLen > 0) && (i < MAX_LINE_BYTES); ++i)
  276. {
  277. fprintf(pfileOut, "%c",
  278. ((*pb >= ' ') && (*pb <= '~'))? *pb: '.');
  279. dwLen--;
  280. pb++;
  281. }
  282. fprintf(pfileOut, "\n");
  283. }
  284. fprintf(pfileOut, "\n");
  285. EXIT((2, "DumpBytes!\n"));
  286. } //DumpBytes
  287. /***LP DumpCode - Dump code stream in ASM file
  288. *
  289. * ENTRY
  290. * pbOp -> Opcode pointer
  291. * pfileOut -> ASM output file
  292. *
  293. * EXIT
  294. * None
  295. */
  296. VOID LOCAL DumpCode(PBYTE pbOp, FILE *pfileOut)
  297. {
  298. ENTER((2, "DumpCode(pbOp=%p,pfileOut=%p)\n", pbOp, pfileOut));
  299. if (pfileOut != NULL)
  300. {
  301. if (gdwfASL & ASLF_GENASM)
  302. {
  303. if (gpbOpBegin != pbOp)
  304. {
  305. fprintf(pfileOut, "\n");
  306. fprintf(pfileOut, "; %08x:\n", gpbOpBegin - gpbOpTop);
  307. DumpBytes(gpbOpBegin, (DWORD)(pbOp - gpbOpBegin), pfileOut);
  308. gpbOpBegin = pbOp;
  309. }
  310. }
  311. else
  312. {
  313. fprintf(pfileOut, "\n");
  314. }
  315. }
  316. EXIT((2, "DumpCode!\n"));
  317. } //DumpCode
  318. /***LP PrintIndent - Print indent level
  319. *
  320. * ENTRY
  321. * iLevel - indent level
  322. * pfileOut -> ASM output file
  323. *
  324. * EXIT
  325. * None
  326. */
  327. VOID LOCAL PrintIndent(int iLevel, FILE *pfileOut)
  328. {
  329. int i;
  330. ENTER((3, "PrintIndent(Level=%d,pfileOut=%p)\n", iLevel, pfileOut));
  331. if (pfileOut != NULL)
  332. {
  333. if ((gdwfASL & ASLF_GENASM) || !(gdwfASL & ASLF_GENSRC))
  334. {
  335. fprintf(pfileOut, "; ");
  336. }
  337. for (i = 0; i < iLevel; ++i)
  338. {
  339. fprintf(pfileOut,
  340. ((gdwfASL & ASLF_GENASM) || !(gdwfASL & ASLF_GENSRC))?
  341. "| ": " ");
  342. }
  343. }
  344. EXIT((3, "PrintIndent!\n"));
  345. } //PrintIndent
  346. /***LP FindOpClass - Find opcode class of extended opcode
  347. *
  348. * ENTRY
  349. * bOp - opcode
  350. * pOpTable -> opcode table
  351. *
  352. * EXIT-SUCCESS
  353. * returns opcode class
  354. * EXIT-FAILURE
  355. * returns OPCLASS_INVALID
  356. */
  357. BYTE LOCAL FindOpClass(BYTE bOp, POPMAP pOpTable)
  358. {
  359. BYTE bOpClass = OPCLASS_INVALID;
  360. ENTER((2, "FindOpClass(Op=%x,pOpTable=%x)\n", bOp, pOpTable));
  361. while (pOpTable->bOpClass != 0)
  362. {
  363. if (bOp == pOpTable->bExOp)
  364. {
  365. bOpClass = pOpTable->bOpClass;
  366. break;
  367. }
  368. else
  369. pOpTable++;
  370. }
  371. EXIT((2, "FindOpClass=%x\n", bOpClass));
  372. return bOpClass;
  373. } //FindOpClass
  374. /***LP FindOpTerm - Find opcode in TermTable
  375. *
  376. * ENTRY
  377. * dwOpcode - opcode
  378. *
  379. * EXIT-SUCCESS
  380. * returns TermTable entry pointer
  381. * EXIT-FAILURE
  382. * returns NULL
  383. */
  384. PASLTERM LOCAL FindOpTerm(DWORD dwOpcode)
  385. {
  386. PASLTERM pterm = NULL;
  387. int i;
  388. ENTER((2, "FindOpTerm(Opcode=%x)\n", dwOpcode));
  389. for (i = 0; TermTable[i].pszID != NULL; ++i)
  390. {
  391. if ((TermTable[i].dwOpcode == dwOpcode) &&
  392. (TermTable[i].dwfTermClass &
  393. (TC_CONST_NAME | TC_SHORT_NAME | TC_NAMESPACE_MODIFIER |
  394. TC_DATA_OBJECT | TC_NAMED_OBJECT | TC_OPCODE_TYPE1 |
  395. TC_OPCODE_TYPE2)))
  396. {
  397. break;
  398. }
  399. }
  400. if (TermTable[i].pszID != NULL)
  401. {
  402. pterm = &TermTable[i];
  403. }
  404. EXIT((2, "FindOpTerm=%p (Term=%s)\n", pterm, pterm? pterm->pszID: ""));
  405. return pterm;
  406. } //FindOpTerm
  407. /***LP FindKeywordTerm - Find keyword in TermTable
  408. *
  409. * ENTRY
  410. * cKWGroup - keyword group
  411. * bData - data to match keyword
  412. *
  413. * EXIT-SUCCESS
  414. * returns TermTable entry pointer
  415. * EXIT-FAILURE
  416. * returns NULL
  417. */
  418. PASLTERM LOCAL FindKeywordTerm(char cKWGroup, BYTE bData)
  419. {
  420. PASLTERM pterm = NULL;
  421. int i;
  422. ENTER((2, "FindKeywordTerm(cKWGroup=%c,Data=%x)\n", cKWGroup, bData));
  423. for (i = 0; TermTable[i].pszID != NULL; ++i)
  424. {
  425. if ((TermTable[i].dwfTermClass == TC_KEYWORD) &&
  426. (TermTable[i].pszArgActions[0] == cKWGroup) &&
  427. ((bData & (BYTE)(TermTable[i].dwTermData >> 8)) ==
  428. (BYTE)(TermTable[i].dwTermData & 0xff)))
  429. {
  430. break;
  431. }
  432. }
  433. if (TermTable[i].pszID != NULL)
  434. {
  435. pterm = &TermTable[i];
  436. }
  437. EXIT((2, "FindKeywordTerm=%p (Term=%s)\n", pterm, pterm? pterm->pszID: ""));
  438. return pterm;
  439. } //FindKeywordTerm
  440. /***LP UnAsmScope - Unassemble a scope
  441. *
  442. * ENTRY
  443. * ppbOp -> Opcode pointer
  444. * pbEnd -> end of scope
  445. * pfileOut -> ASM output file
  446. *
  447. * EXIT-SUCCESS
  448. * returns ASLERR_NONE
  449. * EXIT-FAILURE
  450. * returns negative error code
  451. */
  452. int LOCAL UnAsmScope(PBYTE *ppbOp, PBYTE pbEnd, FILE *pfileOut)
  453. {
  454. int rc = ASLERR_NONE;
  455. ENTER((2, "UnAsmScope(pbOp=%p,pbEnd=%p,pfileOut=%p)\n",
  456. *ppbOp, pbEnd, pfileOut));
  457. DumpCode(*ppbOp, pfileOut);
  458. PrintIndent(giLevel, pfileOut);
  459. if (pfileOut != NULL)
  460. {
  461. fprintf(pfileOut, "{\n");
  462. }
  463. giLevel++;
  464. while ((rc == ASLERR_NONE) && (*ppbOp < pbEnd))
  465. {
  466. PrintIndent(giLevel, pfileOut);
  467. rc = UnAsmOpcode(ppbOp, pfileOut);
  468. if (gpbOpBegin != *ppbOp)
  469. {
  470. DumpCode(*ppbOp, pfileOut);
  471. }
  472. else if (pfileOut != NULL)
  473. {
  474. fprintf(pfileOut, "\n");
  475. }
  476. }
  477. giLevel--;
  478. PrintIndent(giLevel, pfileOut);
  479. if (pfileOut != NULL)
  480. {
  481. fprintf(pfileOut, "}");
  482. }
  483. EXIT((2, "UnAsmScope=%d\n", rc));
  484. return rc;
  485. } //UnAsmScope
  486. /***LP UnAsmOpcode - Unassemble an Opcode
  487. *
  488. * ENTRY
  489. * ppbOp -> Opcode pointer
  490. * pfileOut -> ASM output file
  491. *
  492. * EXIT-SUCCESS
  493. * returns ASLERR_NONE
  494. * EXIT-FAILURE
  495. * returns negative error code
  496. */
  497. int LOCAL UnAsmOpcode(PBYTE *ppbOp, FILE *pfileOut)
  498. {
  499. int rc = ASLERR_NONE;
  500. DWORD dwOpcode;
  501. BYTE bOp;
  502. PASLTERM pterm;
  503. char szUnAsmArgTypes[MAX_ARGS + 1];
  504. PNSOBJ pns;
  505. int i;
  506. ENTER((2, "UnAsmOpcode(pbOp=%p,pfileOut=%p)\n", *ppbOp, pfileOut));
  507. if (**ppbOp == OP_EXT_PREFIX)
  508. {
  509. (*ppbOp)++;
  510. dwOpcode = (((DWORD)**ppbOp) << 8) | OP_EXT_PREFIX;
  511. bOp = FindOpClass(**ppbOp, ExOpClassTable);
  512. }
  513. else
  514. {
  515. dwOpcode = (DWORD)(**ppbOp);
  516. bOp = OpClassTable[**ppbOp];
  517. }
  518. switch (bOp)
  519. {
  520. case OPCLASS_DATA_OBJ:
  521. rc = UnAsmDataObj(ppbOp, pfileOut);
  522. break;
  523. case OPCLASS_NAME_OBJ:
  524. if (((rc = UnAsmNameObj(ppbOp, pfileOut, &pns, NSTYPE_UNKNOWN)) ==
  525. ASLERR_NONE) &&
  526. (pns != NULL) &&
  527. (pns->ObjData.dwDataType == OBJTYPE_METHOD))
  528. {
  529. for (i = 0; i < (int)pns->ObjData.uipDataValue; ++i)
  530. {
  531. szUnAsmArgTypes[i] = 'C';
  532. }
  533. szUnAsmArgTypes[i] = '\0';
  534. rc = UnAsmArgs(szUnAsmArgTypes, NULL, 0, ppbOp, NULL, pfileOut);
  535. }
  536. break;
  537. case OPCLASS_ARG_OBJ:
  538. case OPCLASS_LOCAL_OBJ:
  539. case OPCLASS_CODE_OBJ:
  540. case OPCLASS_CONST_OBJ:
  541. if ((pterm = FindOpTerm(dwOpcode)) == NULL)
  542. {
  543. ERROR(("UnAsmOpcode: invalid opcode 0x%x", dwOpcode));
  544. rc = ASLERR_INVALID_OPCODE;
  545. }
  546. else
  547. {
  548. (*ppbOp)++;
  549. rc = UnAsmTermObj(pterm, ppbOp, pfileOut);
  550. }
  551. break;
  552. default:
  553. ERROR(("UnAsmOpcode: invalid opcode class %d", bOp));
  554. rc = ASLERR_INTERNAL_ERROR;
  555. }
  556. EXIT((2, "UnAsmOpcode=%d\n", rc));
  557. return rc;
  558. } //UnAsmOpcode
  559. /***LP UnAsmDataObj - Unassemble data object
  560. *
  561. * ENTRY
  562. * ppbOp -> opcode pointer
  563. * pfileOut -> ASM output file
  564. *
  565. * EXIT-SUCCESS
  566. * returns ASLERR_NONE
  567. * EXIT-FAILURE
  568. * returns negative error code
  569. */
  570. int LOCAL UnAsmDataObj(PBYTE *ppbOp, FILE *pfileOut)
  571. {
  572. int rc = ASLERR_NONE;
  573. BYTE bOp = **ppbOp;
  574. ENTER((2, "UnAsmDataObj(pbOp=%p,bOp=%x,pfileOut=%p)\n",
  575. *ppbOp, bOp, pfileOut));
  576. (*ppbOp)++;
  577. switch (bOp)
  578. {
  579. case OP_BYTE:
  580. if (pfileOut != NULL)
  581. {
  582. fprintf(pfileOut, "0x%x", **ppbOp);
  583. }
  584. *ppbOp += sizeof(BYTE);
  585. break;
  586. case OP_WORD:
  587. if (pfileOut != NULL)
  588. {
  589. fprintf(pfileOut, "0x%x", *((PWORD)*ppbOp));
  590. }
  591. *ppbOp += sizeof(WORD);
  592. break;
  593. case OP_DWORD:
  594. if (pfileOut != NULL)
  595. {
  596. fprintf(pfileOut, "0x%x", *((PDWORD)*ppbOp));
  597. }
  598. *ppbOp += sizeof(DWORD);
  599. break;
  600. case OP_STRING:
  601. if (pfileOut != NULL)
  602. {
  603. PSZ psz;
  604. fprintf(pfileOut, "\"");
  605. for (psz = (PSZ)*ppbOp; *psz != '\0'; psz++)
  606. {
  607. if (*psz == '\\')
  608. {
  609. fprintf(pfileOut, "\\");
  610. }
  611. fprintf(pfileOut, "%c", *psz);
  612. }
  613. fprintf(pfileOut, "\"");
  614. }
  615. *ppbOp += strlen((PSZ)*ppbOp) + 1;
  616. break;
  617. default:
  618. ERROR(("UnAsmDataObj: unexpected opcode 0x%x", bOp));
  619. rc = ASLERR_INVALID_OPCODE;
  620. }
  621. EXIT((2, "UnAsmDataObj=%d\n", rc));
  622. return rc;
  623. } //UnAsmDataObj
  624. /***LP UnAsmNameObj - Unassemble name object
  625. *
  626. * ENTRY
  627. * ppbOp -> opcode pointer
  628. * pfileOut -> ASM output file
  629. * ppns -> to hold object found or created
  630. * c - object type
  631. *
  632. * EXIT-SUCCESS
  633. * returns ASLERR_NONE
  634. * EXIT-FAILURE
  635. * returns negative error code
  636. */
  637. int LOCAL UnAsmNameObj(PBYTE *ppbOp, FILE *pfileOut, PNSOBJ *ppns, char c)
  638. {
  639. int rc = ASLERR_NONE;
  640. char szName[MAX_NAME_LEN + 1];
  641. int iLen = 0;
  642. ENTER((2, "UnAsmNameObj(pbOp=%p,pfileOut=%p,ppns=%p,c=%c)\n",
  643. *ppbOp, pfileOut, ppns, c));
  644. szName[0] = '\0';
  645. if (**ppbOp == OP_ROOT_PREFIX)
  646. {
  647. szName[iLen] = '\\';
  648. iLen++;
  649. (*ppbOp)++;
  650. rc = ParseNameTail(ppbOp, szName, iLen);
  651. }
  652. else if (**ppbOp == OP_PARENT_PREFIX)
  653. {
  654. szName[iLen] = '^';
  655. iLen++;
  656. (*ppbOp)++;
  657. while ((**ppbOp == OP_PARENT_PREFIX) && (iLen < MAX_NAME_LEN))
  658. {
  659. szName[iLen] = '^';
  660. iLen++;
  661. (*ppbOp)++;
  662. }
  663. if (**ppbOp == OP_PARENT_PREFIX)
  664. {
  665. ERROR(("UnAsmNameObj: name too long - \"%s\"", szName));
  666. rc = ASLERR_NAME_TOO_LONG;
  667. }
  668. else
  669. {
  670. rc = ParseNameTail(ppbOp, szName, iLen);
  671. }
  672. }
  673. else
  674. {
  675. rc = ParseNameTail(ppbOp, szName, iLen);
  676. }
  677. if (rc == ASLERR_NONE)
  678. {
  679. PNSOBJ pns = NULL;
  680. if (pfileOut != NULL)
  681. {
  682. fprintf(pfileOut, "%s", szName);
  683. }
  684. if (islower(c) && (gdwfASL & ASLF_UNASM) &&
  685. ((pfileOut == NULL) ||
  686. (gpnsCurrentScope->ObjData.dwDataType == OBJTYPE_METHOD)))
  687. {
  688. rc = CreateObject(NULL, szName, (char)_toupper(c), &pns);
  689. }
  690. else if ((rc = GetNameSpaceObj(szName, gpnsCurrentScope, &pns, 0)) ==
  691. ASLERR_NSOBJ_NOT_FOUND)
  692. {
  693. if (c == NSTYPE_SCOPE)
  694. {
  695. rc = CreateScopeObj(szName, &pns);
  696. }
  697. else
  698. {
  699. rc = ASLERR_NONE;
  700. }
  701. }
  702. if (rc == ASLERR_NONE)
  703. {
  704. if ((c == NSTYPE_SCOPE) && (pns != NULL))
  705. {
  706. gpnsCurrentScope = pns;
  707. }
  708. if (ppns != NULL)
  709. {
  710. *ppns = pns;
  711. }
  712. }
  713. }
  714. EXIT((2, "UnAsmNameObj=%d (pns=%p)\n", rc, ppns? *ppns: 0));
  715. return rc;
  716. } //UnAsmNameObj
  717. /***LP ParseNameTail - Parse AML name tail
  718. *
  719. * ENTRY
  720. * ppbOp -> opcode pointer
  721. * pszBuff -> to hold parsed name
  722. * iLen - index to tail of pszBuff
  723. *
  724. * EXIT-SUCCESS
  725. * returns ASLERR_NONE
  726. * EXIT-FAILURE
  727. * returns negative error code
  728. */
  729. int LOCAL ParseNameTail(PBYTE *ppbOp, PSZ pszBuff, int iLen)
  730. {
  731. int rc = ASLERR_NONE;
  732. int icNameSegs = 0;
  733. ENTER((2, "ParseNameTail(pbOp=%x,Name=%s,iLen=%d)\n",
  734. *ppbOp, pszBuff, iLen));
  735. //
  736. // We do not check for invalid NameSeg characters here and assume that
  737. // the compiler does its job not generating it.
  738. //
  739. if (**ppbOp == '\0')
  740. {
  741. //
  742. // There is no NameTail (i.e. either NULL name or name with just
  743. // prefixes.
  744. //
  745. (*ppbOp)++;
  746. }
  747. else if (**ppbOp == OP_MULTI_NAME_PREFIX)
  748. {
  749. (*ppbOp)++;
  750. icNameSegs = (int)**ppbOp;
  751. (*ppbOp)++;
  752. }
  753. else if (**ppbOp == OP_DUAL_NAME_PREFIX)
  754. {
  755. (*ppbOp)++;
  756. icNameSegs = 2;
  757. }
  758. else
  759. icNameSegs = 1;
  760. while ((icNameSegs > 0) && (iLen + sizeof(NAMESEG) < MAX_NAME_LEN))
  761. {
  762. strncpy(&pszBuff[iLen], (PSZ)(*ppbOp), sizeof(NAMESEG));
  763. iLen += sizeof(NAMESEG);
  764. *ppbOp += sizeof(NAMESEG);
  765. icNameSegs--;
  766. if ((icNameSegs > 0) && (iLen + 1 < MAX_NAME_LEN))
  767. {
  768. pszBuff[iLen] = '.';
  769. iLen++;
  770. }
  771. }
  772. if (icNameSegs > 0)
  773. {
  774. ERROR(("ParseNameTail: name too long - %s", pszBuff));
  775. rc = ASLERR_NAME_TOO_LONG;
  776. }
  777. else
  778. {
  779. pszBuff[iLen] = '\0';
  780. }
  781. EXIT((2, "ParseNameTail=%x (Name=%s)\n", rc, pszBuff));
  782. return rc;
  783. } //ParseNameTail
  784. /***LP UnAsmTermObj - Unassemble term object
  785. *
  786. * ENTRY
  787. * pterm -> term table entry
  788. * ppbOp -> opcode pointer
  789. * pfileOut -> ASM output file
  790. *
  791. * EXIT-SUCCESS
  792. * returns ASLERR_NONE
  793. * EXIT-FAILURE
  794. * returns negative error code
  795. */
  796. int LOCAL UnAsmTermObj(PASLTERM pterm, PBYTE *ppbOp, FILE *pfileOut)
  797. {
  798. int rc = ASLERR_NONE;
  799. PBYTE pbEnd = NULL;
  800. PNSOBJ pnsScopeSave = gpnsCurrentScope;
  801. PNSOBJ pns = NULL;
  802. ENTER((2, "UnAsmTermObj(pterm=%p,Term=%s,pbOp=%p,pfileOut=%p)\n",
  803. pterm, pterm->pszID, *ppbOp, pfileOut));
  804. if (pfileOut != NULL)
  805. {
  806. fprintf(pfileOut, "%s", pterm->pszID);
  807. }
  808. if (pterm->dwfTerm & TF_PACKAGE_LEN)
  809. {
  810. ParsePackageLen(ppbOp, &pbEnd);
  811. }
  812. if (pterm->pszUnAsmArgTypes != NULL)
  813. {
  814. rc = UnAsmArgs(pterm->pszUnAsmArgTypes, pterm->pszArgActions,
  815. pterm->dwTermData, ppbOp, &pns, pfileOut);
  816. }
  817. if (rc == ASLERR_NONE)
  818. {
  819. if (pterm->dwfTerm & TF_DATA_LIST)
  820. {
  821. rc = UnAsmDataList(ppbOp, pbEnd, pfileOut);
  822. }
  823. else if (pterm->dwfTerm & TF_PACKAGE_LIST)
  824. {
  825. rc = UnAsmPkgList(ppbOp, pbEnd, pfileOut);
  826. }
  827. else if (pterm->dwfTerm & TF_FIELD_LIST)
  828. {
  829. rc = UnAsmFieldList(ppbOp, pbEnd, pfileOut);
  830. }
  831. else if (pterm->dwfTerm & TF_PACKAGE_LEN)
  832. {
  833. if ((pfileOut == NULL) && (pterm->lID == ID_METHOD))
  834. {
  835. //
  836. // We are in NameSpace building pass, so don't need to
  837. // go into methods.
  838. //
  839. *ppbOp = pbEnd;
  840. }
  841. else
  842. {
  843. if (pterm->dwfTerm & TF_CHANGE_CHILDSCOPE)
  844. {
  845. ASSERT(pns != NULL);
  846. gpnsCurrentScope = pns;
  847. }
  848. rc = UnAsmScope(ppbOp, pbEnd, pfileOut);
  849. }
  850. }
  851. }
  852. gpnsCurrentScope = pnsScopeSave;
  853. EXIT((2, "UnAsmTermObj=%d\n", rc));
  854. return rc;
  855. } //UnAsmTermObj
  856. /***LP UnAsmArgs - Unassemble arguments
  857. *
  858. * ENTRY
  859. * pszUnArgTypes -> UnAsm ArgTypes string
  860. * pszArgActions -> Arg Action types
  861. * dwTermData - Term data
  862. * ppbOp -> opcode pointer
  863. * ppns -> to hold created object
  864. * pfileOut -> ASM output file
  865. *
  866. * EXIT-SUCCESS
  867. * returns ASLERR_NONE
  868. * EXIT-FAILURE
  869. * returns negative error code
  870. */
  871. int LOCAL UnAsmArgs(PSZ pszUnAsmArgTypes, PSZ pszArgActions, DWORD dwTermData,
  872. PBYTE *ppbOp, PNSOBJ *ppns, FILE *pfileOut)
  873. {
  874. int rc = ASLERR_NONE;
  875. static BYTE bArgData = 0;
  876. int iNumArgs, i;
  877. PASLTERM pterm;
  878. ENTER((2, "UnAsmArgs(UnAsmArgTypes=%s,ArgActions=%s,TermData=%x,pbOp=%p,ppns=%p,pfileOut=%p)\n",
  879. pszUnAsmArgTypes, pszArgActions? pszArgActions: "", dwTermData,
  880. *ppbOp, ppns, pfileOut));
  881. iNumArgs = strlen(pszUnAsmArgTypes);
  882. if (pfileOut != NULL)
  883. {
  884. fprintf(pfileOut, "(");
  885. }
  886. for (i = 0; i < iNumArgs; ++i)
  887. {
  888. if ((i != 0) && (pfileOut != NULL))
  889. {
  890. fprintf(pfileOut, ", ");
  891. }
  892. switch (pszUnAsmArgTypes[i])
  893. {
  894. case 'N':
  895. ASSERT(pszArgActions != NULL);
  896. rc = UnAsmNameObj(ppbOp, pfileOut, ppns, pszArgActions[i]);
  897. break;
  898. case 'O':
  899. if ((**ppbOp == OP_BUFFER) || (**ppbOp == OP_PACKAGE) ||
  900. (OpClassTable[**ppbOp] == OPCLASS_CONST_OBJ))
  901. {
  902. pterm = FindOpTerm((DWORD)(**ppbOp));
  903. ASSERT(pterm != NULL);
  904. (*ppbOp)++;
  905. rc = UnAsmTermObj(pterm, ppbOp, pfileOut);
  906. }
  907. else
  908. {
  909. rc = UnAsmDataObj(ppbOp, pfileOut);
  910. }
  911. break;
  912. case 'C':
  913. rc = UnAsmOpcode(ppbOp, pfileOut);
  914. break;
  915. case 'B':
  916. if (pfileOut != NULL)
  917. {
  918. fprintf(pfileOut, "0x%x", **ppbOp);
  919. }
  920. *ppbOp += sizeof(BYTE);
  921. break;
  922. case 'E':
  923. case 'e':
  924. case 'K':
  925. case 'k':
  926. if ((pszUnAsmArgTypes[i] == 'K') ||
  927. (pszUnAsmArgTypes[i] == 'E'))
  928. {
  929. bArgData = **ppbOp;
  930. }
  931. if ((pszArgActions != NULL) && (pszArgActions[i] == '!'))
  932. {
  933. if ((gdwfASL & ASLF_UNASM) && (*ppns != NULL))
  934. {
  935. (*ppns)->ObjData.uipDataValue = (DWORD)(**ppbOp & 0x07);
  936. }
  937. if (pfileOut != NULL)
  938. {
  939. fprintf(pfileOut, "0x%x", **ppbOp & 0x07);
  940. }
  941. }
  942. else if (pfileOut != NULL)
  943. {
  944. pterm = FindKeywordTerm(pszArgActions[i], bArgData);
  945. if (pterm != NULL)
  946. {
  947. fprintf(pfileOut, "%s", pterm->pszID);
  948. }
  949. else
  950. {
  951. fprintf(pfileOut, "0x%x", bArgData & dwTermData & 0xff);
  952. }
  953. }
  954. if ((pszUnAsmArgTypes[i] == 'K') ||
  955. (pszUnAsmArgTypes[i] == 'E'))
  956. {
  957. *ppbOp += sizeof(BYTE);
  958. }
  959. break;
  960. case 'W':
  961. if (pfileOut != NULL)
  962. {
  963. fprintf(pfileOut, "0x%x", *((PWORD)*ppbOp));
  964. }
  965. *ppbOp += sizeof(WORD);
  966. break;
  967. case 'D':
  968. if (pfileOut != NULL)
  969. {
  970. fprintf(pfileOut, "0x%x", *((PDWORD)*ppbOp));
  971. }
  972. *ppbOp += sizeof(DWORD);
  973. break;
  974. case 'S':
  975. ASSERT(pszArgActions != NULL);
  976. rc = UnAsmSuperName(ppbOp, pfileOut);
  977. break;
  978. default:
  979. ERROR(("UnAsmOpcode: invalid ArgType '%c'", pszUnAsmArgTypes[i]));
  980. rc = ASLERR_INVALID_ARGTYPE;
  981. }
  982. }
  983. if (pfileOut != NULL)
  984. {
  985. fprintf(pfileOut, ")");
  986. }
  987. EXIT((2, "UnAsmArgs=%d\n", rc));
  988. return rc;
  989. } //UnAsmArgs
  990. /***LP UnAsmSuperName - Unassemble supername
  991. *
  992. * ENTRY
  993. * ppbOp -> opcode pointer
  994. * pfileOut -> ASM output file
  995. *
  996. * EXIT-SUCCESS
  997. * returns ASLERR_NONE
  998. * EXIT-FAILURE
  999. * returns negative error code
  1000. */
  1001. int LOCAL UnAsmSuperName(PBYTE *ppbOp, FILE *pfileOut)
  1002. {
  1003. int rc = ASLERR_NONE;
  1004. ENTER((2, "UnAsmSuperName(pbOp=%p,pfileOut=%p)\n", *ppbOp, pfileOut));
  1005. if (**ppbOp == 0)
  1006. {
  1007. (*ppbOp)++;
  1008. }
  1009. else if ((**ppbOp == OP_EXT_PREFIX) && (*(*ppbOp + 1) == EXOP_DEBUG))
  1010. {
  1011. if (pfileOut != NULL)
  1012. {
  1013. fprintf(pfileOut, "Debug");
  1014. }
  1015. *ppbOp += 2;
  1016. }
  1017. else if (OpClassTable[**ppbOp] == OPCLASS_NAME_OBJ)
  1018. {
  1019. rc = UnAsmNameObj(ppbOp, pfileOut, NULL, NSTYPE_UNKNOWN);
  1020. }
  1021. else if ((**ppbOp == OP_INDEX) ||
  1022. (OpClassTable[**ppbOp] == OPCLASS_ARG_OBJ) ||
  1023. (OpClassTable[**ppbOp] == OPCLASS_LOCAL_OBJ))
  1024. {
  1025. rc = UnAsmOpcode(ppbOp, pfileOut);
  1026. }
  1027. else
  1028. {
  1029. ERROR(("UnAsmSuperName: invalid SuperName - 0x%02x", **ppbOp));
  1030. rc = ASLERR_INVALID_NAME;
  1031. }
  1032. EXIT((2, "UnAsmSuperName=%d\n", rc));
  1033. return rc;
  1034. } //UnAsmSuperName
  1035. /***LP ParsePackageLen - parse package length
  1036. *
  1037. * ENTRY
  1038. * ppbOp -> instruction pointer
  1039. * ppbOpNext -> to hold pointer to next instruction (can be NULL)
  1040. *
  1041. * EXIT
  1042. * returns package length
  1043. */
  1044. DWORD LOCAL ParsePackageLen(PBYTE *ppbOp, PBYTE *ppbOpNext)
  1045. {
  1046. DWORD dwLen;
  1047. BYTE bFollowCnt, i;
  1048. ENTER((2, "ParsePackageLen(pbOp=%x,ppbOpNext=%x)\n", *ppbOp, ppbOpNext));
  1049. if (ppbOpNext != NULL)
  1050. *ppbOpNext = *ppbOp;
  1051. dwLen = (DWORD)(**ppbOp);
  1052. (*ppbOp)++;
  1053. bFollowCnt = (BYTE)((dwLen & 0xc0) >> 6);
  1054. if (bFollowCnt != 0)
  1055. {
  1056. dwLen &= 0x0000000f;
  1057. for (i = 0; i < bFollowCnt; ++i)
  1058. {
  1059. dwLen |= (DWORD)(**ppbOp) << (i*8 + 4);
  1060. (*ppbOp)++;
  1061. }
  1062. }
  1063. if (ppbOpNext != NULL)
  1064. *ppbOpNext += dwLen;
  1065. EXIT((2, "ParsePackageLen=%x (pbOp=%x,pbOpNext=%x)\n",
  1066. dwLen, *ppbOp, ppbOpNext? *ppbOpNext: 0));
  1067. return dwLen;
  1068. } //ParsePackageLen
  1069. /***LP UnAsmDataList - Unassemble data list
  1070. *
  1071. * ENTRY
  1072. * ppbOp -> opcode pointer
  1073. * pbEnd -> end of list
  1074. * pfileOut -> ASM output file
  1075. *
  1076. * EXIT-SUCCESS
  1077. * returns ASLERR_NONE
  1078. * EXIT-FAILURE
  1079. * returns negative error code
  1080. */
  1081. int LOCAL UnAsmDataList(PBYTE *ppbOp, PBYTE pbEnd, FILE *pfileOut)
  1082. {
  1083. int rc = ASLERR_NONE;
  1084. int i;
  1085. ENTER((2, "UnAsmDataList(pbOp=%p,pbEnd=%p,pfileOut=%p)\n",
  1086. *ppbOp, pbEnd, pfileOut));
  1087. DumpCode(*ppbOp, pfileOut);
  1088. PrintIndent(giLevel, pfileOut);
  1089. if (pfileOut != NULL)
  1090. {
  1091. fprintf(pfileOut, "{\n");
  1092. }
  1093. while (*ppbOp < pbEnd)
  1094. {
  1095. if (pfileOut != NULL)
  1096. {
  1097. if ((gdwfASL & ASLF_GENASM) || !(gdwfASL & ASLF_GENSRC))
  1098. {
  1099. fprintf(pfileOut, ";");
  1100. }
  1101. fprintf(pfileOut, "\t0x%02x", **ppbOp);
  1102. }
  1103. (*ppbOp)++;
  1104. for (i = 1; (*ppbOp < pbEnd) && (i < 12); ++i)
  1105. {
  1106. if (pfileOut != NULL)
  1107. {
  1108. fprintf(pfileOut, ", 0x%02x", **ppbOp);
  1109. }
  1110. (*ppbOp)++;
  1111. }
  1112. if (pfileOut != NULL)
  1113. {
  1114. if (*ppbOp < pbEnd)
  1115. {
  1116. fprintf(pfileOut, ",");
  1117. }
  1118. fprintf(pfileOut, "\n");
  1119. }
  1120. }
  1121. PrintIndent(giLevel, pfileOut);
  1122. if (pfileOut != NULL)
  1123. {
  1124. fprintf(pfileOut, "}");
  1125. }
  1126. EXIT((2, "UnAsmDataList=%d\n", rc));
  1127. return rc;
  1128. } //UnAsmDataList
  1129. /***LP UnAsmPkgList - Unassemble package list
  1130. *
  1131. * ENTRY
  1132. * ppbOp -> opcode pointer
  1133. * pbEnd -> end of list
  1134. * pfileOut -> ASM output file
  1135. *
  1136. * EXIT-SUCCESS
  1137. * returns ASLERR_NONE
  1138. * EXIT-FAILURE
  1139. * returns negative error code
  1140. */
  1141. int LOCAL UnAsmPkgList(PBYTE *ppbOp, PBYTE pbEnd, FILE *pfileOut)
  1142. {
  1143. int rc = ASLERR_NONE;
  1144. PASLTERM pterm;
  1145. ENTER((2, "UnAsmPkgList(pbOp=%p,pbEnd=%p,pfileOut=%p)\n",
  1146. *ppbOp, pbEnd, pfileOut));
  1147. DumpCode(*ppbOp, pfileOut);
  1148. PrintIndent(giLevel, pfileOut);
  1149. if (pfileOut != NULL)
  1150. {
  1151. fprintf(pfileOut, "{\n");
  1152. }
  1153. giLevel++;
  1154. while ((*ppbOp < pbEnd) && (rc == ASLERR_NONE))
  1155. {
  1156. PrintIndent(giLevel, pfileOut);
  1157. if ((**ppbOp == OP_BUFFER) || (**ppbOp == OP_PACKAGE) ||
  1158. (OpClassTable[**ppbOp] == OPCLASS_CONST_OBJ))
  1159. {
  1160. pterm = FindOpTerm((DWORD)(**ppbOp));
  1161. ASSERT(pterm != NULL);
  1162. (*ppbOp)++;
  1163. rc = UnAsmTermObj(pterm, ppbOp, pfileOut);
  1164. }
  1165. else if (OpClassTable[**ppbOp] == OPCLASS_NAME_OBJ)
  1166. {
  1167. rc = UnAsmNameObj(ppbOp, pfileOut, NULL, NSTYPE_UNKNOWN);
  1168. }
  1169. else
  1170. {
  1171. rc = UnAsmDataObj(ppbOp, pfileOut);
  1172. }
  1173. if ((*ppbOp < pbEnd) && (rc == ASLERR_NONE) && (pfileOut != NULL))
  1174. {
  1175. fprintf(pfileOut, ",");
  1176. }
  1177. DumpCode(*ppbOp, pfileOut);
  1178. }
  1179. giLevel--;
  1180. PrintIndent(giLevel, pfileOut);
  1181. if (pfileOut != NULL)
  1182. {
  1183. fprintf(pfileOut, "}");
  1184. }
  1185. EXIT((2, "UnAsmPkgList=%d\n", rc));
  1186. return rc;
  1187. } //UnAsmPkgList
  1188. /***LP UnAsmFieldList - Unassemble field list
  1189. *
  1190. * ENTRY
  1191. * ppbOp -> opcode pointer
  1192. * pbEnd -> end of list
  1193. * pfileOut -> ASM output file
  1194. *
  1195. * EXIT-SUCCESS
  1196. * returns ASLERR_NONE
  1197. * EXIT-FAILURE
  1198. * returns negative error code
  1199. */
  1200. int LOCAL UnAsmFieldList(PBYTE *ppbOp, PBYTE pbEnd, FILE *pfileOut)
  1201. {
  1202. int rc = ASLERR_NONE;
  1203. DWORD dwBitPos = 0;
  1204. ENTER((2, "UnAsmFieldList(pbOp=%p,pbEnd=%p,pfileOut=%p)\n",
  1205. *ppbOp, pbEnd, pfileOut));
  1206. DumpCode(*ppbOp, pfileOut);
  1207. PrintIndent(giLevel, pfileOut);
  1208. if (pfileOut != NULL)
  1209. {
  1210. fprintf(pfileOut, "{\n");
  1211. }
  1212. giLevel++;
  1213. while ((*ppbOp < pbEnd) && (rc == ASLERR_NONE))
  1214. {
  1215. PrintIndent(giLevel, pfileOut);
  1216. if (((rc = UnAsmField(ppbOp, pfileOut, &dwBitPos)) == ASLERR_NONE) &&
  1217. (*ppbOp < pbEnd) && (pfileOut != NULL))
  1218. {
  1219. fprintf(pfileOut, ",");
  1220. }
  1221. DumpCode(*ppbOp, pfileOut);
  1222. }
  1223. giLevel--;
  1224. PrintIndent(giLevel, pfileOut);
  1225. if (pfileOut != NULL)
  1226. {
  1227. fprintf(pfileOut, "}");
  1228. }
  1229. EXIT((2, "UnAsmFieldList=%d\n", rc));
  1230. return rc;
  1231. } //UnAsmFieldList
  1232. /***LP UnAsmField - Unassemble field
  1233. *
  1234. * ENTRY
  1235. * ppbOp -> opcode pointer
  1236. * pfileOut -> ASM output file
  1237. * pdwBitPos -> to hold cumulative bit position
  1238. *
  1239. * EXIT-SUCCESS
  1240. * returns ASLERR_NONE
  1241. * EXIT-FAILURE
  1242. * returns negative error code
  1243. */
  1244. int LOCAL UnAsmField(PBYTE *ppbOp, FILE *pfileOut, PDWORD pdwBitPos)
  1245. {
  1246. int rc = ASLERR_NONE;
  1247. ENTER((2, "UnAsmField(pbOp=%p,pfileOut=%p,BitPos=%x)\n",
  1248. *ppbOp, pfileOut, *pdwBitPos));
  1249. if (**ppbOp == 0x01)
  1250. {
  1251. (*ppbOp)++;
  1252. if (pfileOut != NULL)
  1253. {
  1254. PASLTERM pterm;
  1255. pterm = FindKeywordTerm('A', **ppbOp);
  1256. fprintf(pfileOut, "AccessAs(%s, 0x%x)",
  1257. pterm->pszID, *(*ppbOp + 1));
  1258. }
  1259. *ppbOp += 2;
  1260. }
  1261. else
  1262. {
  1263. char szNameSeg[sizeof(NAMESEG) + 1];
  1264. DWORD dwcbBits;
  1265. if (**ppbOp == 0)
  1266. {
  1267. szNameSeg[0] = '\0';
  1268. (*ppbOp)++;
  1269. }
  1270. else
  1271. {
  1272. strncpy(szNameSeg, (PSZ)*ppbOp, sizeof(NAMESEG));
  1273. szNameSeg[4] = '\0';
  1274. *ppbOp += sizeof(NAMESEG);
  1275. }
  1276. dwcbBits = ParsePackageLen(ppbOp, NULL);
  1277. if (szNameSeg[0] == '\0')
  1278. {
  1279. if (pfileOut != NULL)
  1280. {
  1281. if ((dwcbBits > 32) && (((*pdwBitPos + dwcbBits) % 8) == 0))
  1282. {
  1283. fprintf(pfileOut, "Offset(0x%x)", (*pdwBitPos + dwcbBits)/8);
  1284. }
  1285. else
  1286. {
  1287. fprintf(pfileOut, ", %d", dwcbBits);
  1288. }
  1289. }
  1290. }
  1291. else
  1292. {
  1293. if (pfileOut != NULL)
  1294. {
  1295. fprintf(pfileOut, "%s, %d", szNameSeg, dwcbBits);
  1296. }
  1297. if ((gdwfASL & ASLF_UNASM) && (pfileOut == NULL))
  1298. {
  1299. rc = CreateObject(NULL, szNameSeg, NSTYPE_FIELDUNIT, NULL);
  1300. }
  1301. }
  1302. *pdwBitPos += dwcbBits;
  1303. }
  1304. EXIT((2, "UnAsmField=%d\n", rc));
  1305. return rc;
  1306. } //UnAsmField