1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "aslcompiler.h"
154 #include "acdisasm.h"
155 #include "acdispat.h"
156 #include "acnamesp.h"
157 #include "acparser.h"
161 #define _COMPONENT ACPI_TOOLS
162 ACPI_MODULE_NAME ("adisasm")
164 /* Local prototypes */
167 AdDoExternalFileList (
171 AdDisassembleOneTable (
172 ACPI_TABLE_HEADER
*Table
,
175 char *DisasmFilename
);
179 ACPI_TABLE_HEADER
*Table
,
181 ACPI_OWNER_ID OwnerId
);
184 ACPI_TABLE_DESC LocalTables
[1];
185 ACPI_PARSE_OBJECT
*AcpiGbl_ParseOpRoot
;
188 /* Stubs for everything except ASL compiler */
190 #ifndef ACPI_ASL_COMPILER
193 ACPI_PARSE_OBJECT
*Op
,
194 ACPI_WALK_STATE
*WalkState
)
202 ACPI_WALK_STATE
*WalkState
)
209 /*******************************************************************************
211 * FUNCTION: AdInitialize
217 * DESCRIPTION: ACPICA and local initialization
219 ******************************************************************************/
228 /* ACPICA subsystem initialization */
230 Status
= AcpiOsInitialize ();
231 if (ACPI_FAILURE (Status
))
233 fprintf (stderr
, "Could not initialize ACPICA subsystem: %s\n",
234 AcpiFormatException (Status
));
239 Status
= AcpiUtInitGlobals ();
240 if (ACPI_FAILURE (Status
))
242 fprintf (stderr
, "Could not initialize ACPICA globals: %s\n",
243 AcpiFormatException (Status
));
248 Status
= AcpiUtMutexInitialize ();
249 if (ACPI_FAILURE (Status
))
251 fprintf (stderr
, "Could not initialize ACPICA mutex objects: %s\n",
252 AcpiFormatException (Status
));
257 Status
= AcpiNsRootInitialize ();
258 if (ACPI_FAILURE (Status
))
260 fprintf (stderr
, "Could not initialize ACPICA namespace: %s\n",
261 AcpiFormatException (Status
));
266 /* Setup the Table Manager (cheat - there is no RSDT) */
268 AcpiGbl_RootTableList
.MaxTableCount
= 1;
269 AcpiGbl_RootTableList
.CurrentTableCount
= 0;
270 AcpiGbl_RootTableList
.Tables
= LocalTables
;
276 /******************************************************************************
278 * FUNCTION: AdAmlDisassemble
280 * PARAMETERS: Filename - AML input filename
281 * OutToFile - TRUE if output should go to a file
282 * Prefix - Path prefix for output
283 * OutFilename - where the filename is returned
287 * DESCRIPTION: Disassembler entry point. Disassemble an entire ACPI table.
289 *****************************************************************************/
299 char *DisasmFilename
= NULL
;
301 ACPI_TABLE_HEADER
*Table
= NULL
;
302 ACPI_NEW_TABLE_DESC
*ListHead
= NULL
;
306 * Input: AML code from either a file or via GetTables (memory or
311 /* Get the list of all AML tables in the file */
313 Status
= AcGetAllTablesFromFile (Filename
,
314 ACPI_GET_ALL_TABLES
, &ListHead
);
315 if (ACPI_FAILURE (Status
))
317 AcpiOsPrintf ("Could not get ACPI tables from %s, %s\n",
318 Filename
, AcpiFormatException (Status
));
322 /* Process any user-specified files for external objects */
324 Status
= AdDoExternalFileList (Filename
);
325 if (ACPI_FAILURE (Status
))
332 Status
= AdGetLocalTables ();
333 if (ACPI_FAILURE (Status
))
335 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
336 AcpiFormatException (Status
));
340 if (!AcpiGbl_DmOpt_Disasm
)
345 /* Obtained the local tables, just disassemble the DSDT */
347 Status
= AcpiGetTable (ACPI_SIG_DSDT
, 0, &Table
);
348 if (ACPI_FAILURE (Status
))
350 AcpiOsPrintf ("Could not get DSDT, %s\n",
351 AcpiFormatException (Status
));
355 AcpiOsPrintf ("\nDisassembly of DSDT\n");
356 Prefix
= AdGenerateFilename ("dsdt", Table
->OemTableId
);
360 * Output: ASL code. Redirect to a file if requested
364 /* Create/Open a disassembly output file */
366 DisasmFilename
= FlGenerateFilename (Prefix
, FILE_SUFFIX_DISASSEMBLY
);
369 fprintf (stderr
, "Could not generate output filename\n");
374 File
= fopen (DisasmFilename
, "w+");
377 fprintf (stderr
, "Could not open output file %s\n",
383 AcpiOsRedirectOutput (File
);
386 *OutFilename
= DisasmFilename
;
388 /* Disassemble all AML tables within the file */
392 Status
= AdDisassembleOneTable (ListHead
->Table
,
393 File
, Filename
, DisasmFilename
);
394 if (ACPI_FAILURE (Status
))
399 ListHead
= ListHead
->Next
;
405 !AcpiGbl_ForceAmlDisassembly
&&
406 !AcpiUtIsAmlTable (Table
))
411 AcDeleteTableList (ListHead
);
416 AcpiOsRedirectOutput (stdout
);
419 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot
);
420 AcpiGbl_ParseOpRoot
= NULL
;
425 /******************************************************************************
427 * FUNCTION: AdDisassembleOneTable
429 * PARAMETERS: Table - Raw AML table
430 * File - Pointer for the input file
431 * Filename - AML input filename
432 * DisasmFilename - Output filename
436 * DESCRIPTION: Disassemble a single ACPI table. AML or data table.
438 *****************************************************************************/
441 AdDisassembleOneTable (
442 ACPI_TABLE_HEADER
*Table
,
445 char *DisasmFilename
)
448 ACPI_OWNER_ID OwnerId
;
451 #ifdef ACPI_ASL_COMPILER
454 * For ASL-/ASL+ converter: replace the temporary "XXXX"
455 * table signature with the original. This "XXXX" makes
456 * it harder for the AML interpreter to run the badaml
457 * (.xxx) file produced from the converter in case if
458 * it fails to get deleted.
460 if (AcpiGbl_CaptureComments
)
462 strncpy (Table
->Signature
, AcpiGbl_TableSig
, ACPI_NAME_SIZE
);
466 /* ForceAmlDisassembly means to assume the table contains valid AML */
468 if (!AcpiGbl_ForceAmlDisassembly
&& !AcpiUtIsAmlTable (Table
))
470 AdDisassemblerHeader (Filename
, ACPI_IS_DATA_TABLE
);
472 /* This is a "Data Table" (non-AML table) */
474 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
476 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] "
477 "FieldName : FieldValue\n */\n\n");
479 AcpiDmDumpDataTable (Table
);
480 fprintf (stderr
, "Acpi Data Table [%4.4s] decoded\n",
485 fprintf (stderr
, "Formatted output: %s - %u bytes\n",
486 DisasmFilename
, CmGetFileSize (File
));
493 * This is an AML table (DSDT or SSDT).
494 * Always parse the tables, only option is what to display
496 Status
= AdParseTable (Table
, &OwnerId
, TRUE
, FALSE
);
497 if (ACPI_FAILURE (Status
))
499 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
500 AcpiFormatException (Status
));
504 /* Debug output, namespace and parse tree */
506 if (AslCompilerdebug
&& File
)
508 AcpiOsPrintf ("/**** Before second load\n");
510 NsSetupNamespaceListing (File
);
511 NsDisplayNamespace ();
513 AcpiOsPrintf ("*****/\n");
516 /* Load namespace from names created within control methods */
518 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot
,
519 AcpiGbl_RootNode
, OwnerId
);
522 * Cross reference the namespace here, in order to
523 * generate External() statements
525 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot
,
526 AcpiGbl_RootNode
, OwnerId
);
528 if (AslCompilerdebug
)
530 AcpiDmDumpTree (AcpiGbl_ParseOpRoot
);
533 /* Find possible calls to external control methods */
535 AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot
);
538 * If we found any external control methods, we must reparse
539 * the entire tree with the new information (namely, the
540 * number of arguments per method)
542 if (AcpiDmGetUnresolvedExternalMethodCount ())
544 Status
= AdReparseOneTable (Table
, File
, OwnerId
);
545 if (ACPI_FAILURE (Status
))
552 * Now that the namespace is finalized, we can perform namespace
555 * 1) Convert fixed-offset references to resource descriptors
556 * to symbolic references (Note: modifies namespace)
558 AcpiDmConvertParseObjects (AcpiGbl_ParseOpRoot
, AcpiGbl_RootNode
);
560 /* Optional displays */
562 if (AcpiGbl_DmOpt_Disasm
)
564 /* This is the real disassembly */
566 AdDisplayTables (Filename
, Table
);
568 /* Dump hex table if requested (-vt) */
570 AcpiDmDumpDataTable (Table
);
572 fprintf (stderr
, "Disassembly completed\n");
575 fprintf (stderr
, "ASL Output: %s - %u bytes\n",
576 DisasmFilename
, CmGetFileSize (File
));
579 if (AslGbl_MapfileFlag
)
581 fprintf (stderr
, "%14s %s - %u bytes\n",
582 AslGbl_Files
[ASL_FILE_MAP_OUTPUT
].ShortDescription
,
583 AslGbl_Files
[ASL_FILE_MAP_OUTPUT
].Filename
,
584 FlGetFileSize (ASL_FILE_MAP_OUTPUT
));
592 /******************************************************************************
594 * FUNCTION: AdReparseOneTable
596 * PARAMETERS: Table - Raw AML table
597 * File - Pointer for the input file
598 * OwnerId - ID for this table
602 * DESCRIPTION: Reparse a table that has already been loaded. Used to
603 * integrate information about external control methods.
604 * These methods may have been previously parsed incorrectly.
606 *****************************************************************************/
610 ACPI_TABLE_HEADER
*Table
,
612 ACPI_OWNER_ID OwnerId
)
615 ACPI_COMMENT_ADDR_NODE
*AddrListHead
;
619 "\nFound %u external control methods, "
620 "reparsing with new information\n",
621 AcpiDmGetUnresolvedExternalMethodCount ());
623 /* Reparse, rebuild namespace */
625 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot
);
626 AcpiGbl_ParseOpRoot
= NULL
;
627 AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode
);
629 AcpiGbl_RootNode
= NULL
;
630 AcpiGbl_RootNodeStruct
.Name
.Integer
= ACPI_ROOT_NAME
;
631 AcpiGbl_RootNodeStruct
.DescriptorType
= ACPI_DESC_TYPE_NAMED
;
632 AcpiGbl_RootNodeStruct
.Type
= ACPI_TYPE_DEVICE
;
633 AcpiGbl_RootNodeStruct
.Parent
= NULL
;
634 AcpiGbl_RootNodeStruct
.Child
= NULL
;
635 AcpiGbl_RootNodeStruct
.Peer
= NULL
;
636 AcpiGbl_RootNodeStruct
.Object
= NULL
;
637 AcpiGbl_RootNodeStruct
.Flags
= 0;
639 Status
= AcpiNsRootInitialize ();
640 if (ACPI_FAILURE (Status
))
645 /* New namespace, add the external definitions first */
647 AcpiDmAddExternalListToNamespace ();
649 /* For -ca option: clear the list of comment addresses. */
651 while (AcpiGbl_CommentAddrListHead
)
653 AddrListHead
= AcpiGbl_CommentAddrListHead
;
654 AcpiGbl_CommentAddrListHead
= AcpiGbl_CommentAddrListHead
->Next
;
655 AcpiOsFree(AddrListHead
);
658 /* Parse the table again. No need to reload it, however */
660 Status
= AdParseTable (Table
, NULL
, FALSE
, FALSE
);
661 if (ACPI_FAILURE (Status
))
663 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
664 AcpiFormatException (Status
));
668 /* Cross reference the namespace again */
670 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot
,
671 AcpiGbl_RootNode
, OwnerId
);
673 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot
,
674 AcpiGbl_RootNode
, OwnerId
);
676 /* Debug output - namespace and parse tree */
678 if (AslCompilerdebug
)
680 AcpiOsPrintf ("/**** After second load and resource conversion\n");
683 NsSetupNamespaceListing (File
);
684 NsDisplayNamespace ();
687 AcpiOsPrintf ("*****/\n");
688 AcpiDmDumpTree (AcpiGbl_ParseOpRoot
);
695 /******************************************************************************
697 * FUNCTION: AdDoExternalFileList
699 * PARAMETERS: Filename - Input file for the table
703 * DESCRIPTION: Process all tables found in the -e external files list
705 *****************************************************************************/
708 AdDoExternalFileList (
711 ACPI_EXTERNAL_FILE
*ExternalFileList
;
712 char *ExternalFilename
;
713 ACPI_NEW_TABLE_DESC
*ExternalListHead
= NULL
;
715 ACPI_STATUS GlobalStatus
= AE_OK
;
716 ACPI_OWNER_ID OwnerId
;
720 * External filenames are specified on the command line like this:
721 * Example: iasl -e file1,file2,file3 -d xxx.aml
723 ExternalFileList
= AcpiGbl_ExternalFileList
;
725 /* Process each external file */
727 while (ExternalFileList
)
729 ExternalFilename
= ExternalFileList
->Path
;
730 if (!strcmp (ExternalFilename
, Filename
))
732 /* Next external file */
734 ExternalFileList
= ExternalFileList
->Next
;
738 AcpiOsPrintf ("External object resolution file %16s\n",
741 Status
= AcGetAllTablesFromFile (
742 ExternalFilename
, ACPI_GET_ONLY_AML_TABLES
, &ExternalListHead
);
743 if (ACPI_FAILURE (Status
))
745 if (Status
== AE_TYPE
)
747 ExternalFileList
= ExternalFileList
->Next
;
748 GlobalStatus
= AE_TYPE
;
753 AcDeleteTableList (ExternalListHead
);
757 /* Load external tables for symbol resolution */
759 while (ExternalListHead
)
761 Status
= AdParseTable (
762 ExternalListHead
->Table
, &OwnerId
, TRUE
, TRUE
);
763 if (ACPI_FAILURE (Status
))
765 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
766 AcpiFormatException (Status
));
767 AcDeleteTableList (ExternalListHead
);
772 * Load namespace from names created within control methods
773 * Set owner id of nodes in external table
775 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot
,
776 AcpiGbl_RootNode
, OwnerId
);
777 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot
);
779 ExternalListHead
= ExternalListHead
->Next
;
782 /* Next external file */
784 ExternalFileList
= ExternalFileList
->Next
;
787 AcDeleteTableList (ExternalListHead
);
789 if (ACPI_FAILURE (GlobalStatus
))
791 return (GlobalStatus
);
794 /* Clear external list generated by Scope in external tables */
796 if (AcpiGbl_ExternalFileList
)
798 AcpiDmClearExternalList ();
801 /* Load any externals defined in the optional external ref file */
803 AcpiDmGetExternalsFromFile ();