1 /******************************************************************************
3 * Module Name: dmtables - disassembler ACPI table support
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include <contrib/dev/acpica/include/acapps.h>
46 #include <contrib/dev/acpica/include/acdispat.h>
47 #include <contrib/dev/acpica/include/acnamesp.h>
48 #include <contrib/dev/acpica/include/actables.h>
49 #include <contrib/dev/acpica/include/acparser.h>
54 #define _COMPONENT ACPI_TOOLS
55 ACPI_MODULE_NAME ("dmtables")
58 /* Local prototypes */
63 ACPI_TABLE_HEADER *Table);
67 ACPI_TABLE_HEADER *Table,
71 extern ACPI_TABLE_DESC LocalTables[1];
72 extern ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
75 /******************************************************************************
77 * FUNCTION: AdDisassemblerHeader
79 * PARAMETERS: Filename - Input file for the table
80 * TableType - Either AML or DataTable
84 * DESCRIPTION: Create the disassembler header, including ACPICA signon with
85 * current time and date.
87 *****************************************************************************/
90 AdDisassemblerHeader (
99 /* Header and input table info */
101 AcpiOsPrintf ("/*\n");
102 AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
104 if (TableType == ACPI_IS_AML_TABLE)
106 if (AcpiGbl_CstyleDisassembly)
109 " * Disassembling to symbolic ASL+ operators\n"
115 " * Disassembling to non-symbolic legacy ASL operators\n"
120 AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
121 AcpiOsPrintf (" *\n");
125 /******************************************************************************
127 * FUNCTION: AdCreateTableHeader
129 * PARAMETERS: Filename - Input file for the table
130 * Table - Pointer to the raw table
134 * DESCRIPTION: Create the ASL table header, including ACPICA signon with
135 * current time and date.
137 *****************************************************************************/
140 AdCreateTableHeader (
142 ACPI_TABLE_HEADER *Table)
147 /* Reset globals for External statements */
149 AcpiGbl_NumExternalMethods = 0;
150 AcpiGbl_ResolvedExternalMethods = 0;
153 * Print file header and dump original table header
155 AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
157 AcpiOsPrintf (" * Original Table Header:\n");
158 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
159 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
161 /* Print and validate the revision */
163 AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
165 switch (Table->Revision)
169 AcpiOsPrintf (" **** Invalid Revision");
174 /* Revision of DSDT controls the ACPI integer width */
176 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
178 AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
187 /* Print and validate the table checksum */
189 AcpiOsPrintf ("\n * Checksum 0x%2.2X", Table->Checksum);
191 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
194 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
195 (UINT8) (Table->Checksum - Checksum));
199 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
200 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
201 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
202 AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
203 AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
204 AcpiOsPrintf (" */\n");
207 * Open the ASL definition block.
209 * Note: the AMLFilename string is left zero-length in order to just let
210 * the compiler create it when the disassembled file is compiled. This
211 * makes it easier to rename the disassembled ASL file if needed.
214 "DefinitionBlock (\"\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
215 Table->Signature, Table->Revision,
216 Table->OemId, Table->OemTableId, Table->OemRevision);
220 /******************************************************************************
222 * FUNCTION: AdDisplayTables
224 * PARAMETERS: Filename - Input file for the table
225 * Table - Pointer to the raw table
229 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
231 *****************************************************************************/
236 ACPI_TABLE_HEADER *Table)
240 if (!AcpiGbl_ParseOpRoot)
242 return (AE_NOT_EXIST);
245 if (!AcpiGbl_DmOpt_Listing)
247 AdCreateTableHeader (Filename, Table);
250 AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
251 MpEmitMappingInfo ();
253 if (AcpiGbl_DmOpt_Listing)
255 AcpiOsPrintf ("\n\nTable Header:\n");
256 AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
257 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
259 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
260 AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
261 Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
268 /*******************************************************************************
270 * FUNCTION: AdStoreTable
272 * PARAMETERS: Table - Table header
273 * TableIndex - Where the table index is returned
275 * RETURN: Status and table index.
277 * DESCRIPTION: Add an ACPI table to the global table list
279 ******************************************************************************/
283 ACPI_TABLE_HEADER *Table,
287 ACPI_TABLE_DESC *TableDesc;
290 Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
291 if (ACPI_FAILURE (Status))
296 /* Initialize added table */
298 AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
299 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
300 Status = AcpiTbValidateTable (TableDesc);
305 /******************************************************************************
307 * FUNCTION: AdGetLocalTables
313 * DESCRIPTION: Get the ACPI tables from either memory or a file
315 *****************************************************************************/
322 ACPI_TABLE_HEADER TableHeader;
323 ACPI_TABLE_HEADER *NewTable;
327 /* Get the DSDT via table override */
329 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
330 AcpiOsTableOverride (&TableHeader, &NewTable);
333 fprintf (stderr, "Could not obtain DSDT\n");
334 return (AE_NO_ACPI_TABLES);
337 AdWriteTable (NewTable, NewTable->Length,
338 ACPI_SIG_DSDT, NewTable->OemTableId);
340 /* Store DSDT in the Table Manager */
342 Status = AdStoreTable (NewTable, &TableIndex);
343 if (ACPI_FAILURE (Status))
345 fprintf (stderr, "Could not store DSDT\n");
346 return (AE_NO_ACPI_TABLES);
353 /******************************************************************************
355 * FUNCTION: AdParseTable
357 * PARAMETERS: Table - Pointer to the raw table
358 * OwnerId - Returned OwnerId of the table
359 * LoadTable - If add table to the global table list
360 * External - If this is an external table
364 * DESCRIPTION: Parse an ACPI AML table
366 *****************************************************************************/
370 ACPI_TABLE_HEADER *Table,
371 ACPI_OWNER_ID *OwnerId,
375 ACPI_STATUS Status = AE_OK;
376 ACPI_WALK_STATE *WalkState;
384 return (AE_NOT_EXIST);
387 /* Pass 1: Parse everything except control method bodies */
389 fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
391 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
392 AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
394 /* Create the root object */
396 AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
397 if (!AcpiGbl_ParseOpRoot)
399 return (AE_NO_MEMORY);
402 /* Create and initialize a new walk state */
404 WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
407 return (AE_NO_MEMORY);
410 Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
411 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
412 if (ACPI_FAILURE (Status))
417 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
418 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
420 Status = AcpiPsParseAml (WalkState);
421 if (ACPI_FAILURE (Status))
426 /* If LoadTable is FALSE, we are parsing the last loaded table */
428 TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
434 Status = AdStoreTable (Table, &TableIndex);
435 if (ACPI_FAILURE (Status))
439 Status = AcpiTbAllocateOwnerId (TableIndex);
440 if (ACPI_FAILURE (Status))
446 Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
447 if (ACPI_FAILURE (Status))
454 fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
456 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
457 if (ACPI_FAILURE (Status))
462 /* No need to parse control methods of external table */
470 * Pass 3: Parse control methods and link their parse trees
471 * into the main parse tree
474 "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
476 Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
477 fprintf (stderr, "\n");
479 /* Process Resource Templates */
481 AcpiDmFindResources (AcpiGbl_ParseOpRoot);
483 fprintf (stderr, "Parsing completed\n");