159db4265SNate Lawson /****************************************************************************** 259db4265SNate Lawson * 359db4265SNate Lawson * Module Name: adisasm - Application-level disassembler routines 459db4265SNate Lawson * 559db4265SNate Lawson *****************************************************************************/ 659db4265SNate Lawson 7d244b227SJung-uk Kim /* 8*f8146b88SJung-uk Kim * Copyright (C) 2000 - 2016, Intel Corp. 959db4265SNate Lawson * All rights reserved. 1059db4265SNate Lawson * 11d244b227SJung-uk Kim * Redistribution and use in source and binary forms, with or without 12d244b227SJung-uk Kim * modification, are permitted provided that the following conditions 13d244b227SJung-uk Kim * are met: 14d244b227SJung-uk Kim * 1. Redistributions of source code must retain the above copyright 15d244b227SJung-uk Kim * notice, this list of conditions, and the following disclaimer, 16d244b227SJung-uk Kim * without modification. 17d244b227SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18d244b227SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below 19d244b227SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon 20d244b227SJung-uk Kim * including a substantially similar Disclaimer requirement for further 21d244b227SJung-uk Kim * binary redistribution. 22d244b227SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names 23d244b227SJung-uk Kim * of any contributors may be used to endorse or promote products derived 24d244b227SJung-uk Kim * from this software without specific prior written permission. 2559db4265SNate Lawson * 26d244b227SJung-uk Kim * Alternatively, this software may be distributed under the terms of the 27d244b227SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free 28d244b227SJung-uk Kim * Software Foundation. 2959db4265SNate Lawson * 30d244b227SJung-uk Kim * NO WARRANTY 31d244b227SJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32d244b227SJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33d244b227SJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34d244b227SJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35d244b227SJung-uk Kim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36d244b227SJung-uk Kim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37d244b227SJung-uk Kim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38d244b227SJung-uk Kim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39d244b227SJung-uk Kim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40d244b227SJung-uk Kim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41d244b227SJung-uk Kim * POSSIBILITY OF SUCH DAMAGES. 42d244b227SJung-uk Kim */ 4359db4265SNate Lawson 44313a0c13SJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h> 45ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h> 46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h> 47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h> 48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h> 49*f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h> 50ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h> 5159db4265SNate Lawson 5259db4265SNate Lawson #include <stdio.h> 5359db4265SNate Lawson 5459db4265SNate Lawson 5559db4265SNate Lawson #define _COMPONENT ACPI_TOOLS 5659db4265SNate Lawson ACPI_MODULE_NAME ("adisasm") 5759db4265SNate Lawson 581a39cfb0SJung-uk Kim /* Local prototypes */ 591a39cfb0SJung-uk Kim 60*f8146b88SJung-uk Kim static ACPI_STATUS 61*f8146b88SJung-uk Kim AdDoExternalFileList ( 62*f8146b88SJung-uk Kim char *Filename); 631a39cfb0SJung-uk Kim 647cf3e94aSJung-uk Kim static ACPI_STATUS 65*f8146b88SJung-uk Kim AdDisassembleOneTable ( 667cf3e94aSJung-uk Kim ACPI_TABLE_HEADER *Table, 67*f8146b88SJung-uk Kim FILE *File, 68*f8146b88SJung-uk Kim char *Filename, 69*f8146b88SJung-uk Kim char *DisasmFilename); 707cf3e94aSJung-uk Kim 71*f8146b88SJung-uk Kim static ACPI_STATUS 72*f8146b88SJung-uk Kim AdReparseOneTable ( 73*f8146b88SJung-uk Kim ACPI_TABLE_HEADER *Table, 74*f8146b88SJung-uk Kim FILE *File, 75*f8146b88SJung-uk Kim ACPI_OWNER_ID OwnerId); 76*f8146b88SJung-uk Kim 77*f8146b88SJung-uk Kim 78*f8146b88SJung-uk Kim ACPI_TABLE_DESC LocalTables[1]; 79*f8146b88SJung-uk Kim ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot; 80*f8146b88SJung-uk Kim 81*f8146b88SJung-uk Kim 82*f8146b88SJung-uk Kim /* Stubs for everything except ASL compiler */ 8359db4265SNate Lawson 84fba7fc7eSJung-uk Kim #ifndef ACPI_ASL_COMPILER 8559db4265SNate Lawson BOOLEAN 8659db4265SNate Lawson AcpiDsIsResultUsed ( 8759db4265SNate Lawson ACPI_PARSE_OBJECT *Op, 8859db4265SNate Lawson ACPI_WALK_STATE *WalkState) 8959db4265SNate Lawson { 90*f8146b88SJung-uk Kim return (TRUE); 9159db4265SNate Lawson } 921a39cfb0SJung-uk Kim 931a39cfb0SJung-uk Kim ACPI_STATUS 941a39cfb0SJung-uk Kim AcpiDsMethodError ( 951a39cfb0SJung-uk Kim ACPI_STATUS Status, 961a39cfb0SJung-uk Kim ACPI_WALK_STATE *WalkState) 971a39cfb0SJung-uk Kim { 981a39cfb0SJung-uk Kim return (Status); 991a39cfb0SJung-uk Kim } 10059db4265SNate Lawson #endif 10159db4265SNate Lawson 1024c52cad2SJung-uk Kim 1034c52cad2SJung-uk Kim /******************************************************************************* 1044c52cad2SJung-uk Kim * 10559db4265SNate Lawson * FUNCTION: AdInitialize 10659db4265SNate Lawson * 107f556842eSJung-uk Kim * PARAMETERS: None 10859db4265SNate Lawson * 10959db4265SNate Lawson * RETURN: Status 11059db4265SNate Lawson * 111f556842eSJung-uk Kim * DESCRIPTION: ACPICA and local initialization 11259db4265SNate Lawson * 11359db4265SNate Lawson ******************************************************************************/ 11459db4265SNate Lawson 11559db4265SNate Lawson ACPI_STATUS 11659db4265SNate Lawson AdInitialize ( 11759db4265SNate Lawson void) 11859db4265SNate Lawson { 11959db4265SNate Lawson ACPI_STATUS Status; 12059db4265SNate Lawson 12159db4265SNate Lawson 12259db4265SNate Lawson /* ACPICA subsystem initialization */ 12359db4265SNate Lawson 1241a39cfb0SJung-uk Kim Status = AcpiOsInitialize (); 125a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 126a9f12690SJung-uk Kim { 127a9f12690SJung-uk Kim return (Status); 128a9f12690SJung-uk Kim } 129a9f12690SJung-uk Kim 130a9f12690SJung-uk Kim Status = AcpiUtInitGlobals (); 131a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 132a9f12690SJung-uk Kim { 133a9f12690SJung-uk Kim return (Status); 134a9f12690SJung-uk Kim } 1351a39cfb0SJung-uk Kim 13659db4265SNate Lawson Status = AcpiUtMutexInitialize (); 13759db4265SNate Lawson if (ACPI_FAILURE (Status)) 13859db4265SNate Lawson { 139a9f12690SJung-uk Kim return (Status); 14059db4265SNate Lawson } 14159db4265SNate Lawson 14259db4265SNate Lawson Status = AcpiNsRootInitialize (); 1431a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 1441a39cfb0SJung-uk Kim { 145a9f12690SJung-uk Kim return (Status); 1461a39cfb0SJung-uk Kim } 1471a39cfb0SJung-uk Kim 1481a39cfb0SJung-uk Kim /* Setup the Table Manager (cheat - there is no RSDT) */ 1491a39cfb0SJung-uk Kim 1503f5e024cSJung-uk Kim AcpiGbl_RootTableList.MaxTableCount = 1; 1513f5e024cSJung-uk Kim AcpiGbl_RootTableList.CurrentTableCount = 0; 1521a39cfb0SJung-uk Kim AcpiGbl_RootTableList.Tables = LocalTables; 1531a39cfb0SJung-uk Kim 154a9f12690SJung-uk Kim return (Status); 15559db4265SNate Lawson } 15659db4265SNate Lawson 15759db4265SNate Lawson 15859db4265SNate Lawson /****************************************************************************** 15959db4265SNate Lawson * 16059db4265SNate Lawson * FUNCTION: AdAmlDisassemble 16159db4265SNate Lawson * 162fba7fc7eSJung-uk Kim * PARAMETERS: Filename - AML input filename 163fba7fc7eSJung-uk Kim * OutToFile - TRUE if output should go to a file 164fba7fc7eSJung-uk Kim * Prefix - Path prefix for output 165fba7fc7eSJung-uk Kim * OutFilename - where the filename is returned 16659db4265SNate Lawson * 16759db4265SNate Lawson * RETURN: Status 16859db4265SNate Lawson * 169*f8146b88SJung-uk Kim * DESCRIPTION: Disassembler entry point. Disassemble an entire ACPI table. 17059db4265SNate Lawson * 17159db4265SNate Lawson *****************************************************************************/ 17259db4265SNate Lawson 17359db4265SNate Lawson ACPI_STATUS 17459db4265SNate Lawson AdAmlDisassemble ( 17559db4265SNate Lawson BOOLEAN OutToFile, 17659db4265SNate Lawson char *Filename, 17759db4265SNate Lawson char *Prefix, 178313a0c13SJung-uk Kim char **OutFilename) 17959db4265SNate Lawson { 18059db4265SNate Lawson ACPI_STATUS Status; 18159db4265SNate Lawson char *DisasmFilename = NULL; 18259db4265SNate Lawson FILE *File = NULL; 183a9f12690SJung-uk Kim ACPI_TABLE_HEADER *Table = NULL; 184*f8146b88SJung-uk Kim ACPI_NEW_TABLE_DESC *ListHead = NULL; 18559db4265SNate Lawson 18659db4265SNate Lawson 18759db4265SNate Lawson /* 188f556842eSJung-uk Kim * Input: AML code from either a file or via GetTables (memory or 189f556842eSJung-uk Kim * registry) 19059db4265SNate Lawson */ 19159db4265SNate Lawson if (Filename) 19259db4265SNate Lawson { 193*f8146b88SJung-uk Kim /* Get the list of all AML tables in the file */ 194*f8146b88SJung-uk Kim 195*f8146b88SJung-uk Kim Status = AcGetAllTablesFromFile (Filename, 196*f8146b88SJung-uk Kim ACPI_GET_ALL_TABLES, &ListHead); 197*f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 198*f8146b88SJung-uk Kim { 199*f8146b88SJung-uk Kim AcpiOsPrintf ("Could not get ACPI tables from %s, %s\n", 200*f8146b88SJung-uk Kim Filename, AcpiFormatException (Status)); 201*f8146b88SJung-uk Kim return (Status); 202*f8146b88SJung-uk Kim } 203*f8146b88SJung-uk Kim 204*f8146b88SJung-uk Kim /* Process any user-specified files for external objects */ 205*f8146b88SJung-uk Kim 206*f8146b88SJung-uk Kim Status = AdDoExternalFileList (Filename); 20759db4265SNate Lawson if (ACPI_FAILURE (Status)) 20859db4265SNate Lawson { 2098ef1a331SJung-uk Kim return (Status); 21059db4265SNate Lawson } 21159db4265SNate Lawson } 21259db4265SNate Lawson else 21359db4265SNate Lawson { 214313a0c13SJung-uk Kim Status = AdGetLocalTables (); 21559db4265SNate Lawson if (ACPI_FAILURE (Status)) 21659db4265SNate Lawson { 21759db4265SNate Lawson AcpiOsPrintf ("Could not get ACPI tables, %s\n", 21859db4265SNate Lawson AcpiFormatException (Status)); 2198ef1a331SJung-uk Kim return (Status); 22059db4265SNate Lawson } 22159db4265SNate Lawson 22270e6ab8fSJung-uk Kim if (!AcpiGbl_DmOpt_Disasm) 22359db4265SNate Lawson { 2248ef1a331SJung-uk Kim return (AE_OK); 22559db4265SNate Lawson } 22659db4265SNate Lawson 2271a39cfb0SJung-uk Kim /* Obtained the local tables, just disassemble the DSDT */ 22859db4265SNate Lawson 2291a39cfb0SJung-uk Kim Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table); 2301a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 2311a39cfb0SJung-uk Kim { 2321a39cfb0SJung-uk Kim AcpiOsPrintf ("Could not get DSDT, %s\n", 2331a39cfb0SJung-uk Kim AcpiFormatException (Status)); 2348ef1a331SJung-uk Kim return (Status); 2351a39cfb0SJung-uk Kim } 2361a39cfb0SJung-uk Kim 23759db4265SNate Lawson AcpiOsPrintf ("\nDisassembly of DSDT\n"); 2381a39cfb0SJung-uk Kim Prefix = AdGenerateFilename ("dsdt", Table->OemTableId); 23959db4265SNate Lawson } 24059db4265SNate Lawson 24159db4265SNate Lawson /* 242f556842eSJung-uk Kim * Output: ASL code. Redirect to a file if requested 24359db4265SNate Lawson */ 24459db4265SNate Lawson if (OutToFile) 24559db4265SNate Lawson { 24659db4265SNate Lawson /* Create/Open a disassembly output file */ 24759db4265SNate Lawson 24859db4265SNate Lawson DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY); 249313a0c13SJung-uk Kim if (!DisasmFilename) 25059db4265SNate Lawson { 25159db4265SNate Lawson fprintf (stderr, "Could not generate output filename\n"); 252e50beb51SNate Lawson Status = AE_ERROR; 253e50beb51SNate Lawson goto Cleanup; 25459db4265SNate Lawson } 25559db4265SNate Lawson 25659db4265SNate Lawson File = fopen (DisasmFilename, "w+"); 25759db4265SNate Lawson if (!File) 25859db4265SNate Lawson { 259*f8146b88SJung-uk Kim fprintf (stderr, "Could not open output file %s\n", 260*f8146b88SJung-uk Kim DisasmFilename); 261e50beb51SNate Lawson Status = AE_ERROR; 262e50beb51SNate Lawson goto Cleanup; 26359db4265SNate Lawson } 26459db4265SNate Lawson 26559db4265SNate Lawson AcpiOsRedirectOutput (File); 26659db4265SNate Lawson } 26759db4265SNate Lawson 26859db4265SNate Lawson *OutFilename = DisasmFilename; 26959db4265SNate Lawson 270*f8146b88SJung-uk Kim /* Disassemble all AML tables within the file */ 271*f8146b88SJung-uk Kim 272*f8146b88SJung-uk Kim while (ListHead) 273*f8146b88SJung-uk Kim { 274*f8146b88SJung-uk Kim Status = AdDisassembleOneTable (ListHead->Table, 275*f8146b88SJung-uk Kim File, Filename, DisasmFilename); 276*f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 277*f8146b88SJung-uk Kim { 278*f8146b88SJung-uk Kim break; 279*f8146b88SJung-uk Kim } 280*f8146b88SJung-uk Kim 281*f8146b88SJung-uk Kim ListHead = ListHead->Next; 282*f8146b88SJung-uk Kim } 283*f8146b88SJung-uk Kim 284*f8146b88SJung-uk Kim Cleanup: 285*f8146b88SJung-uk Kim 286*f8146b88SJung-uk Kim if (Table && 287*f8146b88SJung-uk Kim !AcpiGbl_ForceAmlDisassembly && 288*f8146b88SJung-uk Kim !AcpiUtIsAmlTable (Table)) 289*f8146b88SJung-uk Kim { 290*f8146b88SJung-uk Kim ACPI_FREE (Table); 291*f8146b88SJung-uk Kim } 292*f8146b88SJung-uk Kim 293*f8146b88SJung-uk Kim if (File) 294*f8146b88SJung-uk Kim { 295*f8146b88SJung-uk Kim fclose (File); 296*f8146b88SJung-uk Kim AcpiOsRedirectOutput (stdout); 297*f8146b88SJung-uk Kim } 298*f8146b88SJung-uk Kim 299*f8146b88SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 300*f8146b88SJung-uk Kim AcpiGbl_ParseOpRoot = NULL; 301*f8146b88SJung-uk Kim return (Status); 302*f8146b88SJung-uk Kim } 303*f8146b88SJung-uk Kim 304*f8146b88SJung-uk Kim 305*f8146b88SJung-uk Kim /****************************************************************************** 306*f8146b88SJung-uk Kim * 307*f8146b88SJung-uk Kim * FUNCTION: AdDisassembleOneTable 308*f8146b88SJung-uk Kim * 309*f8146b88SJung-uk Kim * PARAMETERS: Table - Raw AML table 310*f8146b88SJung-uk Kim * File - Pointer for the input file 311*f8146b88SJung-uk Kim * Filename - AML input filename 312*f8146b88SJung-uk Kim * DisasmFilename - Output filename 313*f8146b88SJung-uk Kim * 314*f8146b88SJung-uk Kim * RETURN: Status 315*f8146b88SJung-uk Kim * 316*f8146b88SJung-uk Kim * DESCRIPTION: Disassemble a single ACPI table. AML or data table. 317*f8146b88SJung-uk Kim * 318*f8146b88SJung-uk Kim *****************************************************************************/ 319*f8146b88SJung-uk Kim 320*f8146b88SJung-uk Kim static ACPI_STATUS 321*f8146b88SJung-uk Kim AdDisassembleOneTable ( 322*f8146b88SJung-uk Kim ACPI_TABLE_HEADER *Table, 323*f8146b88SJung-uk Kim FILE *File, 324*f8146b88SJung-uk Kim char *Filename, 325*f8146b88SJung-uk Kim char *DisasmFilename) 326*f8146b88SJung-uk Kim { 327*f8146b88SJung-uk Kim ACPI_STATUS Status; 328*f8146b88SJung-uk Kim ACPI_OWNER_ID OwnerId; 329*f8146b88SJung-uk Kim 330*f8146b88SJung-uk Kim 3317cf3e94aSJung-uk Kim /* ForceAmlDisassembly means to assume the table contains valid AML */ 3327cf3e94aSJung-uk Kim 3337cf3e94aSJung-uk Kim if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table)) 3341a39cfb0SJung-uk Kim { 3357cf3e94aSJung-uk Kim AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE); 336*f8146b88SJung-uk Kim 337*f8146b88SJung-uk Kim /* This is a "Data Table" (non-AML table) */ 338*f8146b88SJung-uk Kim 3391a39cfb0SJung-uk Kim AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n", 3401a39cfb0SJung-uk Kim Table->Signature); 341ec3fc72fSJung-uk Kim AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] " 342ec3fc72fSJung-uk Kim "FieldName : FieldValue\n */\n\n"); 3431a39cfb0SJung-uk Kim 3441a39cfb0SJung-uk Kim AcpiDmDumpDataTable (Table); 3454c52cad2SJung-uk Kim fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n", 3464c52cad2SJung-uk Kim Table->Signature); 3471c0e1b6dSJung-uk Kim 3481c0e1b6dSJung-uk Kim if (File) 3491c0e1b6dSJung-uk Kim { 3504c52cad2SJung-uk Kim fprintf (stderr, "Formatted output: %s - %u bytes\n", 351313a0c13SJung-uk Kim DisasmFilename, CmGetFileSize (File)); 3521a39cfb0SJung-uk Kim } 35359db4265SNate Lawson 354*f8146b88SJung-uk Kim return (AE_OK); 355*f8146b88SJung-uk Kim } 356*f8146b88SJung-uk Kim 357*f8146b88SJung-uk Kim /* 358*f8146b88SJung-uk Kim * This is an AML table (DSDT or SSDT). 359*f8146b88SJung-uk Kim * Always parse the tables, only option is what to display 360*f8146b88SJung-uk Kim */ 361a9f12690SJung-uk Kim Status = AdParseTable (Table, &OwnerId, TRUE, FALSE); 36259db4265SNate Lawson if (ACPI_FAILURE (Status)) 36359db4265SNate Lawson { 36459db4265SNate Lawson AcpiOsPrintf ("Could not parse ACPI tables, %s\n", 36559db4265SNate Lawson AcpiFormatException (Status)); 366*f8146b88SJung-uk Kim return (Status); 36759db4265SNate Lawson } 36859db4265SNate Lawson 369*f8146b88SJung-uk Kim /* Debug output, namespace and parse tree */ 370*f8146b88SJung-uk Kim 371*f8146b88SJung-uk Kim if (AslCompilerdebug && File) 3721a39cfb0SJung-uk Kim { 3731a39cfb0SJung-uk Kim AcpiOsPrintf ("/**** Before second load\n"); 3741a39cfb0SJung-uk Kim 375efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 376efcc2a30SJung-uk Kim NsDisplayNamespace (); 377*f8146b88SJung-uk Kim 3781a39cfb0SJung-uk Kim AcpiOsPrintf ("*****/\n"); 3791a39cfb0SJung-uk Kim } 3801a39cfb0SJung-uk Kim 381ec3fc72fSJung-uk Kim /* Load namespace from names created within control methods */ 382ec3fc72fSJung-uk Kim 383ec3fc72fSJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 384ec3fc72fSJung-uk Kim AcpiGbl_RootNode, OwnerId); 3851a39cfb0SJung-uk Kim 3861a39cfb0SJung-uk Kim /* 387ec3fc72fSJung-uk Kim * Cross reference the namespace here, in order to 388ec3fc72fSJung-uk Kim * generate External() statements 3891a39cfb0SJung-uk Kim */ 390ec3fc72fSJung-uk Kim AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, 391ec3fc72fSJung-uk Kim AcpiGbl_RootNode, OwnerId); 3921a39cfb0SJung-uk Kim 3931a39cfb0SJung-uk Kim if (AslCompilerdebug) 3941a39cfb0SJung-uk Kim { 3951a39cfb0SJung-uk Kim AcpiDmDumpTree (AcpiGbl_ParseOpRoot); 3961a39cfb0SJung-uk Kim } 3971a39cfb0SJung-uk Kim 3981a39cfb0SJung-uk Kim /* Find possible calls to external control methods */ 3991a39cfb0SJung-uk Kim 4001a39cfb0SJung-uk Kim AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot); 4011a39cfb0SJung-uk Kim 4021a39cfb0SJung-uk Kim /* 403ec3fc72fSJung-uk Kim * If we found any external control methods, we must reparse 404ec3fc72fSJung-uk Kim * the entire tree with the new information (namely, the 405ec3fc72fSJung-uk Kim * number of arguments per method) 4061a39cfb0SJung-uk Kim */ 407f556842eSJung-uk Kim if (AcpiDmGetExternalMethodCount ()) 4081a39cfb0SJung-uk Kim { 409*f8146b88SJung-uk Kim Status = AdReparseOneTable (Table, File, OwnerId); 4101a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 4111a39cfb0SJung-uk Kim { 412*f8146b88SJung-uk Kim return (Status); 4131a39cfb0SJung-uk Kim } 4141a39cfb0SJung-uk Kim } 415e0ef747bSNate Lawson 416ec3fc72fSJung-uk Kim /* 417ec3fc72fSJung-uk Kim * Now that the namespace is finalized, we can perform namespace 418ec3fc72fSJung-uk Kim * transforms. 419ec3fc72fSJung-uk Kim * 420ec3fc72fSJung-uk Kim * 1) Convert fixed-offset references to resource descriptors 421ec3fc72fSJung-uk Kim * to symbolic references (Note: modifies namespace) 422ec3fc72fSJung-uk Kim */ 423ec3fc72fSJung-uk Kim AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode); 424ec3fc72fSJung-uk Kim 42559db4265SNate Lawson /* Optional displays */ 42659db4265SNate Lawson 42770e6ab8fSJung-uk Kim if (AcpiGbl_DmOpt_Disasm) 42859db4265SNate Lawson { 4298ef1a331SJung-uk Kim /* This is the real disassembly */ 4308ef1a331SJung-uk Kim 43159db4265SNate Lawson AdDisplayTables (Filename, Table); 4328ef1a331SJung-uk Kim 4338ef1a331SJung-uk Kim /* Dump hex table if requested (-vt) */ 4348ef1a331SJung-uk Kim 4358ef1a331SJung-uk Kim AcpiDmDumpDataTable (Table); 4368ef1a331SJung-uk Kim 4374c52cad2SJung-uk Kim fprintf (stderr, "Disassembly completed\n"); 4381c0e1b6dSJung-uk Kim if (File) 4391c0e1b6dSJung-uk Kim { 4404c52cad2SJung-uk Kim fprintf (stderr, "ASL Output: %s - %u bytes\n", 441313a0c13SJung-uk Kim DisasmFilename, CmGetFileSize (File)); 4421c0e1b6dSJung-uk Kim } 443313a0c13SJung-uk Kim 444313a0c13SJung-uk Kim if (Gbl_MapfileFlag) 445313a0c13SJung-uk Kim { 446313a0c13SJung-uk Kim fprintf (stderr, "%14s %s - %u bytes\n", 447313a0c13SJung-uk Kim Gbl_Files[ASL_FILE_MAP_OUTPUT].ShortDescription, 448313a0c13SJung-uk Kim Gbl_Files[ASL_FILE_MAP_OUTPUT].Filename, 449313a0c13SJung-uk Kim FlGetFileSize (ASL_FILE_MAP_OUTPUT)); 450313a0c13SJung-uk Kim } 4511a39cfb0SJung-uk Kim } 452*f8146b88SJung-uk Kim 453*f8146b88SJung-uk Kim return (AE_OK); 45459db4265SNate Lawson } 45559db4265SNate Lawson 456a9f12690SJung-uk Kim 457*f8146b88SJung-uk Kim /****************************************************************************** 458*f8146b88SJung-uk Kim * 459*f8146b88SJung-uk Kim * FUNCTION: AdReparseOneTable 460*f8146b88SJung-uk Kim * 461*f8146b88SJung-uk Kim * PARAMETERS: Table - Raw AML table 462*f8146b88SJung-uk Kim * File - Pointer for the input file 463*f8146b88SJung-uk Kim * OwnerId - ID for this table 464*f8146b88SJung-uk Kim * 465*f8146b88SJung-uk Kim * RETURN: Status 466*f8146b88SJung-uk Kim * 467*f8146b88SJung-uk Kim * DESCRIPTION: Reparse a table that has already been loaded. Used to 468*f8146b88SJung-uk Kim * integrate information about external control methods. 469*f8146b88SJung-uk Kim * These methods may have been previously parsed incorrectly. 470*f8146b88SJung-uk Kim * 471*f8146b88SJung-uk Kim *****************************************************************************/ 472*f8146b88SJung-uk Kim 473*f8146b88SJung-uk Kim static ACPI_STATUS 474*f8146b88SJung-uk Kim AdReparseOneTable ( 475*f8146b88SJung-uk Kim ACPI_TABLE_HEADER *Table, 476*f8146b88SJung-uk Kim FILE *File, 477*f8146b88SJung-uk Kim ACPI_OWNER_ID OwnerId) 478a9f12690SJung-uk Kim { 479*f8146b88SJung-uk Kim ACPI_STATUS Status; 480*f8146b88SJung-uk Kim 481*f8146b88SJung-uk Kim 482*f8146b88SJung-uk Kim fprintf (stderr, 483*f8146b88SJung-uk Kim "\nFound %u external control methods, " 484*f8146b88SJung-uk Kim "reparsing with new information\n", 485*f8146b88SJung-uk Kim AcpiDmGetExternalMethodCount ()); 486*f8146b88SJung-uk Kim 487*f8146b88SJung-uk Kim /* Reparse, rebuild namespace */ 488*f8146b88SJung-uk Kim 489*f8146b88SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 490*f8146b88SJung-uk Kim AcpiGbl_ParseOpRoot = NULL; 491*f8146b88SJung-uk Kim AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode); 492*f8146b88SJung-uk Kim 493*f8146b88SJung-uk Kim AcpiGbl_RootNode = NULL; 494*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME; 495*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED; 496*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE; 497*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.Parent = NULL; 498*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.Child = NULL; 499*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.Peer = NULL; 500*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.Object = NULL; 501*f8146b88SJung-uk Kim AcpiGbl_RootNodeStruct.Flags = 0; 502*f8146b88SJung-uk Kim 503*f8146b88SJung-uk Kim Status = AcpiNsRootInitialize (); 504*f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 505*f8146b88SJung-uk Kim { 506*f8146b88SJung-uk Kim return (Status); 507a9f12690SJung-uk Kim } 508a9f12690SJung-uk Kim 509*f8146b88SJung-uk Kim /* New namespace, add the external definitions first */ 510*f8146b88SJung-uk Kim 511*f8146b88SJung-uk Kim AcpiDmAddExternalsToNamespace (); 512*f8146b88SJung-uk Kim 513*f8146b88SJung-uk Kim /* Parse the table again. No need to reload it, however */ 514*f8146b88SJung-uk Kim 515*f8146b88SJung-uk Kim Status = AdParseTable (Table, NULL, FALSE, FALSE); 516*f8146b88SJung-uk Kim if (ACPI_FAILURE (Status)) 517*f8146b88SJung-uk Kim { 518*f8146b88SJung-uk Kim AcpiOsPrintf ("Could not parse ACPI tables, %s\n", 519*f8146b88SJung-uk Kim AcpiFormatException (Status)); 520*f8146b88SJung-uk Kim return (Status); 521*f8146b88SJung-uk Kim } 522*f8146b88SJung-uk Kim 523*f8146b88SJung-uk Kim /* Cross reference the namespace again */ 524*f8146b88SJung-uk Kim 525*f8146b88SJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 526*f8146b88SJung-uk Kim AcpiGbl_RootNode, OwnerId); 527*f8146b88SJung-uk Kim 528*f8146b88SJung-uk Kim AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, 529*f8146b88SJung-uk Kim AcpiGbl_RootNode, OwnerId); 530*f8146b88SJung-uk Kim 531*f8146b88SJung-uk Kim /* Debug output - namespace and parse tree */ 532*f8146b88SJung-uk Kim 533*f8146b88SJung-uk Kim if (AslCompilerdebug) 534*f8146b88SJung-uk Kim { 535*f8146b88SJung-uk Kim AcpiOsPrintf ("/**** After second load and resource conversion\n"); 5361c0e1b6dSJung-uk Kim if (File) 53759db4265SNate Lawson { 538efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 539efcc2a30SJung-uk Kim NsDisplayNamespace (); 540ec3fc72fSJung-uk Kim } 541ec3fc72fSJung-uk Kim 542*f8146b88SJung-uk Kim AcpiOsPrintf ("*****/\n"); 543*f8146b88SJung-uk Kim AcpiDmDumpTree (AcpiGbl_ParseOpRoot); 54459db4265SNate Lawson } 54559db4265SNate Lawson 5468ef1a331SJung-uk Kim return (AE_OK); 54759db4265SNate Lawson } 54859db4265SNate Lawson 54959db4265SNate Lawson 550*f8146b88SJung-uk Kim /****************************************************************************** 5517cf3e94aSJung-uk Kim * 552*f8146b88SJung-uk Kim * FUNCTION: AdDoExternalFileList 5537cf3e94aSJung-uk Kim * 554*f8146b88SJung-uk Kim * PARAMETERS: Filename - Input file for the table 5557cf3e94aSJung-uk Kim * 556*f8146b88SJung-uk Kim * RETURN: Status 5577cf3e94aSJung-uk Kim * 558*f8146b88SJung-uk Kim * DESCRIPTION: Process all tables found in the -e external files list 5597cf3e94aSJung-uk Kim * 560*f8146b88SJung-uk Kim *****************************************************************************/ 5617cf3e94aSJung-uk Kim 5627cf3e94aSJung-uk Kim static ACPI_STATUS 563*f8146b88SJung-uk Kim AdDoExternalFileList ( 564*f8146b88SJung-uk Kim char *Filename) 5657cf3e94aSJung-uk Kim { 566*f8146b88SJung-uk Kim ACPI_EXTERNAL_FILE *ExternalFileList; 567*f8146b88SJung-uk Kim char *ExternalFilename; 568*f8146b88SJung-uk Kim ACPI_NEW_TABLE_DESC *ExternalListHead = NULL; 5697cf3e94aSJung-uk Kim ACPI_STATUS Status; 570*f8146b88SJung-uk Kim ACPI_STATUS GlobalStatus = AE_OK; 571*f8146b88SJung-uk Kim ACPI_OWNER_ID OwnerId; 5727cf3e94aSJung-uk Kim 5737cf3e94aSJung-uk Kim 574*f8146b88SJung-uk Kim /* 575*f8146b88SJung-uk Kim * External filenames are specified on the command line like this: 576*f8146b88SJung-uk Kim * Example: iasl -e file1,file2,file3 -d xxx.aml 577*f8146b88SJung-uk Kim */ 578*f8146b88SJung-uk Kim ExternalFileList = AcpiGbl_ExternalFileList; 579*f8146b88SJung-uk Kim 580*f8146b88SJung-uk Kim /* Process each external file */ 581*f8146b88SJung-uk Kim 582*f8146b88SJung-uk Kim while (ExternalFileList) 583*f8146b88SJung-uk Kim { 584*f8146b88SJung-uk Kim ExternalFilename = ExternalFileList->Path; 585*f8146b88SJung-uk Kim if (!strcmp (ExternalFilename, Filename)) 586*f8146b88SJung-uk Kim { 587*f8146b88SJung-uk Kim /* Next external file */ 588*f8146b88SJung-uk Kim 589*f8146b88SJung-uk Kim ExternalFileList = ExternalFileList->Next; 590*f8146b88SJung-uk Kim continue; 591*f8146b88SJung-uk Kim } 592*f8146b88SJung-uk Kim 593*f8146b88SJung-uk Kim AcpiOsPrintf ("External object resolution file %16s\n", 594*f8146b88SJung-uk Kim ExternalFilename); 595*f8146b88SJung-uk Kim 596*f8146b88SJung-uk Kim Status = AcGetAllTablesFromFile ( 597*f8146b88SJung-uk Kim ExternalFilename, ACPI_GET_ONLY_AML_TABLES, &ExternalListHead); 5987cf3e94aSJung-uk Kim if (ACPI_FAILURE (Status)) 5997cf3e94aSJung-uk Kim { 600*f8146b88SJung-uk Kim if (Status == AE_TYPE) 601*f8146b88SJung-uk Kim { 602*f8146b88SJung-uk Kim ExternalFileList = ExternalFileList->Next; 603*f8146b88SJung-uk Kim GlobalStatus = AE_TYPE; 604*f8146b88SJung-uk Kim Status = AE_OK; 605*f8146b88SJung-uk Kim continue; 606*f8146b88SJung-uk Kim } 607*f8146b88SJung-uk Kim 6087cf3e94aSJung-uk Kim return (Status); 6097cf3e94aSJung-uk Kim } 6107cf3e94aSJung-uk Kim 611*f8146b88SJung-uk Kim /* Load external tables for symbol resolution */ 6127cf3e94aSJung-uk Kim 613*f8146b88SJung-uk Kim while (ExternalListHead) 61459db4265SNate Lawson { 615*f8146b88SJung-uk Kim Status = AdParseTable ( 616*f8146b88SJung-uk Kim ExternalListHead->Table, &OwnerId, TRUE, TRUE); 617f556842eSJung-uk Kim if (ACPI_FAILURE (Status)) 618f556842eSJung-uk Kim { 619*f8146b88SJung-uk Kim AcpiOsPrintf ("Could not parse external ACPI tables, %s\n", 620*f8146b88SJung-uk Kim AcpiFormatException (Status)); 62159db4265SNate Lawson return (Status); 62259db4265SNate Lawson } 62359db4265SNate Lawson 624313a0c13SJung-uk Kim /* 625*f8146b88SJung-uk Kim * Load namespace from names created within control methods 626*f8146b88SJung-uk Kim * Set owner id of nodes in external table 627313a0c13SJung-uk Kim */ 628*f8146b88SJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 629*f8146b88SJung-uk Kim AcpiGbl_RootNode, OwnerId); 630*f8146b88SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 6311a39cfb0SJung-uk Kim 632*f8146b88SJung-uk Kim ExternalListHead = ExternalListHead->Next; 633*f8146b88SJung-uk Kim } 6341a39cfb0SJung-uk Kim 635*f8146b88SJung-uk Kim /* Next external file */ 63659db4265SNate Lawson 637*f8146b88SJung-uk Kim ExternalFileList = ExternalFileList->Next; 638*f8146b88SJung-uk Kim } 639*f8146b88SJung-uk Kim 640*f8146b88SJung-uk Kim if (ACPI_FAILURE (GlobalStatus)) 641*f8146b88SJung-uk Kim { 642*f8146b88SJung-uk Kim return (GlobalStatus); 643*f8146b88SJung-uk Kim } 644*f8146b88SJung-uk Kim 645*f8146b88SJung-uk Kim /* Clear external list generated by Scope in external tables */ 646*f8146b88SJung-uk Kim 647*f8146b88SJung-uk Kim if (AcpiGbl_ExternalFileList) 648*f8146b88SJung-uk Kim { 649*f8146b88SJung-uk Kim AcpiDmClearExternalList (); 650*f8146b88SJung-uk Kim } 651*f8146b88SJung-uk Kim 652*f8146b88SJung-uk Kim /* Load any externals defined in the optional external ref file */ 653*f8146b88SJung-uk Kim 654*f8146b88SJung-uk Kim AcpiDmGetExternalsFromFile (); 6558ef1a331SJung-uk Kim return (AE_OK); 65659db4265SNate Lawson } 657