159db4265SNate Lawson /****************************************************************************** 259db4265SNate Lawson * 359db4265SNate Lawson * Module Name: adisasm - Application-level disassembler routines 459db4265SNate Lawson * 559db4265SNate Lawson *****************************************************************************/ 659db4265SNate Lawson 7d244b227SJung-uk Kim /* 8*efcc2a30SJung-uk Kim * Copyright (C) 2000 - 2013, 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 4459db4265SNate Lawson 45ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h> 46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h> 47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h> 48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h> 49ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdebug.h> 50ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h> 51ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h> 52ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h> 53ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h> 54ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h> 5559db4265SNate Lawson 5659db4265SNate Lawson #include <stdio.h> 5759db4265SNate Lawson #include <time.h> 5859db4265SNate Lawson 5959db4265SNate Lawson 6059db4265SNate Lawson #define _COMPONENT ACPI_TOOLS 6159db4265SNate Lawson ACPI_MODULE_NAME ("adisasm") 6259db4265SNate Lawson 631df130f1SJung-uk Kim /* 641df130f1SJung-uk Kim * Older versions of Bison won't emit this external in the generated header. 651df130f1SJung-uk Kim * Newer versions do emit the external, so we don't need to do it. 661df130f1SJung-uk Kim */ 671df130f1SJung-uk Kim #ifndef ASLCOMPILER_ASLCOMPILERPARSE_H 681a39cfb0SJung-uk Kim extern int AslCompilerdebug; 691df130f1SJung-uk Kim #endif 7059db4265SNate Lawson 711a39cfb0SJung-uk Kim ACPI_STATUS 72*efcc2a30SJung-uk Kim NsDisplayNamespace ( 731a39cfb0SJung-uk Kim void); 7459db4265SNate Lawson 751a39cfb0SJung-uk Kim void 76*efcc2a30SJung-uk Kim NsSetupNamespaceListing ( 77f556842eSJung-uk Kim void *Handle); 781a39cfb0SJung-uk Kim 791a39cfb0SJung-uk Kim 801a39cfb0SJung-uk Kim /* Local prototypes */ 811a39cfb0SJung-uk Kim 824c52cad2SJung-uk Kim static UINT32 834c52cad2SJung-uk Kim AdGetFileSize ( 844c52cad2SJung-uk Kim FILE *File); 854c52cad2SJung-uk Kim 8642fecd12SJung-uk Kim static void 871a39cfb0SJung-uk Kim AdCreateTableHeader ( 881a39cfb0SJung-uk Kim char *Filename, 891a39cfb0SJung-uk Kim ACPI_TABLE_HEADER *Table); 901a39cfb0SJung-uk Kim 911a39cfb0SJung-uk Kim /* Stubs for ASL compiler */ 9259db4265SNate Lawson 93fba7fc7eSJung-uk Kim #ifndef ACPI_ASL_COMPILER 9459db4265SNate Lawson BOOLEAN 9559db4265SNate Lawson AcpiDsIsResultUsed ( 9659db4265SNate Lawson ACPI_PARSE_OBJECT *Op, 9759db4265SNate Lawson ACPI_WALK_STATE *WalkState) 9859db4265SNate Lawson { 9959db4265SNate Lawson return TRUE; 10059db4265SNate Lawson } 1011a39cfb0SJung-uk Kim 1021a39cfb0SJung-uk Kim ACPI_STATUS 1031a39cfb0SJung-uk Kim AcpiDsMethodError ( 1041a39cfb0SJung-uk Kim ACPI_STATUS Status, 1051a39cfb0SJung-uk Kim ACPI_WALK_STATE *WalkState) 1061a39cfb0SJung-uk Kim { 1071a39cfb0SJung-uk Kim return (Status); 1081a39cfb0SJung-uk Kim } 10959db4265SNate Lawson #endif 11059db4265SNate Lawson 11159db4265SNate Lawson ACPI_STATUS 1121a39cfb0SJung-uk Kim AcpiNsLoadTable ( 113a9f12690SJung-uk Kim UINT32 TableIndex, 1141a39cfb0SJung-uk Kim ACPI_NAMESPACE_NODE *Node) 1151a39cfb0SJung-uk Kim { 1161a39cfb0SJung-uk Kim return (AE_NOT_IMPLEMENTED); 1171a39cfb0SJung-uk Kim } 1181a39cfb0SJung-uk Kim 1191a39cfb0SJung-uk Kim ACPI_STATUS 12059db4265SNate Lawson AcpiDsRestartControlMethod ( 12159db4265SNate Lawson ACPI_WALK_STATE *WalkState, 12259db4265SNate Lawson ACPI_OPERAND_OBJECT *ReturnDesc) 12359db4265SNate Lawson { 12459db4265SNate Lawson return (AE_OK); 12559db4265SNate Lawson } 12659db4265SNate Lawson 127fba7fc7eSJung-uk Kim void 12859db4265SNate Lawson AcpiDsTerminateControlMethod ( 1291a39cfb0SJung-uk Kim ACPI_OPERAND_OBJECT *MethodDesc, 13059db4265SNate Lawson ACPI_WALK_STATE *WalkState) 13159db4265SNate Lawson { 132fba7fc7eSJung-uk Kim return; 13359db4265SNate Lawson } 13459db4265SNate Lawson 13559db4265SNate Lawson ACPI_STATUS 13659db4265SNate Lawson AcpiDsCallControlMethod ( 13759db4265SNate Lawson ACPI_THREAD_STATE *Thread, 13859db4265SNate Lawson ACPI_WALK_STATE *WalkState, 13959db4265SNate Lawson ACPI_PARSE_OBJECT *Op) 14059db4265SNate Lawson { 14159db4265SNate Lawson return (AE_OK); 14259db4265SNate Lawson } 14359db4265SNate Lawson 14459db4265SNate Lawson ACPI_STATUS 14559db4265SNate Lawson AcpiDsMethodDataInitArgs ( 14659db4265SNate Lawson ACPI_OPERAND_OBJECT **Params, 14759db4265SNate Lawson UINT32 MaxParamCount, 14859db4265SNate Lawson ACPI_WALK_STATE *WalkState) 14959db4265SNate Lawson { 15059db4265SNate Lawson return (AE_OK); 15159db4265SNate Lawson } 15259db4265SNate Lawson 15359db4265SNate Lawson 154f556842eSJung-uk Kim static ACPI_TABLE_DESC LocalTables[1]; 155f556842eSJung-uk Kim static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot; 15659db4265SNate Lawson 15759db4265SNate Lawson 15859db4265SNate Lawson /******************************************************************************* 15959db4265SNate Lawson * 1604c52cad2SJung-uk Kim * FUNCTION: AdGetFileSize 1614c52cad2SJung-uk Kim * 1624c52cad2SJung-uk Kim * PARAMETERS: File - Open file handle 1634c52cad2SJung-uk Kim * 1644c52cad2SJung-uk Kim * RETURN: File Size 1654c52cad2SJung-uk Kim * 1664c52cad2SJung-uk Kim * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open. 1674c52cad2SJung-uk Kim * 1684c52cad2SJung-uk Kim ******************************************************************************/ 1694c52cad2SJung-uk Kim 1704c52cad2SJung-uk Kim static UINT32 1714c52cad2SJung-uk Kim AdGetFileSize ( 1724c52cad2SJung-uk Kim FILE *File) 1734c52cad2SJung-uk Kim { 1744c52cad2SJung-uk Kim UINT32 FileSize; 1754c52cad2SJung-uk Kim long Offset; 1764c52cad2SJung-uk Kim 1774c52cad2SJung-uk Kim 1784c52cad2SJung-uk Kim Offset = ftell (File); 1794c52cad2SJung-uk Kim 1804c52cad2SJung-uk Kim fseek (File, 0, SEEK_END); 1814c52cad2SJung-uk Kim FileSize = (UINT32) ftell (File); 1824c52cad2SJung-uk Kim 1834c52cad2SJung-uk Kim /* Restore file pointer */ 1844c52cad2SJung-uk Kim 1854c52cad2SJung-uk Kim fseek (File, Offset, SEEK_SET); 1864c52cad2SJung-uk Kim return (FileSize); 1874c52cad2SJung-uk Kim } 1884c52cad2SJung-uk Kim 1894c52cad2SJung-uk Kim 1904c52cad2SJung-uk Kim /******************************************************************************* 1914c52cad2SJung-uk Kim * 19259db4265SNate Lawson * FUNCTION: AdInitialize 19359db4265SNate Lawson * 194f556842eSJung-uk Kim * PARAMETERS: None 19559db4265SNate Lawson * 19659db4265SNate Lawson * RETURN: Status 19759db4265SNate Lawson * 198f556842eSJung-uk Kim * DESCRIPTION: ACPICA and local initialization 19959db4265SNate Lawson * 20059db4265SNate Lawson ******************************************************************************/ 20159db4265SNate Lawson 20259db4265SNate Lawson ACPI_STATUS 20359db4265SNate Lawson AdInitialize ( 20459db4265SNate Lawson void) 20559db4265SNate Lawson { 20659db4265SNate Lawson ACPI_STATUS Status; 20759db4265SNate Lawson 20859db4265SNate Lawson 20959db4265SNate Lawson /* ACPI CA subsystem initialization */ 21059db4265SNate Lawson 2111a39cfb0SJung-uk Kim Status = AcpiOsInitialize (); 212a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 213a9f12690SJung-uk Kim { 214a9f12690SJung-uk Kim return (Status); 215a9f12690SJung-uk Kim } 216a9f12690SJung-uk Kim 217a9f12690SJung-uk Kim Status = AcpiUtInitGlobals (); 218a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 219a9f12690SJung-uk Kim { 220a9f12690SJung-uk Kim return (Status); 221a9f12690SJung-uk Kim } 2221a39cfb0SJung-uk Kim 22359db4265SNate Lawson Status = AcpiUtMutexInitialize (); 22459db4265SNate Lawson if (ACPI_FAILURE (Status)) 22559db4265SNate Lawson { 226a9f12690SJung-uk Kim return (Status); 22759db4265SNate Lawson } 22859db4265SNate Lawson 22959db4265SNate Lawson Status = AcpiNsRootInitialize (); 2301a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 2311a39cfb0SJung-uk Kim { 232a9f12690SJung-uk Kim return (Status); 2331a39cfb0SJung-uk Kim } 2341a39cfb0SJung-uk Kim 2351a39cfb0SJung-uk Kim /* Setup the Table Manager (cheat - there is no RSDT) */ 2361a39cfb0SJung-uk Kim 2373f5e024cSJung-uk Kim AcpiGbl_RootTableList.MaxTableCount = 1; 2383f5e024cSJung-uk Kim AcpiGbl_RootTableList.CurrentTableCount = 0; 2391a39cfb0SJung-uk Kim AcpiGbl_RootTableList.Tables = LocalTables; 2401a39cfb0SJung-uk Kim 241a9f12690SJung-uk Kim return (Status); 24259db4265SNate Lawson } 24359db4265SNate Lawson 24459db4265SNate Lawson 24559db4265SNate Lawson /****************************************************************************** 24659db4265SNate Lawson * 24759db4265SNate Lawson * FUNCTION: AdAmlDisassemble 24859db4265SNate Lawson * 249fba7fc7eSJung-uk Kim * PARAMETERS: Filename - AML input filename 250fba7fc7eSJung-uk Kim * OutToFile - TRUE if output should go to a file 251fba7fc7eSJung-uk Kim * Prefix - Path prefix for output 252fba7fc7eSJung-uk Kim * OutFilename - where the filename is returned 253fba7fc7eSJung-uk Kim * GetAllTables - TRUE if all tables are desired 25459db4265SNate Lawson * 25559db4265SNate Lawson * RETURN: Status 25659db4265SNate Lawson * 25759db4265SNate Lawson * DESCRIPTION: Disassemble an entire ACPI table 25859db4265SNate Lawson * 25959db4265SNate Lawson *****************************************************************************/ 26059db4265SNate Lawson 26159db4265SNate Lawson ACPI_STATUS 26259db4265SNate Lawson AdAmlDisassemble ( 26359db4265SNate Lawson BOOLEAN OutToFile, 26459db4265SNate Lawson char *Filename, 26559db4265SNate Lawson char *Prefix, 26659db4265SNate Lawson char **OutFilename, 26759db4265SNate Lawson BOOLEAN GetAllTables) 26859db4265SNate Lawson { 26959db4265SNate Lawson ACPI_STATUS Status; 27059db4265SNate Lawson char *DisasmFilename = NULL; 271a9f12690SJung-uk Kim char *ExternalFilename; 272709fac06SJung-uk Kim ACPI_EXTERNAL_FILE *ExternalFileList = AcpiGbl_ExternalFileList; 27359db4265SNate Lawson FILE *File = NULL; 274a9f12690SJung-uk Kim ACPI_TABLE_HEADER *Table = NULL; 2751a39cfb0SJung-uk Kim ACPI_TABLE_HEADER *ExternalTable; 276a9f12690SJung-uk Kim ACPI_OWNER_ID OwnerId; 27759db4265SNate Lawson 27859db4265SNate Lawson 27959db4265SNate Lawson /* 280f556842eSJung-uk Kim * Input: AML code from either a file or via GetTables (memory or 281f556842eSJung-uk Kim * registry) 28259db4265SNate Lawson */ 28359db4265SNate Lawson if (Filename) 28459db4265SNate Lawson { 28559db4265SNate Lawson Status = AcpiDbGetTableFromFile (Filename, &Table); 28659db4265SNate Lawson if (ACPI_FAILURE (Status)) 28759db4265SNate Lawson { 2888ef1a331SJung-uk Kim return (Status); 28959db4265SNate Lawson } 2901a39cfb0SJung-uk Kim 291a9f12690SJung-uk Kim /* 292a9f12690SJung-uk Kim * External filenames separated by commas 293a9f12690SJung-uk Kim * Example: iasl -e file1,file2,file3 -d xxx.aml 294a9f12690SJung-uk Kim */ 295709fac06SJung-uk Kim while (ExternalFileList) 2961a39cfb0SJung-uk Kim { 297709fac06SJung-uk Kim ExternalFilename = ExternalFileList->Path; 298709fac06SJung-uk Kim if (!ACPI_STRCMP (ExternalFilename, Filename)) 299709fac06SJung-uk Kim { 300709fac06SJung-uk Kim /* Next external file */ 301a9f12690SJung-uk Kim 302709fac06SJung-uk Kim ExternalFileList = ExternalFileList->Next; 303709fac06SJung-uk Kim continue; 304709fac06SJung-uk Kim } 305709fac06SJung-uk Kim 306a9f12690SJung-uk Kim Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable); 3071a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 3081a39cfb0SJung-uk Kim { 3098ef1a331SJung-uk Kim return (Status); 3101a39cfb0SJung-uk Kim } 311a9f12690SJung-uk Kim 312a9f12690SJung-uk Kim /* Load external table for symbol resolution */ 313a9f12690SJung-uk Kim 314a9f12690SJung-uk Kim if (ExternalTable) 315a9f12690SJung-uk Kim { 316a9f12690SJung-uk Kim Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE); 317a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 318a9f12690SJung-uk Kim { 319a9f12690SJung-uk Kim AcpiOsPrintf ("Could not parse external ACPI tables, %s\n", 320a9f12690SJung-uk Kim AcpiFormatException (Status)); 3218ef1a331SJung-uk Kim return (Status); 322a9f12690SJung-uk Kim } 323a9f12690SJung-uk Kim 324a9f12690SJung-uk Kim /* 325a9f12690SJung-uk Kim * Load namespace from names created within control methods 326a9f12690SJung-uk Kim * Set owner id of nodes in external table 327a9f12690SJung-uk Kim */ 328a9f12690SJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 329a9f12690SJung-uk Kim AcpiGbl_RootNode, OwnerId); 330a9f12690SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 331a9f12690SJung-uk Kim } 332a9f12690SJung-uk Kim 333709fac06SJung-uk Kim /* Next external file */ 334a9f12690SJung-uk Kim 335709fac06SJung-uk Kim ExternalFileList = ExternalFileList->Next; 336a9f12690SJung-uk Kim } 337a9f12690SJung-uk Kim 338a9f12690SJung-uk Kim /* Clear external list generated by Scope in external tables */ 339a9f12690SJung-uk Kim 340709fac06SJung-uk Kim if (AcpiGbl_ExternalFileList) 341709fac06SJung-uk Kim { 342f556842eSJung-uk Kim AcpiDmClearExternalList (); 3431a39cfb0SJung-uk Kim } 34459db4265SNate Lawson } 34559db4265SNate Lawson else 34659db4265SNate Lawson { 34759db4265SNate Lawson Status = AdGetLocalTables (Filename, GetAllTables); 34859db4265SNate Lawson if (ACPI_FAILURE (Status)) 34959db4265SNate Lawson { 35059db4265SNate Lawson AcpiOsPrintf ("Could not get ACPI tables, %s\n", 35159db4265SNate Lawson AcpiFormatException (Status)); 3528ef1a331SJung-uk Kim return (Status); 35359db4265SNate Lawson } 35459db4265SNate Lawson 35559db4265SNate Lawson if (!AcpiGbl_DbOpt_disasm) 35659db4265SNate Lawson { 3578ef1a331SJung-uk Kim return (AE_OK); 35859db4265SNate Lawson } 35959db4265SNate Lawson 3601a39cfb0SJung-uk Kim /* Obtained the local tables, just disassemble the DSDT */ 36159db4265SNate Lawson 3621a39cfb0SJung-uk Kim Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table); 3631a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 3641a39cfb0SJung-uk Kim { 3651a39cfb0SJung-uk Kim AcpiOsPrintf ("Could not get DSDT, %s\n", 3661a39cfb0SJung-uk Kim AcpiFormatException (Status)); 3678ef1a331SJung-uk Kim return (Status); 3681a39cfb0SJung-uk Kim } 3691a39cfb0SJung-uk Kim 37059db4265SNate Lawson AcpiOsPrintf ("\nDisassembly of DSDT\n"); 3711a39cfb0SJung-uk Kim Prefix = AdGenerateFilename ("dsdt", Table->OemTableId); 37259db4265SNate Lawson } 37359db4265SNate Lawson 37459db4265SNate Lawson /* 375f556842eSJung-uk Kim * Output: ASL code. Redirect to a file if requested 37659db4265SNate Lawson */ 37759db4265SNate Lawson if (OutToFile) 37859db4265SNate Lawson { 37959db4265SNate Lawson /* Create/Open a disassembly output file */ 38059db4265SNate Lawson 38159db4265SNate Lawson DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY); 38259db4265SNate Lawson if (!OutFilename) 38359db4265SNate Lawson { 38459db4265SNate Lawson fprintf (stderr, "Could not generate output filename\n"); 385e50beb51SNate Lawson Status = AE_ERROR; 386e50beb51SNate Lawson goto Cleanup; 38759db4265SNate Lawson } 38859db4265SNate Lawson 38959db4265SNate Lawson File = fopen (DisasmFilename, "w+"); 39059db4265SNate Lawson if (!File) 39159db4265SNate Lawson { 3921a39cfb0SJung-uk Kim fprintf (stderr, "Could not open output file %s\n", DisasmFilename); 393e50beb51SNate Lawson Status = AE_ERROR; 394e50beb51SNate Lawson goto Cleanup; 39559db4265SNate Lawson } 39659db4265SNate Lawson 39759db4265SNate Lawson AcpiOsRedirectOutput (File); 39859db4265SNate Lawson } 39959db4265SNate Lawson 40059db4265SNate Lawson *OutFilename = DisasmFilename; 40159db4265SNate Lawson 4021a39cfb0SJung-uk Kim if (!AcpiUtIsAmlTable (Table)) 4031a39cfb0SJung-uk Kim { 4041a39cfb0SJung-uk Kim AdDisassemblerHeader (Filename); 4051a39cfb0SJung-uk Kim AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n", 4061a39cfb0SJung-uk Kim Table->Signature); 407ec3fc72fSJung-uk Kim AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] " 408ec3fc72fSJung-uk Kim "FieldName : FieldValue\n */\n\n"); 4091a39cfb0SJung-uk Kim 4101a39cfb0SJung-uk Kim AcpiDmDumpDataTable (Table); 4114c52cad2SJung-uk Kim fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n", 4124c52cad2SJung-uk Kim Table->Signature); 4134c52cad2SJung-uk Kim fprintf (stderr, "Formatted output: %s - %u bytes\n", 4144c52cad2SJung-uk Kim DisasmFilename, AdGetFileSize (File)); 4151a39cfb0SJung-uk Kim } 4161a39cfb0SJung-uk Kim else 4171a39cfb0SJung-uk Kim { 41859db4265SNate Lawson /* Always parse the tables, only option is what to display */ 41959db4265SNate Lawson 420a9f12690SJung-uk Kim Status = AdParseTable (Table, &OwnerId, TRUE, FALSE); 42159db4265SNate Lawson if (ACPI_FAILURE (Status)) 42259db4265SNate Lawson { 42359db4265SNate Lawson AcpiOsPrintf ("Could not parse ACPI tables, %s\n", 42459db4265SNate Lawson AcpiFormatException (Status)); 42559db4265SNate Lawson goto Cleanup; 42659db4265SNate Lawson } 42759db4265SNate Lawson 4281a39cfb0SJung-uk Kim if (AslCompilerdebug) 4291a39cfb0SJung-uk Kim { 4301a39cfb0SJung-uk Kim AcpiOsPrintf ("/**** Before second load\n"); 4311a39cfb0SJung-uk Kim 432*efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 433*efcc2a30SJung-uk Kim NsDisplayNamespace (); 4341a39cfb0SJung-uk Kim AcpiOsPrintf ("*****/\n"); 4351a39cfb0SJung-uk Kim } 4361a39cfb0SJung-uk Kim 437ec3fc72fSJung-uk Kim /* Load namespace from names created within control methods */ 438ec3fc72fSJung-uk Kim 439ec3fc72fSJung-uk Kim AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, 440ec3fc72fSJung-uk Kim AcpiGbl_RootNode, OwnerId); 4411a39cfb0SJung-uk Kim 4421a39cfb0SJung-uk Kim /* 443ec3fc72fSJung-uk Kim * Cross reference the namespace here, in order to 444ec3fc72fSJung-uk Kim * generate External() statements 4451a39cfb0SJung-uk Kim */ 446ec3fc72fSJung-uk Kim AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, 447ec3fc72fSJung-uk Kim AcpiGbl_RootNode, OwnerId); 4481a39cfb0SJung-uk Kim 4491a39cfb0SJung-uk Kim if (AslCompilerdebug) 4501a39cfb0SJung-uk Kim { 4511a39cfb0SJung-uk Kim AcpiDmDumpTree (AcpiGbl_ParseOpRoot); 4521a39cfb0SJung-uk Kim } 4531a39cfb0SJung-uk Kim 4541a39cfb0SJung-uk Kim /* Find possible calls to external control methods */ 4551a39cfb0SJung-uk Kim 4561a39cfb0SJung-uk Kim AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot); 4571a39cfb0SJung-uk Kim 4581a39cfb0SJung-uk Kim /* 459ec3fc72fSJung-uk Kim * If we found any external control methods, we must reparse 460ec3fc72fSJung-uk Kim * the entire tree with the new information (namely, the 461ec3fc72fSJung-uk Kim * number of arguments per method) 4621a39cfb0SJung-uk Kim */ 463f556842eSJung-uk Kim if (AcpiDmGetExternalMethodCount ()) 4641a39cfb0SJung-uk Kim { 4651a39cfb0SJung-uk Kim fprintf (stderr, 466ec3fc72fSJung-uk Kim "\nFound %u external control methods, " 467ec3fc72fSJung-uk Kim "reparsing with new information\n", 468f556842eSJung-uk Kim AcpiDmGetExternalMethodCount ()); 4691a39cfb0SJung-uk Kim 470ec3fc72fSJung-uk Kim /* Reparse, rebuild namespace. no need to xref namespace */ 471ec3fc72fSJung-uk Kim 4721a39cfb0SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 4731a39cfb0SJung-uk Kim AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode); 4741a39cfb0SJung-uk Kim 4751a39cfb0SJung-uk Kim AcpiGbl_RootNode = NULL; 4761a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME; 4771a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED; 4781a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE; 479a88e22b7SJung-uk Kim AcpiGbl_RootNodeStruct.Parent = NULL; 4801a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Child = NULL; 4811a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Peer = NULL; 4821a39cfb0SJung-uk Kim AcpiGbl_RootNodeStruct.Object = NULL; 483a88e22b7SJung-uk Kim AcpiGbl_RootNodeStruct.Flags = 0; 4841a39cfb0SJung-uk Kim 4851a39cfb0SJung-uk Kim Status = AcpiNsRootInitialize (); 486f556842eSJung-uk Kim AcpiDmAddExternalsToNamespace (); 4871a39cfb0SJung-uk Kim 488ec3fc72fSJung-uk Kim /* Parse the table again. No need to reload it, however */ 489a9f12690SJung-uk Kim 490a9f12690SJung-uk Kim Status = AdParseTable (Table, NULL, FALSE, FALSE); 4911a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 4921a39cfb0SJung-uk Kim { 4931a39cfb0SJung-uk Kim AcpiOsPrintf ("Could not parse ACPI tables, %s\n", 4941a39cfb0SJung-uk Kim AcpiFormatException (Status)); 4951a39cfb0SJung-uk Kim goto Cleanup; 4961a39cfb0SJung-uk Kim } 4971a39cfb0SJung-uk Kim 4981a39cfb0SJung-uk Kim if (AslCompilerdebug) 4991a39cfb0SJung-uk Kim { 500a9f12690SJung-uk Kim AcpiOsPrintf ("/**** After second load and resource conversion\n"); 501*efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 502*efcc2a30SJung-uk Kim NsDisplayNamespace (); 503a9f12690SJung-uk Kim AcpiOsPrintf ("*****/\n"); 504a9f12690SJung-uk Kim 5051a39cfb0SJung-uk Kim AcpiDmDumpTree (AcpiGbl_ParseOpRoot); 5061a39cfb0SJung-uk Kim } 5071a39cfb0SJung-uk Kim } 508e0ef747bSNate Lawson 509ec3fc72fSJung-uk Kim /* 510ec3fc72fSJung-uk Kim * Now that the namespace is finalized, we can perform namespace 511ec3fc72fSJung-uk Kim * transforms. 512ec3fc72fSJung-uk Kim * 513ec3fc72fSJung-uk Kim * 1) Convert fixed-offset references to resource descriptors 514ec3fc72fSJung-uk Kim * to symbolic references (Note: modifies namespace) 515ec3fc72fSJung-uk Kim */ 516ec3fc72fSJung-uk Kim AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode); 517ec3fc72fSJung-uk Kim 51859db4265SNate Lawson /* Optional displays */ 51959db4265SNate Lawson 52059db4265SNate Lawson if (AcpiGbl_DbOpt_disasm) 52159db4265SNate Lawson { 5228ef1a331SJung-uk Kim /* This is the real disassembly */ 5238ef1a331SJung-uk Kim 52459db4265SNate Lawson AdDisplayTables (Filename, Table); 5258ef1a331SJung-uk Kim 5268ef1a331SJung-uk Kim /* Dump hex table if requested (-vt) */ 5278ef1a331SJung-uk Kim 5288ef1a331SJung-uk Kim AcpiDmDumpDataTable (Table); 5298ef1a331SJung-uk Kim 5304c52cad2SJung-uk Kim fprintf (stderr, "Disassembly completed\n"); 5314c52cad2SJung-uk Kim fprintf (stderr, "ASL Output: %s - %u bytes\n", 5324c52cad2SJung-uk Kim DisasmFilename, AdGetFileSize (File)); 5331a39cfb0SJung-uk Kim } 53459db4265SNate Lawson } 53559db4265SNate Lawson 53659db4265SNate Lawson Cleanup: 537a9f12690SJung-uk Kim 538a9f12690SJung-uk Kim if (Table && !AcpiUtIsAmlTable (Table)) 539a9f12690SJung-uk Kim { 540a9f12690SJung-uk Kim ACPI_FREE (Table); 541a9f12690SJung-uk Kim } 542a9f12690SJung-uk Kim 543a9f12690SJung-uk Kim if (DisasmFilename) 544a9f12690SJung-uk Kim { 545a9f12690SJung-uk Kim ACPI_FREE (DisasmFilename); 546a9f12690SJung-uk Kim } 547a9f12690SJung-uk Kim 5481a39cfb0SJung-uk Kim if (OutToFile && File) 54959db4265SNate Lawson { 550ec3fc72fSJung-uk Kim if (AslCompilerdebug) /* Display final namespace, with transforms */ 551ec3fc72fSJung-uk Kim { 552*efcc2a30SJung-uk Kim NsSetupNamespaceListing (File); 553*efcc2a30SJung-uk Kim NsDisplayNamespace (); 554ec3fc72fSJung-uk Kim } 555ec3fc72fSJung-uk Kim 55659db4265SNate Lawson fclose (File); 55759db4265SNate Lawson AcpiOsRedirectOutput (stdout); 55859db4265SNate Lawson } 55959db4265SNate Lawson 5601a39cfb0SJung-uk Kim AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot); 561a9f12690SJung-uk Kim AcpiGbl_ParseOpRoot = NULL; 562a9f12690SJung-uk Kim return (Status); 56359db4265SNate Lawson } 56459db4265SNate Lawson 56559db4265SNate Lawson 56659db4265SNate Lawson /****************************************************************************** 56759db4265SNate Lawson * 5681a39cfb0SJung-uk Kim * FUNCTION: AdDisassemblerHeader 5691a39cfb0SJung-uk Kim * 5701a39cfb0SJung-uk Kim * PARAMETERS: Filename - Input file for the table 5711a39cfb0SJung-uk Kim * 5721a39cfb0SJung-uk Kim * RETURN: None 5731a39cfb0SJung-uk Kim * 5741a39cfb0SJung-uk Kim * DESCRIPTION: Create the disassembler header, including ACPI CA signon with 5751a39cfb0SJung-uk Kim * current time and date. 5761a39cfb0SJung-uk Kim * 5771a39cfb0SJung-uk Kim *****************************************************************************/ 5781a39cfb0SJung-uk Kim 5791a39cfb0SJung-uk Kim void 5801a39cfb0SJung-uk Kim AdDisassemblerHeader ( 5811a39cfb0SJung-uk Kim char *Filename) 5821a39cfb0SJung-uk Kim { 5831a39cfb0SJung-uk Kim time_t Timer; 5841a39cfb0SJung-uk Kim 5851a39cfb0SJung-uk Kim time (&Timer); 5861a39cfb0SJung-uk Kim 5871a39cfb0SJung-uk Kim /* Header and input table info */ 5881a39cfb0SJung-uk Kim 5893c1812acSJung-uk Kim AcpiOsPrintf ("/*\n"); 5903c1812acSJung-uk Kim AcpiOsPrintf (ACPI_COMMON_HEADER ("AML Disassembler", " * ")); 5911a39cfb0SJung-uk Kim 5923c1812acSJung-uk Kim AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer)); 5931a39cfb0SJung-uk Kim AcpiOsPrintf (" *\n"); 5941a39cfb0SJung-uk Kim } 5951a39cfb0SJung-uk Kim 5961a39cfb0SJung-uk Kim 5971a39cfb0SJung-uk Kim /****************************************************************************** 5981a39cfb0SJung-uk Kim * 59959db4265SNate Lawson * FUNCTION: AdCreateTableHeader 60059db4265SNate Lawson * 60159db4265SNate Lawson * PARAMETERS: Filename - Input file for the table 60259db4265SNate Lawson * Table - Pointer to the raw table 60359db4265SNate Lawson * 60459db4265SNate Lawson * RETURN: None 60559db4265SNate Lawson * 60659db4265SNate Lawson * DESCRIPTION: Create the ASL table header, including ACPI CA signon with 60759db4265SNate Lawson * current time and date. 60859db4265SNate Lawson * 60959db4265SNate Lawson *****************************************************************************/ 61059db4265SNate Lawson 61142fecd12SJung-uk Kim static void 61259db4265SNate Lawson AdCreateTableHeader ( 61359db4265SNate Lawson char *Filename, 61459db4265SNate Lawson ACPI_TABLE_HEADER *Table) 61559db4265SNate Lawson { 6161a39cfb0SJung-uk Kim char *NewFilename; 617a9f12690SJung-uk Kim UINT8 Checksum; 61859db4265SNate Lawson 61959db4265SNate Lawson 620a9f12690SJung-uk Kim /* 621a9f12690SJung-uk Kim * Print file header and dump original table header 622a9f12690SJung-uk Kim */ 6231a39cfb0SJung-uk Kim AdDisassemblerHeader (Filename); 62459db4265SNate Lawson 625a88e22b7SJung-uk Kim AcpiOsPrintf (" * Original Table Header:\n"); 6261a39cfb0SJung-uk Kim AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature); 6271a39cfb0SJung-uk Kim AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length); 628a9f12690SJung-uk Kim 629a9f12690SJung-uk Kim /* Print and validate the revision */ 630a9f12690SJung-uk Kim 631a9f12690SJung-uk Kim AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision); 632a9f12690SJung-uk Kim 633a9f12690SJung-uk Kim switch (Table->Revision) 634a9f12690SJung-uk Kim { 635a9f12690SJung-uk Kim case 0: 636a9f12690SJung-uk Kim AcpiOsPrintf (" **** Invalid Revision"); 637a9f12690SJung-uk Kim break; 638a9f12690SJung-uk Kim 639a9f12690SJung-uk Kim case 1: 640a9f12690SJung-uk Kim /* Revision of DSDT controls the ACPI integer width */ 641a9f12690SJung-uk Kim 642a9f12690SJung-uk Kim if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT)) 643a9f12690SJung-uk Kim { 644d244b227SJung-uk Kim AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support"); 645a9f12690SJung-uk Kim } 646a9f12690SJung-uk Kim break; 647a9f12690SJung-uk Kim 648a9f12690SJung-uk Kim default: 649a9f12690SJung-uk Kim break; 650a9f12690SJung-uk Kim } 651a9f12690SJung-uk Kim AcpiOsPrintf ("\n"); 652a9f12690SJung-uk Kim 653a9f12690SJung-uk Kim /* Print and validate the table checksum */ 654a9f12690SJung-uk Kim 655a9f12690SJung-uk Kim AcpiOsPrintf (" * Checksum 0x%2.2X", Table->Checksum); 656a9f12690SJung-uk Kim 657a9f12690SJung-uk Kim Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length); 658a9f12690SJung-uk Kim if (Checksum) 659a9f12690SJung-uk Kim { 660a9f12690SJung-uk Kim AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X", 661a9f12690SJung-uk Kim (UINT8) (Table->Checksum - Checksum)); 662a9f12690SJung-uk Kim } 663a9f12690SJung-uk Kim AcpiOsPrintf ("\n"); 664a9f12690SJung-uk Kim 6651a39cfb0SJung-uk Kim AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId); 6661a39cfb0SJung-uk Kim AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId); 6671a39cfb0SJung-uk Kim AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision); 668a9f12690SJung-uk Kim AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId); 669a9f12690SJung-uk Kim AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision); 670a88e22b7SJung-uk Kim AcpiOsPrintf (" */\n\n"); 6711a39cfb0SJung-uk Kim 6721a39cfb0SJung-uk Kim /* Create AML output filename based on input filename */ 6731a39cfb0SJung-uk Kim 6741a39cfb0SJung-uk Kim if (Filename) 6751a39cfb0SJung-uk Kim { 6761a39cfb0SJung-uk Kim NewFilename = FlGenerateFilename (Filename, "aml"); 6771a39cfb0SJung-uk Kim } 6781a39cfb0SJung-uk Kim else 6791a39cfb0SJung-uk Kim { 6801a39cfb0SJung-uk Kim NewFilename = ACPI_ALLOCATE_ZEROED (9); 6811a39cfb0SJung-uk Kim strncat (NewFilename, Table->Signature, 4); 6821a39cfb0SJung-uk Kim strcat (NewFilename, ".aml"); 6831a39cfb0SJung-uk Kim } 6841a39cfb0SJung-uk Kim 6851a39cfb0SJung-uk Kim /* Open the ASL definition block */ 68659db4265SNate Lawson 68759db4265SNate Lawson AcpiOsPrintf ( 688a88e22b7SJung-uk Kim "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n", 6891a39cfb0SJung-uk Kim NewFilename, Table->Signature, Table->Revision, 69059db4265SNate Lawson Table->OemId, Table->OemTableId, Table->OemRevision); 691a9f12690SJung-uk Kim 692a9f12690SJung-uk Kim ACPI_FREE (NewFilename); 69359db4265SNate Lawson } 69459db4265SNate Lawson 69559db4265SNate Lawson 69659db4265SNate Lawson /****************************************************************************** 69759db4265SNate Lawson * 69859db4265SNate Lawson * FUNCTION: AdDisplayTables 69959db4265SNate Lawson * 70059db4265SNate Lawson * PARAMETERS: Filename - Input file for the table 701fba7fc7eSJung-uk Kim * Table - Pointer to the raw table 70259db4265SNate Lawson * 70359db4265SNate Lawson * RETURN: Status 70459db4265SNate Lawson * 70559db4265SNate Lawson * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables 70659db4265SNate Lawson * 70759db4265SNate Lawson *****************************************************************************/ 70859db4265SNate Lawson 70959db4265SNate Lawson ACPI_STATUS 71059db4265SNate Lawson AdDisplayTables ( 71159db4265SNate Lawson char *Filename, 71259db4265SNate Lawson ACPI_TABLE_HEADER *Table) 71359db4265SNate Lawson { 71459db4265SNate Lawson 71559db4265SNate Lawson 7161a39cfb0SJung-uk Kim if (!AcpiGbl_ParseOpRoot) 71759db4265SNate Lawson { 7188ef1a331SJung-uk Kim return (AE_NOT_EXIST); 71959db4265SNate Lawson } 72059db4265SNate Lawson 72159db4265SNate Lawson if (!AcpiGbl_DbOpt_verbose) 72259db4265SNate Lawson { 72359db4265SNate Lawson AdCreateTableHeader (Filename, Table); 72459db4265SNate Lawson } 72559db4265SNate Lawson 7261a39cfb0SJung-uk Kim AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX); 72759db4265SNate Lawson 72859db4265SNate Lawson if (AcpiGbl_DbOpt_verbose) 72959db4265SNate Lawson { 73059db4265SNate Lawson AcpiOsPrintf ("\n\nTable Header:\n"); 7318ef1a331SJung-uk Kim AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER), 73259db4265SNate Lawson DB_BYTE_DISPLAY, ACPI_UINT32_MAX); 73359db4265SNate Lawson 73459db4265SNate Lawson AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length); 7358ef1a331SJung-uk Kim AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), 7368ef1a331SJung-uk Kim Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX); 73759db4265SNate Lawson } 73859db4265SNate Lawson 7398ef1a331SJung-uk Kim return (AE_OK); 74059db4265SNate Lawson } 74159db4265SNate Lawson 74259db4265SNate Lawson 74359db4265SNate Lawson /****************************************************************************** 74459db4265SNate Lawson * 74559db4265SNate Lawson * FUNCTION: AdGetLocalTables 74659db4265SNate Lawson * 747fba7fc7eSJung-uk Kim * PARAMETERS: Filename - Not used 748fba7fc7eSJung-uk Kim * GetAllTables - TRUE if all tables are desired 74959db4265SNate Lawson * 750fba7fc7eSJung-uk Kim * RETURN: Status 75159db4265SNate Lawson * 75259db4265SNate Lawson * DESCRIPTION: Get the ACPI tables from either memory or a file 75359db4265SNate Lawson * 75459db4265SNate Lawson *****************************************************************************/ 75559db4265SNate Lawson 75659db4265SNate Lawson ACPI_STATUS 75759db4265SNate Lawson AdGetLocalTables ( 75859db4265SNate Lawson char *Filename, 75959db4265SNate Lawson BOOLEAN GetAllTables) 76059db4265SNate Lawson { 76159db4265SNate Lawson ACPI_STATUS Status; 76259db4265SNate Lawson ACPI_TABLE_HEADER TableHeader; 76359db4265SNate Lawson ACPI_TABLE_HEADER *NewTable; 76459db4265SNate Lawson UINT32 NumTables; 76559db4265SNate Lawson UINT32 PointerSize; 766a9f12690SJung-uk Kim UINT32 TableIndex; 76759db4265SNate Lawson 76859db4265SNate Lawson 76959db4265SNate Lawson if (GetAllTables) 77059db4265SNate Lawson { 7711a39cfb0SJung-uk Kim ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT); 77259db4265SNate Lawson AcpiOsTableOverride (&TableHeader, &NewTable); 773e50beb51SNate Lawson if (!NewTable) 774e50beb51SNate Lawson { 775e50beb51SNate Lawson fprintf (stderr, "Could not obtain RSDT\n"); 7768ef1a331SJung-uk Kim return (AE_NO_ACPI_TABLES); 777e50beb51SNate Lawson } 778a9f12690SJung-uk Kim else 779a9f12690SJung-uk Kim { 780a9f12690SJung-uk Kim AdWriteTable (NewTable, NewTable->Length, 781a9f12690SJung-uk Kim ACPI_SIG_RSDT, NewTable->OemTableId); 782a9f12690SJung-uk Kim } 78359db4265SNate Lawson 7841a39cfb0SJung-uk Kim if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT)) 78559db4265SNate Lawson { 78659db4265SNate Lawson PointerSize = sizeof (UINT32); 78759db4265SNate Lawson } 78859db4265SNate Lawson else 78959db4265SNate Lawson { 79059db4265SNate Lawson PointerSize = sizeof (UINT64); 79159db4265SNate Lawson } 79259db4265SNate Lawson 79359db4265SNate Lawson /* 79459db4265SNate Lawson * Determine the number of tables pointed to by the RSDT/XSDT. 79559db4265SNate Lawson * This is defined by the ACPI Specification to be the number of 79659db4265SNate Lawson * pointers contained within the RSDT/XSDT. The size of the pointers 79759db4265SNate Lawson * is architecture-dependent. 79859db4265SNate Lawson */ 79959db4265SNate Lawson NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize; 800a88e22b7SJung-uk Kim AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n", 80159db4265SNate Lawson NumTables, NewTable->Signature); 80259db4265SNate Lawson 80359db4265SNate Lawson /* Get the FADT */ 80459db4265SNate Lawson 8051a39cfb0SJung-uk Kim ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT); 80659db4265SNate Lawson AcpiOsTableOverride (&TableHeader, &NewTable); 80759db4265SNate Lawson if (NewTable) 80859db4265SNate Lawson { 80959db4265SNate Lawson AdWriteTable (NewTable, NewTable->Length, 8101a39cfb0SJung-uk Kim ACPI_SIG_FADT, NewTable->OemTableId); 81159db4265SNate Lawson } 81259db4265SNate Lawson AcpiOsPrintf ("\n"); 81359db4265SNate Lawson 8141a39cfb0SJung-uk Kim /* Don't bother with FACS, it is usually all zeros */ 81559db4265SNate Lawson } 81659db4265SNate Lawson 81759db4265SNate Lawson /* Always get the DSDT */ 81859db4265SNate Lawson 8191a39cfb0SJung-uk Kim ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT); 82059db4265SNate Lawson AcpiOsTableOverride (&TableHeader, &NewTable); 82159db4265SNate Lawson if (NewTable) 82259db4265SNate Lawson { 8231a39cfb0SJung-uk Kim AdWriteTable (NewTable, NewTable->Length, 8241a39cfb0SJung-uk Kim ACPI_SIG_DSDT, NewTable->OemTableId); 8251a39cfb0SJung-uk Kim 8261a39cfb0SJung-uk Kim /* Store DSDT in the Table Manager */ 8271a39cfb0SJung-uk Kim 8281a39cfb0SJung-uk Kim Status = AcpiTbStoreTable (0, NewTable, NewTable->Length, 8291a39cfb0SJung-uk Kim 0, &TableIndex); 830f556842eSJung-uk Kim if (ACPI_FAILURE (Status)) 831f556842eSJung-uk Kim { 832f556842eSJung-uk Kim fprintf (stderr, "Could not store DSDT\n"); 8338ef1a331SJung-uk Kim return (AE_NO_ACPI_TABLES); 834f556842eSJung-uk Kim } 83559db4265SNate Lawson } 83659db4265SNate Lawson else 83759db4265SNate Lawson { 83859db4265SNate Lawson fprintf (stderr, "Could not obtain DSDT\n"); 8398ef1a331SJung-uk Kim return (AE_NO_ACPI_TABLES); 84059db4265SNate Lawson } 84159db4265SNate Lawson 8421a39cfb0SJung-uk Kim #if 0 8431a39cfb0SJung-uk Kim /* TBD: Future implementation */ 8441a39cfb0SJung-uk Kim 84559db4265SNate Lawson AcpiOsPrintf ("\n"); 84659db4265SNate Lawson 84759db4265SNate Lawson /* Get all SSDTs */ 84859db4265SNate Lawson 8491a39cfb0SJung-uk Kim ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT); 8501a39cfb0SJung-uk Kim do 85159db4265SNate Lawson { 8521a39cfb0SJung-uk Kim NewTable = NULL; 85359db4265SNate Lawson Status = AcpiOsTableOverride (&TableHeader, &NewTable); 8541a39cfb0SJung-uk Kim 8551a39cfb0SJung-uk Kim } while (NewTable); 8561a39cfb0SJung-uk Kim #endif 85759db4265SNate Lawson 8588ef1a331SJung-uk Kim return (AE_OK); 85959db4265SNate Lawson } 86059db4265SNate Lawson 8611a39cfb0SJung-uk Kim 86259db4265SNate Lawson /****************************************************************************** 86359db4265SNate Lawson * 86459db4265SNate Lawson * FUNCTION: AdParseTable 86559db4265SNate Lawson * 866fba7fc7eSJung-uk Kim * PARAMETERS: Table - Pointer to the raw table 867a9f12690SJung-uk Kim * OwnerId - Returned OwnerId of the table 868a9f12690SJung-uk Kim * LoadTable - If add table to the global table list 869a9f12690SJung-uk Kim * External - If this is an external table 87059db4265SNate Lawson * 87159db4265SNate Lawson * RETURN: Status 87259db4265SNate Lawson * 87359db4265SNate Lawson * DESCRIPTION: Parse the DSDT. 87459db4265SNate Lawson * 87559db4265SNate Lawson *****************************************************************************/ 87659db4265SNate Lawson 87759db4265SNate Lawson ACPI_STATUS 87859db4265SNate Lawson AdParseTable ( 879a9f12690SJung-uk Kim ACPI_TABLE_HEADER *Table, 880a9f12690SJung-uk Kim ACPI_OWNER_ID *OwnerId, 881a9f12690SJung-uk Kim BOOLEAN LoadTable, 882a9f12690SJung-uk Kim BOOLEAN External) 88359db4265SNate Lawson { 88459db4265SNate Lawson ACPI_STATUS Status = AE_OK; 88559db4265SNate Lawson ACPI_WALK_STATE *WalkState; 88659db4265SNate Lawson UINT8 *AmlStart; 88759db4265SNate Lawson UINT32 AmlLength; 888a9f12690SJung-uk Kim UINT32 TableIndex; 88959db4265SNate Lawson 89059db4265SNate Lawson 89159db4265SNate Lawson if (!Table) 89259db4265SNate Lawson { 8938ef1a331SJung-uk Kim return (AE_NOT_EXIST); 89459db4265SNate Lawson } 89559db4265SNate Lawson 89659db4265SNate Lawson /* Pass 1: Parse everything except control method bodies */ 89759db4265SNate Lawson 89859db4265SNate Lawson fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature); 89959db4265SNate Lawson 90059db4265SNate Lawson AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER); 90159db4265SNate Lawson AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)); 90259db4265SNate Lawson 90359db4265SNate Lawson /* Create the root object */ 90459db4265SNate Lawson 9051a39cfb0SJung-uk Kim AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (); 9061a39cfb0SJung-uk Kim if (!AcpiGbl_ParseOpRoot) 90759db4265SNate Lawson { 9088ef1a331SJung-uk Kim return (AE_NO_MEMORY); 90959db4265SNate Lawson } 91059db4265SNate Lawson 91159db4265SNate Lawson /* Create and initialize a new walk state */ 91259db4265SNate Lawson 91359db4265SNate Lawson WalkState = AcpiDsCreateWalkState (0, 9141a39cfb0SJung-uk Kim AcpiGbl_ParseOpRoot, NULL, NULL); 91559db4265SNate Lawson if (!WalkState) 91659db4265SNate Lawson { 91759db4265SNate Lawson return (AE_NO_MEMORY); 91859db4265SNate Lawson } 91959db4265SNate Lawson 9201a39cfb0SJung-uk Kim Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot, 9211a39cfb0SJung-uk Kim NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1); 92259db4265SNate Lawson if (ACPI_FAILURE (Status)) 92359db4265SNate Lawson { 92459db4265SNate Lawson return (Status); 92559db4265SNate Lawson } 92659db4265SNate Lawson 92759db4265SNate Lawson WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE; 928fba7fc7eSJung-uk Kim WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE; 92959db4265SNate Lawson 93059db4265SNate Lawson Status = AcpiPsParseAml (WalkState); 93159db4265SNate Lawson if (ACPI_FAILURE (Status)) 93259db4265SNate Lawson { 9338ef1a331SJung-uk Kim return (Status); 93459db4265SNate Lawson } 93559db4265SNate Lawson 936a9f12690SJung-uk Kim /* If LoadTable is FALSE, we are parsing the last loaded table */ 937a9f12690SJung-uk Kim 9383f5e024cSJung-uk Kim TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1; 939a9f12690SJung-uk Kim 94059db4265SNate Lawson /* Pass 2 */ 94159db4265SNate Lawson 942a9f12690SJung-uk Kim if (LoadTable) 943a9f12690SJung-uk Kim { 944a9f12690SJung-uk Kim Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table, 9451a39cfb0SJung-uk Kim Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex); 9461a39cfb0SJung-uk Kim if (ACPI_FAILURE (Status)) 9471a39cfb0SJung-uk Kim { 9488ef1a331SJung-uk Kim return (Status); 9491a39cfb0SJung-uk Kim } 950a9f12690SJung-uk Kim Status = AcpiTbAllocateOwnerId (TableIndex); 951a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 952a9f12690SJung-uk Kim { 9538ef1a331SJung-uk Kim return (Status); 954a9f12690SJung-uk Kim } 955a9f12690SJung-uk Kim if (OwnerId) 956a9f12690SJung-uk Kim { 957a9f12690SJung-uk Kim Status = AcpiTbGetOwnerId (TableIndex, OwnerId); 958a9f12690SJung-uk Kim if (ACPI_FAILURE (Status)) 959a9f12690SJung-uk Kim { 9608ef1a331SJung-uk Kim return (Status); 961a9f12690SJung-uk Kim } 962a9f12690SJung-uk Kim } 963a9f12690SJung-uk Kim } 96459db4265SNate Lawson 9651a39cfb0SJung-uk Kim fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature); 9661a39cfb0SJung-uk Kim 967a9f12690SJung-uk Kim Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL); 96859db4265SNate Lawson if (ACPI_FAILURE (Status)) 96959db4265SNate Lawson { 97059db4265SNate Lawson return (Status); 97159db4265SNate Lawson } 97259db4265SNate Lawson 973a9f12690SJung-uk Kim /* No need to parse control methods of external table */ 974a9f12690SJung-uk Kim 975a9f12690SJung-uk Kim if (External) 976a9f12690SJung-uk Kim { 9778ef1a331SJung-uk Kim return (AE_OK); 978a9f12690SJung-uk Kim } 979a9f12690SJung-uk Kim 98059db4265SNate Lawson /* Pass 3: Parse control methods and link their parse trees into the main parse tree */ 98159db4265SNate Lawson 982ed17e06eSJung-uk Kim fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n"); 983ed17e06eSJung-uk Kim Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot); 984ed17e06eSJung-uk Kim fprintf (stderr, "\n"); 9851a39cfb0SJung-uk Kim 9861a39cfb0SJung-uk Kim /* Process Resource Templates */ 9871a39cfb0SJung-uk Kim 9881a39cfb0SJung-uk Kim AcpiDmFindResources (AcpiGbl_ParseOpRoot); 98959db4265SNate Lawson 99059db4265SNate Lawson fprintf (stderr, "Parsing completed\n"); 9918ef1a331SJung-uk Kim return (AE_OK); 99259db4265SNate Lawson } 993