1 /******************************************************************************
3 * Module Name: dmtables - disassembler ACPI table support
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2017, 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/acdispat.h>
46 #include <contrib/dev/acpica/include/acnamesp.h>
47 #include <contrib/dev/acpica/include/actables.h>
48 #include <contrib/dev/acpica/include/acparser.h>
49 #include <contrib/dev/acpica/include/acapps.h>
52 #define _COMPONENT ACPI_TOOLS
53 ACPI_MODULE_NAME ("dmtables")
56 /* Local prototypes */
61 ACPI_TABLE_HEADER *Table);
65 ACPI_TABLE_HEADER *Table,
69 extern ACPI_TABLE_DESC LocalTables[1];
70 extern ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
73 /******************************************************************************
75 * FUNCTION: AdDisassemblerHeader
77 * PARAMETERS: Filename - Input file for the table
78 * TableType - Either AML or DataTable
82 * DESCRIPTION: Create the disassembler header, including ACPICA signon with
83 * current time and date.
85 *****************************************************************************/
88 AdDisassemblerHeader (
97 /* Header and input table info */
99 AcpiOsPrintf ("/*\n");
100 AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
102 if (TableType == ACPI_IS_AML_TABLE)
104 if (AcpiGbl_CstyleDisassembly)
107 " * Disassembling to symbolic ASL+ operators\n"
113 " * Disassembling to non-symbolic legacy ASL operators\n"
118 AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
119 AcpiOsPrintf (" *\n");
123 /******************************************************************************
125 * FUNCTION: AdCreateTableHeader
127 * PARAMETERS: Filename - Input file for the table
128 * Table - Pointer to the raw table
132 * DESCRIPTION: Create the ASL table header, including ACPICA signon with
133 * current time and date.
135 *****************************************************************************/
138 AdCreateTableHeader (
140 ACPI_TABLE_HEADER *Table)
145 /* Reset globals for External statements */
147 AcpiGbl_NumExternalMethods = 0;
148 AcpiGbl_ResolvedExternalMethods = 0;
151 * Print file header and dump original table header
153 AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
155 AcpiOsPrintf (" * Original Table Header:\n");
156 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
157 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
159 /* Print and validate the revision */
161 AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
163 switch (Table->Revision)
167 AcpiOsPrintf (" **** Invalid Revision");
172 /* Revision of DSDT controls the ACPI integer width */
174 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
176 AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
185 /* Print and validate the table checksum */
187 AcpiOsPrintf ("\n * Checksum 0x%2.2X", Table->Checksum);
189 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
192 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
193 (UINT8) (Table->Checksum - Checksum));
197 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
198 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
199 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
200 AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
201 AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
202 AcpiOsPrintf (" */\n");
205 * Open the ASL definition block.
207 * Note: the AMLFilename string is left zero-length in order to just let
208 * the compiler create it when the disassembled file is compiled. This
209 * makes it easier to rename the disassembled ASL file if needed.
212 "DefinitionBlock (\"\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
213 Table->Signature, Table->Revision,
214 Table->OemId, Table->OemTableId, Table->OemRevision);
218 /******************************************************************************
220 * FUNCTION: AdDisplayTables
222 * PARAMETERS: Filename - Input file for the table
223 * Table - Pointer to the raw table
227 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
229 *****************************************************************************/
234 ACPI_TABLE_HEADER *Table)
238 if (!AcpiGbl_ParseOpRoot)
240 return (AE_NOT_EXIST);
243 if (!AcpiGbl_DmOpt_Listing)
245 AdCreateTableHeader (Filename, Table);
248 AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
249 MpEmitMappingInfo ();
251 if (AcpiGbl_DmOpt_Listing)
253 AcpiOsPrintf ("\n\nTable Header:\n");
254 AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
255 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
257 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
258 AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
259 Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
266 /*******************************************************************************
268 * FUNCTION: AdStoreTable
270 * PARAMETERS: Table - Table header
271 * TableIndex - Where the table index is returned
273 * RETURN: Status and table index.
275 * DESCRIPTION: Add an ACPI table to the global table list
277 ******************************************************************************/
281 ACPI_TABLE_HEADER *Table,
285 ACPI_TABLE_DESC *TableDesc;
288 Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
289 if (ACPI_FAILURE (Status))
294 /* Initialize added table */
296 AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
297 ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
298 Status = AcpiTbValidateTable (TableDesc);
303 /******************************************************************************
305 * FUNCTION: AdGetLocalTables
311 * DESCRIPTION: Get the ACPI tables from either memory or a file
313 *****************************************************************************/
320 ACPI_TABLE_HEADER TableHeader;
321 ACPI_TABLE_HEADER *NewTable;
325 /* Get the DSDT via table override */
327 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
328 AcpiOsTableOverride (&TableHeader, &NewTable);
331 fprintf (stderr, "Could not obtain DSDT\n");
332 return (AE_NO_ACPI_TABLES);
335 AdWriteTable (NewTable, NewTable->Length,
336 ACPI_SIG_DSDT, NewTable->OemTableId);
338 /* Store DSDT in the Table Manager */
340 Status = AdStoreTable (NewTable, &TableIndex);
341 if (ACPI_FAILURE (Status))
343 fprintf (stderr, "Could not store DSDT\n");
344 return (AE_NO_ACPI_TABLES);
351 /******************************************************************************
353 * FUNCTION: AdParseTable
355 * PARAMETERS: Table - Pointer to the raw table
356 * OwnerId - Returned OwnerId of the table
357 * LoadTable - If add table to the global table list
358 * External - If this is an external table
362 * DESCRIPTION: Parse an ACPI AML table
364 *****************************************************************************/
368 ACPI_TABLE_HEADER *Table,
369 ACPI_OWNER_ID *OwnerId,
373 ACPI_STATUS Status = AE_OK;
374 ACPI_WALK_STATE *WalkState;
382 return (AE_NOT_EXIST);
385 /* Pass 1: Parse everything except control method bodies */
387 fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
389 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
390 AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
392 /* Create the root object */
394 AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
395 if (!AcpiGbl_ParseOpRoot)
397 return (AE_NO_MEMORY);
400 /* Create and initialize a new walk state */
402 WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
405 return (AE_NO_MEMORY);
408 Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
409 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
410 if (ACPI_FAILURE (Status))
415 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
416 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
418 Status = AcpiPsParseAml (WalkState);
419 if (ACPI_FAILURE (Status))
424 /* If LoadTable is FALSE, we are parsing the last loaded table */
426 TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
432 Status = AdStoreTable (Table, &TableIndex);
433 if (ACPI_FAILURE (Status))
437 Status = AcpiTbAllocateOwnerId (TableIndex);
438 if (ACPI_FAILURE (Status))
444 Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
445 if (ACPI_FAILURE (Status))
452 fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
454 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
455 if (ACPI_FAILURE (Status))
460 /* No need to parse control methods of external table */
468 * Pass 3: Parse control methods and link their parse trees
469 * into the main parse tree
472 "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
474 Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
475 fprintf (stderr, "\n");
477 /* Process Resource Templates */
479 AcpiDmFindResources (AcpiGbl_ParseOpRoot);
481 fprintf (stderr, "Parsing completed\n");