dmtables.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. /******************************************************************************
  2. *
  3. * Module Name: dmtables - disassembler ACPI table support
  4. *
  5. *****************************************************************************/
  6. /******************************************************************************
  7. *
  8. * 1. Copyright Notice
  9. *
  10. * Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp.
  11. * All rights reserved.
  12. *
  13. * 2. License
  14. *
  15. * 2.1. This is your license from Intel Corp. under its intellectual property
  16. * rights. You may have additional license terms from the party that provided
  17. * you this software, covering your right to use that party's intellectual
  18. * property rights.
  19. *
  20. * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  21. * copy of the source code appearing in this file ("Covered Code") an
  22. * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  23. * base code distributed originally by Intel ("Original Intel Code") to copy,
  24. * make derivatives, distribute, use and display any portion of the Covered
  25. * Code in any form, with the right to sublicense such rights; and
  26. *
  27. * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  28. * license (with the right to sublicense), under only those claims of Intel
  29. * patents that are infringed by the Original Intel Code, to make, use, sell,
  30. * offer to sell, and import the Covered Code and derivative works thereof
  31. * solely to the minimum extent necessary to exercise the above copyright
  32. * license, and in no event shall the patent license extend to any additions
  33. * to or modifications of the Original Intel Code. No other license or right
  34. * is granted directly or by implication, estoppel or otherwise;
  35. *
  36. * The above copyright and patent license is granted only if the following
  37. * conditions are met:
  38. *
  39. * 3. Conditions
  40. *
  41. * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  42. * Redistribution of source code of any substantial portion of the Covered
  43. * Code or modification with rights to further distribute source must include
  44. * the above Copyright Notice, the above License, this list of Conditions,
  45. * and the following Disclaimer and Export Compliance provision. In addition,
  46. * Licensee must cause all Covered Code to which Licensee contributes to
  47. * contain a file documenting the changes Licensee made to create that Covered
  48. * Code and the date of any change. Licensee must include in that file the
  49. * documentation of any changes made by any predecessor Licensee. Licensee
  50. * must include a prominent statement that the modification is derived,
  51. * directly or indirectly, from Original Intel Code.
  52. *
  53. * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
  54. * Redistribution of source code of any substantial portion of the Covered
  55. * Code or modification without rights to further distribute source must
  56. * include the following Disclaimer and Export Compliance provision in the
  57. * documentation and/or other materials provided with distribution. In
  58. * addition, Licensee may not authorize further sublicense of source of any
  59. * portion of the Covered Code, and must include terms to the effect that the
  60. * license from Licensee to its licensee is limited to the intellectual
  61. * property embodied in the software Licensee provides to its licensee, and
  62. * not to intellectual property embodied in modifications its licensee may
  63. * make.
  64. *
  65. * 3.3. Redistribution of Executable. Redistribution in executable form of any
  66. * substantial portion of the Covered Code or modification must reproduce the
  67. * above Copyright Notice, and the following Disclaimer and Export Compliance
  68. * provision in the documentation and/or other materials provided with the
  69. * distribution.
  70. *
  71. * 3.4. Intel retains all right, title, and interest in and to the Original
  72. * Intel Code.
  73. *
  74. * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  75. * Intel shall be used in advertising or otherwise to promote the sale, use or
  76. * other dealings in products derived from or relating to the Covered Code
  77. * without prior written authorization from Intel.
  78. *
  79. * 4. Disclaimer and Export Compliance
  80. *
  81. * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  82. * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  83. * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
  84. * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
  85. * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
  86. * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  87. * PARTICULAR PURPOSE.
  88. *
  89. * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  90. * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  91. * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  92. * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  93. * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  94. * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
  95. * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  96. * LIMITED REMEDY.
  97. *
  98. * 4.3. Licensee shall not export, either directly or indirectly, any of this
  99. * software or system incorporating such software without first obtaining any
  100. * required license or other approval from the U. S. Department of Commerce or
  101. * any other agency or department of the United States Government. In the
  102. * event Licensee exports any such software from the United States or
  103. * re-exports any such software from a foreign destination, Licensee shall
  104. * ensure that the distribution and export/re-export of the software is in
  105. * compliance with all laws, regulations, orders, or other restrictions of the
  106. * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  107. * any of its subsidiaries will export/re-export any technical data, process,
  108. * software, or service, directly or indirectly, to any country for which the
  109. * United States government or any agency thereof requires an export license,
  110. * other governmental approval, or letter of assurance, without first obtaining
  111. * such license, approval or letter.
  112. *
  113. *****************************************************************************/
  114. #include "aslcompiler.h"
  115. #include "acapps.h"
  116. #include "acdispat.h"
  117. #include "acnamesp.h"
  118. #include "actables.h"
  119. #include "acparser.h"
  120. #include <stdio.h>
  121. #include <time.h>
  122. #define _COMPONENT ACPI_TOOLS
  123. ACPI_MODULE_NAME ("dmtables")
  124. /* Local prototypes */
  125. static void
  126. AdCreateTableHeader (
  127. char *Filename,
  128. ACPI_TABLE_HEADER *Table);
  129. static ACPI_STATUS
  130. AdStoreTable (
  131. ACPI_TABLE_HEADER *Table,
  132. UINT32 *TableIndex);
  133. extern ACPI_TABLE_DESC LocalTables[1];
  134. extern ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
  135. /******************************************************************************
  136. *
  137. * FUNCTION: AdDisassemblerHeader
  138. *
  139. * PARAMETERS: Filename - Input file for the table
  140. * TableType - Either AML or DataTable
  141. *
  142. * RETURN: None
  143. *
  144. * DESCRIPTION: Create the disassembler header, including ACPICA signon with
  145. * current time and date.
  146. *
  147. *****************************************************************************/
  148. void
  149. AdDisassemblerHeader (
  150. char *Filename,
  151. UINT8 TableType)
  152. {
  153. time_t Timer;
  154. time (&Timer);
  155. /* Header and input table info */
  156. AcpiOsPrintf ("/*\n");
  157. AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
  158. if (TableType == ACPI_IS_AML_TABLE)
  159. {
  160. if (AcpiGbl_CstyleDisassembly)
  161. {
  162. AcpiOsPrintf (
  163. " * Disassembling to symbolic ASL+ operators\n"
  164. " *\n");
  165. }
  166. else
  167. {
  168. AcpiOsPrintf (
  169. " * Disassembling to non-symbolic legacy ASL operators\n"
  170. " *\n");
  171. }
  172. }
  173. AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
  174. AcpiOsPrintf (" *\n");
  175. }
  176. /******************************************************************************
  177. *
  178. * FUNCTION: AdCreateTableHeader
  179. *
  180. * PARAMETERS: Filename - Input file for the table
  181. * Table - Pointer to the raw table
  182. *
  183. * RETURN: None
  184. *
  185. * DESCRIPTION: Create the ASL table header, including ACPICA signon with
  186. * current time and date.
  187. *
  188. *****************************************************************************/
  189. static void
  190. AdCreateTableHeader (
  191. char *Filename,
  192. ACPI_TABLE_HEADER *Table)
  193. {
  194. UINT8 Checksum;
  195. /* Reset globals for External statements */
  196. AcpiGbl_NumExternalMethods = 0;
  197. AcpiGbl_ResolvedExternalMethods = 0;
  198. /*
  199. * Print file header and dump original table header
  200. */
  201. AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
  202. AcpiOsPrintf (" * Original Table Header:\n");
  203. AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
  204. AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
  205. /* Print and validate the revision */
  206. AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
  207. switch (Table->Revision)
  208. {
  209. case 0:
  210. AcpiOsPrintf (" **** Invalid Revision");
  211. break;
  212. case 1:
  213. /* Revision of DSDT controls the ACPI integer width */
  214. if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
  215. {
  216. AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
  217. }
  218. break;
  219. default:
  220. break;
  221. }
  222. /* Print and validate the table checksum */
  223. AcpiOsPrintf ("\n * Checksum 0x%2.2X", Table->Checksum);
  224. Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
  225. if (Checksum)
  226. {
  227. AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
  228. (UINT8) (Table->Checksum - Checksum));
  229. }
  230. AcpiOsPrintf ("\n");
  231. AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
  232. AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
  233. AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
  234. AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
  235. AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
  236. AcpiOsPrintf (" */\n");
  237. /*
  238. * Open the ASL definition block.
  239. *
  240. * Note: the AMLFilename string is left zero-length in order to just let
  241. * the compiler create it when the disassembled file is compiled. This
  242. * makes it easier to rename the disassembled ASL file if needed.
  243. */
  244. AcpiOsPrintf (
  245. "DefinitionBlock (\"\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
  246. Table->Signature, Table->Revision,
  247. Table->OemId, Table->OemTableId, Table->OemRevision);
  248. }
  249. /******************************************************************************
  250. *
  251. * FUNCTION: AdDisplayTables
  252. *
  253. * PARAMETERS: Filename - Input file for the table
  254. * Table - Pointer to the raw table
  255. *
  256. * RETURN: Status
  257. *
  258. * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
  259. *
  260. *****************************************************************************/
  261. ACPI_STATUS
  262. AdDisplayTables (
  263. char *Filename,
  264. ACPI_TABLE_HEADER *Table)
  265. {
  266. if (!AcpiGbl_ParseOpRoot)
  267. {
  268. return (AE_NOT_EXIST);
  269. }
  270. if (!AcpiGbl_DmOpt_Listing)
  271. {
  272. AdCreateTableHeader (Filename, Table);
  273. }
  274. AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
  275. MpEmitMappingInfo ();
  276. if (AcpiGbl_DmOpt_Listing)
  277. {
  278. AcpiOsPrintf ("\n\nTable Header:\n");
  279. AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
  280. DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
  281. AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
  282. AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
  283. Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
  284. }
  285. return (AE_OK);
  286. }
  287. /*******************************************************************************
  288. *
  289. * FUNCTION: AdStoreTable
  290. *
  291. * PARAMETERS: Table - Table header
  292. * TableIndex - Where the table index is returned
  293. *
  294. * RETURN: Status and table index.
  295. *
  296. * DESCRIPTION: Add an ACPI table to the global table list
  297. *
  298. ******************************************************************************/
  299. static ACPI_STATUS
  300. AdStoreTable (
  301. ACPI_TABLE_HEADER *Table,
  302. UINT32 *TableIndex)
  303. {
  304. ACPI_STATUS Status;
  305. ACPI_TABLE_DESC *TableDesc;
  306. Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
  307. if (ACPI_FAILURE (Status))
  308. {
  309. return (Status);
  310. }
  311. /* Initialize added table */
  312. AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
  313. ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
  314. Status = AcpiTbValidateTable (TableDesc);
  315. return (Status);
  316. }
  317. /******************************************************************************
  318. *
  319. * FUNCTION: AdGetLocalTables
  320. *
  321. * PARAMETERS: None
  322. *
  323. * RETURN: Status
  324. *
  325. * DESCRIPTION: Get the ACPI tables from either memory or a file
  326. *
  327. *****************************************************************************/
  328. ACPI_STATUS
  329. AdGetLocalTables (
  330. void)
  331. {
  332. ACPI_STATUS Status;
  333. ACPI_TABLE_HEADER TableHeader;
  334. ACPI_TABLE_HEADER *NewTable;
  335. UINT32 TableIndex;
  336. /* Get the DSDT via table override */
  337. ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
  338. AcpiOsTableOverride (&TableHeader, &NewTable);
  339. if (!NewTable)
  340. {
  341. fprintf (stderr, "Could not obtain DSDT\n");
  342. return (AE_NO_ACPI_TABLES);
  343. }
  344. AdWriteTable (NewTable, NewTable->Length,
  345. ACPI_SIG_DSDT, NewTable->OemTableId);
  346. /* Store DSDT in the Table Manager */
  347. Status = AdStoreTable (NewTable, &TableIndex);
  348. if (ACPI_FAILURE (Status))
  349. {
  350. fprintf (stderr, "Could not store DSDT\n");
  351. return (AE_NO_ACPI_TABLES);
  352. }
  353. return (AE_OK);
  354. }
  355. /******************************************************************************
  356. *
  357. * FUNCTION: AdParseTable
  358. *
  359. * PARAMETERS: Table - Pointer to the raw table
  360. * OwnerId - Returned OwnerId of the table
  361. * LoadTable - If add table to the global table list
  362. * External - If this is an external table
  363. *
  364. * RETURN: Status
  365. *
  366. * DESCRIPTION: Parse an ACPI AML table
  367. *
  368. *****************************************************************************/
  369. ACPI_STATUS
  370. AdParseTable (
  371. ACPI_TABLE_HEADER *Table,
  372. ACPI_OWNER_ID *OwnerId,
  373. BOOLEAN LoadTable,
  374. BOOLEAN External)
  375. {
  376. ACPI_STATUS Status = AE_OK;
  377. ACPI_WALK_STATE *WalkState;
  378. UINT8 *AmlStart;
  379. UINT32 AmlLength;
  380. UINT32 TableIndex;
  381. if (!Table)
  382. {
  383. return (AE_NOT_EXIST);
  384. }
  385. /* Pass 1: Parse everything except control method bodies */
  386. fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
  387. AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
  388. AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
  389. /* Create the root object */
  390. AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
  391. if (!AcpiGbl_ParseOpRoot)
  392. {
  393. return (AE_NO_MEMORY);
  394. }
  395. /* Create and initialize a new walk state */
  396. WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
  397. if (!WalkState)
  398. {
  399. return (AE_NO_MEMORY);
  400. }
  401. Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
  402. NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
  403. if (ACPI_FAILURE (Status))
  404. {
  405. return (Status);
  406. }
  407. WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
  408. WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
  409. Status = AcpiPsParseAml (WalkState);
  410. if (ACPI_FAILURE (Status))
  411. {
  412. return (Status);
  413. }
  414. /* If LoadTable is FALSE, we are parsing the last loaded table */
  415. TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
  416. /* Pass 2 */
  417. if (LoadTable)
  418. {
  419. Status = AdStoreTable (Table, &TableIndex);
  420. if (ACPI_FAILURE (Status))
  421. {
  422. return (Status);
  423. }
  424. Status = AcpiTbAllocateOwnerId (TableIndex);
  425. if (ACPI_FAILURE (Status))
  426. {
  427. return (Status);
  428. }
  429. if (OwnerId)
  430. {
  431. Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
  432. if (ACPI_FAILURE (Status))
  433. {
  434. return (Status);
  435. }
  436. }
  437. }
  438. fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
  439. Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
  440. if (ACPI_FAILURE (Status))
  441. {
  442. return (Status);
  443. }
  444. /* No need to parse control methods of external table */
  445. if (External)
  446. {
  447. return (AE_OK);
  448. }
  449. /*
  450. * Pass 3: Parse control methods and link their parse trees
  451. * into the main parse tree
  452. */
  453. fprintf (stderr,
  454. "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
  455. Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
  456. fprintf (stderr, "\n");
  457. /* Process Resource Templates */
  458. AcpiDmFindResources (AcpiGbl_ParseOpRoot);
  459. fprintf (stderr, "Parsing completed\n");
  460. return (AE_OK);
  461. }