xref: /freebsd/sys/contrib/dev/acpica/common/adisasm.c (revision 7cf3e94a41ba78bb319589610ad72bf914dc75c1)
159db4265SNate Lawson /******************************************************************************
259db4265SNate Lawson  *
359db4265SNate Lawson  * Module Name: adisasm - Application-level disassembler routines
459db4265SNate Lawson  *
559db4265SNate Lawson  *****************************************************************************/
659db4265SNate Lawson 
7d244b227SJung-uk Kim /*
81c0e1b6dSJung-uk Kim  * Copyright (C) 2000 - 2015, 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/acparser.h>
46ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
47ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h>
48ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
49ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
50ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
51ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
5259db4265SNate Lawson 
5359db4265SNate Lawson #include <stdio.h>
5459db4265SNate Lawson #include <time.h>
5559db4265SNate Lawson 
5659db4265SNate Lawson 
5759db4265SNate Lawson #define _COMPONENT          ACPI_TOOLS
5859db4265SNate Lawson         ACPI_MODULE_NAME    ("adisasm")
5959db4265SNate Lawson 
601a39cfb0SJung-uk Kim /* Local prototypes */
611a39cfb0SJung-uk Kim 
6242fecd12SJung-uk Kim static void
631a39cfb0SJung-uk Kim AdCreateTableHeader (
641a39cfb0SJung-uk Kim     char                    *Filename,
651a39cfb0SJung-uk Kim     ACPI_TABLE_HEADER       *Table);
661a39cfb0SJung-uk Kim 
67*7cf3e94aSJung-uk Kim static ACPI_STATUS
68*7cf3e94aSJung-uk Kim AdStoreTable (
69*7cf3e94aSJung-uk Kim     ACPI_TABLE_HEADER       *Table,
70*7cf3e94aSJung-uk Kim     UINT32                  *TableIndex);
71*7cf3e94aSJung-uk Kim 
721a39cfb0SJung-uk Kim /* Stubs for ASL compiler */
7359db4265SNate Lawson 
74fba7fc7eSJung-uk Kim #ifndef ACPI_ASL_COMPILER
7559db4265SNate Lawson BOOLEAN
7659db4265SNate Lawson AcpiDsIsResultUsed (
7759db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
7859db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
7959db4265SNate Lawson {
8059db4265SNate Lawson     return TRUE;
8159db4265SNate Lawson }
821a39cfb0SJung-uk Kim 
831a39cfb0SJung-uk Kim ACPI_STATUS
841a39cfb0SJung-uk Kim AcpiDsMethodError (
851a39cfb0SJung-uk Kim     ACPI_STATUS             Status,
861a39cfb0SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
871a39cfb0SJung-uk Kim {
881a39cfb0SJung-uk Kim     return (Status);
891a39cfb0SJung-uk Kim }
9059db4265SNate Lawson #endif
9159db4265SNate Lawson 
9259db4265SNate Lawson ACPI_STATUS
931a39cfb0SJung-uk Kim AcpiNsLoadTable (
94a9f12690SJung-uk Kim     UINT32                  TableIndex,
951a39cfb0SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node)
961a39cfb0SJung-uk Kim {
971a39cfb0SJung-uk Kim     return (AE_NOT_IMPLEMENTED);
981a39cfb0SJung-uk Kim }
991a39cfb0SJung-uk Kim 
1001a39cfb0SJung-uk Kim ACPI_STATUS
10159db4265SNate Lawson AcpiDsRestartControlMethod (
10259db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
10359db4265SNate Lawson     ACPI_OPERAND_OBJECT     *ReturnDesc)
10459db4265SNate Lawson {
10559db4265SNate Lawson     return (AE_OK);
10659db4265SNate Lawson }
10759db4265SNate Lawson 
108fba7fc7eSJung-uk Kim void
10959db4265SNate Lawson AcpiDsTerminateControlMethod (
1101a39cfb0SJung-uk Kim     ACPI_OPERAND_OBJECT     *MethodDesc,
11159db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
11259db4265SNate Lawson {
113fba7fc7eSJung-uk Kim     return;
11459db4265SNate Lawson }
11559db4265SNate Lawson 
11659db4265SNate Lawson ACPI_STATUS
11759db4265SNate Lawson AcpiDsCallControlMethod (
11859db4265SNate Lawson     ACPI_THREAD_STATE       *Thread,
11959db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
12059db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op)
12159db4265SNate Lawson {
12259db4265SNate Lawson     return (AE_OK);
12359db4265SNate Lawson }
12459db4265SNate Lawson 
12559db4265SNate Lawson ACPI_STATUS
12659db4265SNate Lawson AcpiDsMethodDataInitArgs (
12759db4265SNate Lawson     ACPI_OPERAND_OBJECT     **Params,
12859db4265SNate Lawson     UINT32                  MaxParamCount,
12959db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
13059db4265SNate Lawson {
13159db4265SNate Lawson     return (AE_OK);
13259db4265SNate Lawson }
13359db4265SNate Lawson 
13459db4265SNate Lawson 
135f556842eSJung-uk Kim static ACPI_TABLE_DESC      LocalTables[1];
136313a0c13SJung-uk Kim ACPI_PARSE_OBJECT    *AcpiGbl_ParseOpRoot;
1374c52cad2SJung-uk Kim 
1384c52cad2SJung-uk Kim 
1394c52cad2SJung-uk Kim /*******************************************************************************
1404c52cad2SJung-uk Kim  *
14159db4265SNate Lawson  * FUNCTION:    AdInitialize
14259db4265SNate Lawson  *
143f556842eSJung-uk Kim  * PARAMETERS:  None
14459db4265SNate Lawson  *
14559db4265SNate Lawson  * RETURN:      Status
14659db4265SNate Lawson  *
147f556842eSJung-uk Kim  * DESCRIPTION: ACPICA and local initialization
14859db4265SNate Lawson  *
14959db4265SNate Lawson  ******************************************************************************/
15059db4265SNate Lawson 
15159db4265SNate Lawson ACPI_STATUS
15259db4265SNate Lawson AdInitialize (
15359db4265SNate Lawson     void)
15459db4265SNate Lawson {
15559db4265SNate Lawson     ACPI_STATUS             Status;
15659db4265SNate Lawson 
15759db4265SNate Lawson 
15859db4265SNate Lawson     /* ACPICA subsystem initialization */
15959db4265SNate Lawson 
1601a39cfb0SJung-uk Kim     Status = AcpiOsInitialize ();
161a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
162a9f12690SJung-uk Kim     {
163a9f12690SJung-uk Kim         return (Status);
164a9f12690SJung-uk Kim     }
165a9f12690SJung-uk Kim 
166a9f12690SJung-uk Kim     Status = AcpiUtInitGlobals ();
167a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
168a9f12690SJung-uk Kim     {
169a9f12690SJung-uk Kim         return (Status);
170a9f12690SJung-uk Kim     }
1711a39cfb0SJung-uk Kim 
17259db4265SNate Lawson     Status = AcpiUtMutexInitialize ();
17359db4265SNate Lawson     if (ACPI_FAILURE (Status))
17459db4265SNate Lawson     {
175a9f12690SJung-uk Kim         return (Status);
17659db4265SNate Lawson     }
17759db4265SNate Lawson 
17859db4265SNate Lawson     Status = AcpiNsRootInitialize ();
1791a39cfb0SJung-uk Kim     if (ACPI_FAILURE (Status))
1801a39cfb0SJung-uk Kim     {
181a9f12690SJung-uk Kim         return (Status);
1821a39cfb0SJung-uk Kim     }
1831a39cfb0SJung-uk Kim 
1841a39cfb0SJung-uk Kim     /* Setup the Table Manager (cheat - there is no RSDT) */
1851a39cfb0SJung-uk Kim 
1863f5e024cSJung-uk Kim     AcpiGbl_RootTableList.MaxTableCount = 1;
1873f5e024cSJung-uk Kim     AcpiGbl_RootTableList.CurrentTableCount = 0;
1881a39cfb0SJung-uk Kim     AcpiGbl_RootTableList.Tables = LocalTables;
1891a39cfb0SJung-uk Kim 
190a9f12690SJung-uk Kim     return (Status);
19159db4265SNate Lawson }
19259db4265SNate Lawson 
19359db4265SNate Lawson 
19459db4265SNate Lawson /******************************************************************************
19559db4265SNate Lawson  *
19659db4265SNate Lawson  * FUNCTION:    AdAmlDisassemble
19759db4265SNate Lawson  *
198fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename            - AML input filename
199fba7fc7eSJung-uk Kim  *              OutToFile           - TRUE if output should go to a file
200fba7fc7eSJung-uk Kim  *              Prefix              - Path prefix for output
201fba7fc7eSJung-uk Kim  *              OutFilename         - where the filename is returned
20259db4265SNate Lawson  *
20359db4265SNate Lawson  * RETURN:      Status
20459db4265SNate Lawson  *
20559db4265SNate Lawson  * DESCRIPTION: Disassemble an entire ACPI table
20659db4265SNate Lawson  *
20759db4265SNate Lawson  *****************************************************************************/
20859db4265SNate Lawson 
20959db4265SNate Lawson ACPI_STATUS
21059db4265SNate Lawson AdAmlDisassemble (
21159db4265SNate Lawson     BOOLEAN                 OutToFile,
21259db4265SNate Lawson     char                    *Filename,
21359db4265SNate Lawson     char                    *Prefix,
214313a0c13SJung-uk Kim     char                    **OutFilename)
21559db4265SNate Lawson {
21659db4265SNate Lawson     ACPI_STATUS             Status;
21759db4265SNate Lawson     char                    *DisasmFilename = NULL;
218a9f12690SJung-uk Kim     char                    *ExternalFilename;
219709fac06SJung-uk Kim     ACPI_EXTERNAL_FILE      *ExternalFileList = AcpiGbl_ExternalFileList;
22059db4265SNate Lawson     FILE                    *File = NULL;
221a9f12690SJung-uk Kim     ACPI_TABLE_HEADER       *Table = NULL;
2221a39cfb0SJung-uk Kim     ACPI_TABLE_HEADER       *ExternalTable;
223a9f12690SJung-uk Kim     ACPI_OWNER_ID           OwnerId;
22459db4265SNate Lawson 
22559db4265SNate Lawson 
22659db4265SNate Lawson     /*
227f556842eSJung-uk Kim      * Input: AML code from either a file or via GetTables (memory or
228f556842eSJung-uk Kim      * registry)
22959db4265SNate Lawson      */
23059db4265SNate Lawson     if (Filename)
23159db4265SNate Lawson     {
23259db4265SNate Lawson         Status = AcpiDbGetTableFromFile (Filename, &Table);
23359db4265SNate Lawson         if (ACPI_FAILURE (Status))
23459db4265SNate Lawson         {
2358ef1a331SJung-uk Kim             return (Status);
23659db4265SNate Lawson         }
2371a39cfb0SJung-uk Kim 
238a9f12690SJung-uk Kim         /*
239a9f12690SJung-uk Kim          * External filenames separated by commas
240a9f12690SJung-uk Kim          * Example: iasl -e file1,file2,file3 -d xxx.aml
241a9f12690SJung-uk Kim          */
242709fac06SJung-uk Kim         while (ExternalFileList)
2431a39cfb0SJung-uk Kim         {
244709fac06SJung-uk Kim             ExternalFilename = ExternalFileList->Path;
245709fac06SJung-uk Kim             if (!ACPI_STRCMP (ExternalFilename, Filename))
246709fac06SJung-uk Kim             {
247709fac06SJung-uk Kim                 /* Next external file */
248a9f12690SJung-uk Kim 
249709fac06SJung-uk Kim                 ExternalFileList = ExternalFileList->Next;
250709fac06SJung-uk Kim                 continue;
251709fac06SJung-uk Kim             }
252709fac06SJung-uk Kim 
253a9f12690SJung-uk Kim             Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
2541a39cfb0SJung-uk Kim             if (ACPI_FAILURE (Status))
2551a39cfb0SJung-uk Kim             {
2568ef1a331SJung-uk Kim                 return (Status);
2571a39cfb0SJung-uk Kim             }
258a9f12690SJung-uk Kim 
259a9f12690SJung-uk Kim             /* Load external table for symbol resolution */
260a9f12690SJung-uk Kim 
261a9f12690SJung-uk Kim             if (ExternalTable)
262a9f12690SJung-uk Kim             {
263a9f12690SJung-uk Kim                 Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
264a9f12690SJung-uk Kim                 if (ACPI_FAILURE (Status))
265a9f12690SJung-uk Kim                 {
266a9f12690SJung-uk Kim                     AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
267a9f12690SJung-uk Kim                         AcpiFormatException (Status));
2688ef1a331SJung-uk Kim                     return (Status);
269a9f12690SJung-uk Kim                 }
270a9f12690SJung-uk Kim 
271a9f12690SJung-uk Kim                 /*
272a9f12690SJung-uk Kim                  * Load namespace from names created within control methods
273a9f12690SJung-uk Kim                  * Set owner id of nodes in external table
274a9f12690SJung-uk Kim                  */
275a9f12690SJung-uk Kim                 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
276a9f12690SJung-uk Kim                     AcpiGbl_RootNode, OwnerId);
277a9f12690SJung-uk Kim                 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
278a9f12690SJung-uk Kim             }
279a9f12690SJung-uk Kim 
280709fac06SJung-uk Kim             /* Next external file */
281a9f12690SJung-uk Kim 
282709fac06SJung-uk Kim             ExternalFileList = ExternalFileList->Next;
283a9f12690SJung-uk Kim         }
284a9f12690SJung-uk Kim 
285a9f12690SJung-uk Kim         /* Clear external list generated by Scope in external tables */
286a9f12690SJung-uk Kim 
287709fac06SJung-uk Kim         if (AcpiGbl_ExternalFileList)
288709fac06SJung-uk Kim         {
289f556842eSJung-uk Kim             AcpiDmClearExternalList ();
2901a39cfb0SJung-uk Kim         }
29179c6d946SJung-uk Kim 
29279c6d946SJung-uk Kim         /* Load any externals defined in the optional external ref file */
29379c6d946SJung-uk Kim 
29479c6d946SJung-uk Kim         AcpiDmGetExternalsFromFile ();
29559db4265SNate Lawson     }
29659db4265SNate Lawson     else
29759db4265SNate Lawson     {
298313a0c13SJung-uk Kim         Status = AdGetLocalTables ();
29959db4265SNate Lawson         if (ACPI_FAILURE (Status))
30059db4265SNate Lawson         {
30159db4265SNate Lawson             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
30259db4265SNate Lawson                 AcpiFormatException (Status));
3038ef1a331SJung-uk Kim             return (Status);
30459db4265SNate Lawson         }
30559db4265SNate Lawson 
306*7cf3e94aSJung-uk Kim         if (!AcpiGbl_DbOpt_Disasm)
30759db4265SNate Lawson         {
3088ef1a331SJung-uk Kim             return (AE_OK);
30959db4265SNate Lawson         }
31059db4265SNate Lawson 
3111a39cfb0SJung-uk Kim         /* Obtained the local tables, just disassemble the DSDT */
31259db4265SNate Lawson 
3131a39cfb0SJung-uk Kim         Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
3141a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
3151a39cfb0SJung-uk Kim         {
3161a39cfb0SJung-uk Kim             AcpiOsPrintf ("Could not get DSDT, %s\n",
3171a39cfb0SJung-uk Kim                 AcpiFormatException (Status));
3188ef1a331SJung-uk Kim             return (Status);
3191a39cfb0SJung-uk Kim         }
3201a39cfb0SJung-uk Kim 
32159db4265SNate Lawson         AcpiOsPrintf ("\nDisassembly of DSDT\n");
3221a39cfb0SJung-uk Kim         Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
32359db4265SNate Lawson     }
32459db4265SNate Lawson 
32559db4265SNate Lawson     /*
326f556842eSJung-uk Kim      * Output: ASL code. Redirect to a file if requested
32759db4265SNate Lawson      */
32859db4265SNate Lawson     if (OutToFile)
32959db4265SNate Lawson     {
33059db4265SNate Lawson         /* Create/Open a disassembly output file */
33159db4265SNate Lawson 
33259db4265SNate Lawson         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
333313a0c13SJung-uk Kim         if (!DisasmFilename)
33459db4265SNate Lawson         {
33559db4265SNate Lawson             fprintf (stderr, "Could not generate output filename\n");
336e50beb51SNate Lawson             Status = AE_ERROR;
337e50beb51SNate Lawson             goto Cleanup;
33859db4265SNate Lawson         }
33959db4265SNate Lawson 
34059db4265SNate Lawson         File = fopen (DisasmFilename, "w+");
34159db4265SNate Lawson         if (!File)
34259db4265SNate Lawson         {
3431a39cfb0SJung-uk Kim             fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
344e50beb51SNate Lawson             Status = AE_ERROR;
345e50beb51SNate Lawson             goto Cleanup;
34659db4265SNate Lawson         }
34759db4265SNate Lawson 
34859db4265SNate Lawson         AcpiOsRedirectOutput (File);
34959db4265SNate Lawson     }
35059db4265SNate Lawson 
35159db4265SNate Lawson     *OutFilename = DisasmFilename;
35259db4265SNate Lawson 
353*7cf3e94aSJung-uk Kim     /* ForceAmlDisassembly means to assume the table contains valid AML */
354*7cf3e94aSJung-uk Kim 
355*7cf3e94aSJung-uk Kim     if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table))
3561a39cfb0SJung-uk Kim     {
357*7cf3e94aSJung-uk Kim         AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE);
3581a39cfb0SJung-uk Kim         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
3591a39cfb0SJung-uk Kim             Table->Signature);
360ec3fc72fSJung-uk Kim         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  "
361ec3fc72fSJung-uk Kim             "FieldName : FieldValue\n */\n\n");
3621a39cfb0SJung-uk Kim 
3631a39cfb0SJung-uk Kim         AcpiDmDumpDataTable (Table);
3644c52cad2SJung-uk Kim         fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
3654c52cad2SJung-uk Kim             Table->Signature);
3661c0e1b6dSJung-uk Kim 
3671c0e1b6dSJung-uk Kim         if (File)
3681c0e1b6dSJung-uk Kim         {
3694c52cad2SJung-uk Kim             fprintf (stderr, "Formatted output:  %s - %u bytes\n",
370313a0c13SJung-uk Kim                 DisasmFilename, CmGetFileSize (File));
3711a39cfb0SJung-uk Kim         }
3721c0e1b6dSJung-uk Kim     }
3731a39cfb0SJung-uk Kim     else
3741a39cfb0SJung-uk Kim     {
37559db4265SNate Lawson         /* Always parse the tables, only option is what to display */
37659db4265SNate Lawson 
377a9f12690SJung-uk Kim         Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
37859db4265SNate Lawson         if (ACPI_FAILURE (Status))
37959db4265SNate Lawson         {
38059db4265SNate Lawson             AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
38159db4265SNate Lawson                 AcpiFormatException (Status));
38259db4265SNate Lawson             goto Cleanup;
38359db4265SNate Lawson         }
38459db4265SNate Lawson 
3851a39cfb0SJung-uk Kim         if (AslCompilerdebug)
3861a39cfb0SJung-uk Kim         {
3871a39cfb0SJung-uk Kim             AcpiOsPrintf ("/**** Before second load\n");
3881a39cfb0SJung-uk Kim 
3891c0e1b6dSJung-uk Kim             if (File)
3901c0e1b6dSJung-uk Kim             {
391efcc2a30SJung-uk Kim                 NsSetupNamespaceListing (File);
392efcc2a30SJung-uk Kim                 NsDisplayNamespace ();
3931c0e1b6dSJung-uk Kim             }
3941a39cfb0SJung-uk Kim             AcpiOsPrintf ("*****/\n");
3951a39cfb0SJung-uk Kim         }
3961a39cfb0SJung-uk Kim 
397ec3fc72fSJung-uk Kim         /* Load namespace from names created within control methods */
398ec3fc72fSJung-uk Kim 
399ec3fc72fSJung-uk Kim         AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
400ec3fc72fSJung-uk Kim             AcpiGbl_RootNode, OwnerId);
4011a39cfb0SJung-uk Kim 
4021a39cfb0SJung-uk Kim         /*
403ec3fc72fSJung-uk Kim          * Cross reference the namespace here, in order to
404ec3fc72fSJung-uk Kim          * generate External() statements
4051a39cfb0SJung-uk Kim          */
406ec3fc72fSJung-uk Kim         AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
407ec3fc72fSJung-uk Kim             AcpiGbl_RootNode, OwnerId);
4081a39cfb0SJung-uk Kim 
4091a39cfb0SJung-uk Kim         if (AslCompilerdebug)
4101a39cfb0SJung-uk Kim         {
4111a39cfb0SJung-uk Kim             AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
4121a39cfb0SJung-uk Kim         }
4131a39cfb0SJung-uk Kim 
4141a39cfb0SJung-uk Kim         /* Find possible calls to external control methods */
4151a39cfb0SJung-uk Kim 
4161a39cfb0SJung-uk Kim         AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
4171a39cfb0SJung-uk Kim 
4181a39cfb0SJung-uk Kim         /*
419ec3fc72fSJung-uk Kim          * If we found any external control methods, we must reparse
420ec3fc72fSJung-uk Kim          * the entire tree with the new information (namely, the
421ec3fc72fSJung-uk Kim          * number of arguments per method)
4221a39cfb0SJung-uk Kim          */
423f556842eSJung-uk Kim         if (AcpiDmGetExternalMethodCount ())
4241a39cfb0SJung-uk Kim         {
4251a39cfb0SJung-uk Kim             fprintf (stderr,
426ec3fc72fSJung-uk Kim                 "\nFound %u external control methods, "
427ec3fc72fSJung-uk Kim                 "reparsing with new information\n",
428f556842eSJung-uk Kim                 AcpiDmGetExternalMethodCount ());
4291a39cfb0SJung-uk Kim 
430313a0c13SJung-uk Kim             /* Reparse, rebuild namespace */
431ec3fc72fSJung-uk Kim 
4321a39cfb0SJung-uk Kim             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
433313a0c13SJung-uk Kim             AcpiGbl_ParseOpRoot = NULL;
4341a39cfb0SJung-uk Kim             AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
4351a39cfb0SJung-uk Kim 
4361a39cfb0SJung-uk Kim             AcpiGbl_RootNode                    = NULL;
4371a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
4381a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
4391a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
440a88e22b7SJung-uk Kim             AcpiGbl_RootNodeStruct.Parent       = NULL;
4411a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Child        = NULL;
4421a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Peer         = NULL;
4431a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Object       = NULL;
444a88e22b7SJung-uk Kim             AcpiGbl_RootNodeStruct.Flags        = 0;
4451a39cfb0SJung-uk Kim 
4461a39cfb0SJung-uk Kim             Status = AcpiNsRootInitialize ();
447313a0c13SJung-uk Kim 
448313a0c13SJung-uk Kim             /* New namespace, add the external definitions first */
449313a0c13SJung-uk Kim 
450f556842eSJung-uk Kim             AcpiDmAddExternalsToNamespace ();
4511a39cfb0SJung-uk Kim 
452ec3fc72fSJung-uk Kim             /* Parse the table again. No need to reload it, however */
453a9f12690SJung-uk Kim 
454a9f12690SJung-uk Kim             Status = AdParseTable (Table, NULL, FALSE, FALSE);
4551a39cfb0SJung-uk Kim             if (ACPI_FAILURE (Status))
4561a39cfb0SJung-uk Kim             {
4571a39cfb0SJung-uk Kim                 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
4581a39cfb0SJung-uk Kim                     AcpiFormatException (Status));
4591a39cfb0SJung-uk Kim                 goto Cleanup;
4601a39cfb0SJung-uk Kim             }
4611a39cfb0SJung-uk Kim 
462313a0c13SJung-uk Kim             /* Cross reference the namespace again */
463313a0c13SJung-uk Kim 
464313a0c13SJung-uk Kim             AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
465313a0c13SJung-uk Kim                 AcpiGbl_RootNode, OwnerId);
466313a0c13SJung-uk Kim 
467313a0c13SJung-uk Kim             AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
468313a0c13SJung-uk Kim                 AcpiGbl_RootNode, OwnerId);
469313a0c13SJung-uk Kim 
4701a39cfb0SJung-uk Kim             if (AslCompilerdebug)
4711a39cfb0SJung-uk Kim             {
472a9f12690SJung-uk Kim                 AcpiOsPrintf ("/**** After second load and resource conversion\n");
4731c0e1b6dSJung-uk Kim                 if (File)
4741c0e1b6dSJung-uk Kim                 {
475efcc2a30SJung-uk Kim                     NsSetupNamespaceListing (File);
476efcc2a30SJung-uk Kim                     NsDisplayNamespace ();
4771c0e1b6dSJung-uk Kim                 }
478a9f12690SJung-uk Kim                 AcpiOsPrintf ("*****/\n");
479a9f12690SJung-uk Kim 
4801a39cfb0SJung-uk Kim                 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
4811a39cfb0SJung-uk Kim             }
4821a39cfb0SJung-uk Kim         }
483e0ef747bSNate Lawson 
484ec3fc72fSJung-uk Kim         /*
485ec3fc72fSJung-uk Kim          * Now that the namespace is finalized, we can perform namespace
486ec3fc72fSJung-uk Kim          * transforms.
487ec3fc72fSJung-uk Kim          *
488ec3fc72fSJung-uk Kim          * 1) Convert fixed-offset references to resource descriptors
489ec3fc72fSJung-uk Kim          *    to symbolic references (Note: modifies namespace)
490ec3fc72fSJung-uk Kim          */
491ec3fc72fSJung-uk Kim         AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
492ec3fc72fSJung-uk Kim 
49359db4265SNate Lawson         /* Optional displays */
49459db4265SNate Lawson 
495*7cf3e94aSJung-uk Kim         if (AcpiGbl_DbOpt_Disasm)
49659db4265SNate Lawson         {
4978ef1a331SJung-uk Kim             /* This is the real disassembly */
4988ef1a331SJung-uk Kim 
49959db4265SNate Lawson             AdDisplayTables (Filename, Table);
5008ef1a331SJung-uk Kim 
5018ef1a331SJung-uk Kim             /* Dump hex table if requested (-vt) */
5028ef1a331SJung-uk Kim 
5038ef1a331SJung-uk Kim             AcpiDmDumpDataTable (Table);
5048ef1a331SJung-uk Kim 
5054c52cad2SJung-uk Kim             fprintf (stderr, "Disassembly completed\n");
5061c0e1b6dSJung-uk Kim             if (File)
5071c0e1b6dSJung-uk Kim             {
5084c52cad2SJung-uk Kim                 fprintf (stderr, "ASL Output:    %s - %u bytes\n",
509313a0c13SJung-uk Kim                     DisasmFilename, CmGetFileSize (File));
5101c0e1b6dSJung-uk Kim             }
511313a0c13SJung-uk Kim 
512313a0c13SJung-uk Kim             if (Gbl_MapfileFlag)
513313a0c13SJung-uk Kim             {
514313a0c13SJung-uk Kim                 fprintf (stderr, "%14s %s - %u bytes\n",
515313a0c13SJung-uk Kim                     Gbl_Files[ASL_FILE_MAP_OUTPUT].ShortDescription,
516313a0c13SJung-uk Kim                     Gbl_Files[ASL_FILE_MAP_OUTPUT].Filename,
517313a0c13SJung-uk Kim                     FlGetFileSize (ASL_FILE_MAP_OUTPUT));
518313a0c13SJung-uk Kim             }
5191a39cfb0SJung-uk Kim         }
52059db4265SNate Lawson     }
52159db4265SNate Lawson 
52259db4265SNate Lawson Cleanup:
523a9f12690SJung-uk Kim 
524*7cf3e94aSJung-uk Kim     if (Table && !AcpiGbl_ForceAmlDisassembly &&!AcpiUtIsAmlTable (Table))
525a9f12690SJung-uk Kim     {
526a9f12690SJung-uk Kim         ACPI_FREE (Table);
527a9f12690SJung-uk Kim     }
528a9f12690SJung-uk Kim 
5291c0e1b6dSJung-uk Kim     if (File)
53059db4265SNate Lawson     {
531ec3fc72fSJung-uk Kim         if (AslCompilerdebug) /* Display final namespace, with transforms */
532ec3fc72fSJung-uk Kim         {
533efcc2a30SJung-uk Kim             NsSetupNamespaceListing (File);
534efcc2a30SJung-uk Kim             NsDisplayNamespace ();
535ec3fc72fSJung-uk Kim         }
536ec3fc72fSJung-uk Kim 
53759db4265SNate Lawson         fclose (File);
53859db4265SNate Lawson         AcpiOsRedirectOutput (stdout);
53959db4265SNate Lawson     }
54059db4265SNate Lawson 
5411a39cfb0SJung-uk Kim     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
542a9f12690SJung-uk Kim     AcpiGbl_ParseOpRoot = NULL;
543a9f12690SJung-uk Kim     return (Status);
54459db4265SNate Lawson }
54559db4265SNate Lawson 
54659db4265SNate Lawson 
54759db4265SNate Lawson /******************************************************************************
54859db4265SNate Lawson  *
5491a39cfb0SJung-uk Kim  * FUNCTION:    AdDisassemblerHeader
5501a39cfb0SJung-uk Kim  *
5511a39cfb0SJung-uk Kim  * PARAMETERS:  Filename            - Input file for the table
552*7cf3e94aSJung-uk Kim  *              TableType           - Either AML or DataTable
5531a39cfb0SJung-uk Kim  *
5541a39cfb0SJung-uk Kim  * RETURN:      None
5551a39cfb0SJung-uk Kim  *
5561a39cfb0SJung-uk Kim  * DESCRIPTION: Create the disassembler header, including ACPICA signon with
5571a39cfb0SJung-uk Kim  *              current time and date.
5581a39cfb0SJung-uk Kim  *
5591a39cfb0SJung-uk Kim  *****************************************************************************/
5601a39cfb0SJung-uk Kim 
5611a39cfb0SJung-uk Kim void
5621a39cfb0SJung-uk Kim AdDisassemblerHeader (
563*7cf3e94aSJung-uk Kim     char                    *Filename,
564*7cf3e94aSJung-uk Kim     UINT8                   TableType)
5651a39cfb0SJung-uk Kim {
5661a39cfb0SJung-uk Kim     time_t                  Timer;
5671a39cfb0SJung-uk Kim 
5681c0e1b6dSJung-uk Kim 
5691a39cfb0SJung-uk Kim     time (&Timer);
5701a39cfb0SJung-uk Kim 
5711a39cfb0SJung-uk Kim     /* Header and input table info */
5721a39cfb0SJung-uk Kim 
5733c1812acSJung-uk Kim     AcpiOsPrintf ("/*\n");
5741c0e1b6dSJung-uk Kim     AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
5751c0e1b6dSJung-uk Kim 
576*7cf3e94aSJung-uk Kim     if (TableType == ACPI_IS_AML_TABLE)
577*7cf3e94aSJung-uk Kim     {
5781c0e1b6dSJung-uk Kim         if (AcpiGbl_CstyleDisassembly)
5791c0e1b6dSJung-uk Kim         {
5801c0e1b6dSJung-uk Kim             AcpiOsPrintf (
5811c0e1b6dSJung-uk Kim                 " * Disassembling to symbolic ASL+ operators\n"
5821c0e1b6dSJung-uk Kim                 " *\n");
5831c0e1b6dSJung-uk Kim         }
5841c0e1b6dSJung-uk Kim         else
5851c0e1b6dSJung-uk Kim         {
5861c0e1b6dSJung-uk Kim             AcpiOsPrintf (
5871c0e1b6dSJung-uk Kim                 " * Disassembling to non-symbolic legacy ASL operators\n"
5881c0e1b6dSJung-uk Kim                 " *\n");
5891c0e1b6dSJung-uk Kim         }
590*7cf3e94aSJung-uk Kim     }
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 ACPICA 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      */
623*7cf3e94aSJung-uk Kim     AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
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:
636a9d8d09cSJung-uk Kim 
637a9f12690SJung-uk Kim         AcpiOsPrintf (" **** Invalid Revision");
638a9f12690SJung-uk Kim         break;
639a9f12690SJung-uk Kim 
640a9f12690SJung-uk Kim     case 1:
641a9d8d09cSJung-uk Kim 
642a9f12690SJung-uk Kim         /* Revision of DSDT controls the ACPI integer width */
643a9f12690SJung-uk Kim 
644a9f12690SJung-uk Kim         if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
645a9f12690SJung-uk Kim         {
646d244b227SJung-uk Kim             AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
647a9f12690SJung-uk Kim         }
648a9f12690SJung-uk Kim         break;
649a9f12690SJung-uk Kim 
650a9f12690SJung-uk Kim     default:
651a9d8d09cSJung-uk Kim 
652a9f12690SJung-uk Kim         break;
653a9f12690SJung-uk Kim     }
654a9f12690SJung-uk Kim     AcpiOsPrintf ("\n");
655a9f12690SJung-uk Kim 
656a9f12690SJung-uk Kim     /* Print and validate the table checksum */
657a9f12690SJung-uk Kim 
658a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Checksum         0x%2.2X",        Table->Checksum);
659a9f12690SJung-uk Kim 
660a9f12690SJung-uk Kim     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
661a9f12690SJung-uk Kim     if (Checksum)
662a9f12690SJung-uk Kim     {
663a9f12690SJung-uk Kim         AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
664a9f12690SJung-uk Kim             (UINT8) (Table->Checksum - Checksum));
665a9f12690SJung-uk Kim     }
666a9f12690SJung-uk Kim     AcpiOsPrintf ("\n");
667a9f12690SJung-uk Kim 
6681a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM ID           \"%.6s\"\n",     Table->OemId);
6691a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM Table ID     \"%.8s\"\n",     Table->OemTableId);
6701a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM Revision     0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
671a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Compiler ID      \"%.4s\"\n",     Table->AslCompilerId);
672a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
6739c48c75eSJung-uk Kim     AcpiOsPrintf (" */\n");
6741a39cfb0SJung-uk Kim 
6751a39cfb0SJung-uk Kim     /* Create AML output filename based on input filename */
6761a39cfb0SJung-uk Kim 
6771a39cfb0SJung-uk Kim     if (Filename)
6781a39cfb0SJung-uk Kim     {
6791a39cfb0SJung-uk Kim         NewFilename = FlGenerateFilename (Filename, "aml");
6801a39cfb0SJung-uk Kim     }
6811a39cfb0SJung-uk Kim     else
6821a39cfb0SJung-uk Kim     {
683313a0c13SJung-uk Kim         NewFilename = UtStringCacheCalloc (9);
684313a0c13SJung-uk Kim         if (NewFilename)
685313a0c13SJung-uk Kim         {
6861a39cfb0SJung-uk Kim             strncat (NewFilename, Table->Signature, 4);
6871a39cfb0SJung-uk Kim             strcat (NewFilename, ".aml");
6881a39cfb0SJung-uk Kim         }
689313a0c13SJung-uk Kim     }
690313a0c13SJung-uk Kim 
691313a0c13SJung-uk Kim     if (!NewFilename)
692313a0c13SJung-uk Kim     {
693313a0c13SJung-uk Kim         AcpiOsPrintf (" **** Could not generate AML output filename\n");
694313a0c13SJung-uk Kim         return;
695313a0c13SJung-uk Kim     }
6961a39cfb0SJung-uk Kim 
6971a39cfb0SJung-uk Kim     /* Open the ASL definition block */
69859db4265SNate Lawson 
69959db4265SNate Lawson     AcpiOsPrintf (
700a88e22b7SJung-uk Kim         "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
7011a39cfb0SJung-uk Kim         NewFilename, Table->Signature, Table->Revision,
70259db4265SNate Lawson         Table->OemId, Table->OemTableId, Table->OemRevision);
70359db4265SNate Lawson }
70459db4265SNate Lawson 
70559db4265SNate Lawson 
70659db4265SNate Lawson /******************************************************************************
70759db4265SNate Lawson  *
70859db4265SNate Lawson  * FUNCTION:    AdDisplayTables
70959db4265SNate Lawson  *
71059db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
711fba7fc7eSJung-uk Kim  *              Table               - Pointer to the raw table
71259db4265SNate Lawson  *
71359db4265SNate Lawson  * RETURN:      Status
71459db4265SNate Lawson  *
71559db4265SNate Lawson  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
71659db4265SNate Lawson  *
71759db4265SNate Lawson  *****************************************************************************/
71859db4265SNate Lawson 
71959db4265SNate Lawson ACPI_STATUS
72059db4265SNate Lawson AdDisplayTables (
72159db4265SNate Lawson     char                    *Filename,
72259db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
72359db4265SNate Lawson {
72459db4265SNate Lawson 
72559db4265SNate Lawson 
7261a39cfb0SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
72759db4265SNate Lawson     {
7288ef1a331SJung-uk Kim         return (AE_NOT_EXIST);
72959db4265SNate Lawson     }
73059db4265SNate Lawson 
731*7cf3e94aSJung-uk Kim     if (!AcpiGbl_DbOpt_Verbose)
73259db4265SNate Lawson     {
73359db4265SNate Lawson         AdCreateTableHeader (Filename, Table);
73459db4265SNate Lawson     }
73559db4265SNate Lawson 
7361a39cfb0SJung-uk Kim     AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
737313a0c13SJung-uk Kim     MpEmitMappingInfo ();
73859db4265SNate Lawson 
739*7cf3e94aSJung-uk Kim     if (AcpiGbl_DbOpt_Verbose)
74059db4265SNate Lawson     {
74159db4265SNate Lawson         AcpiOsPrintf ("\n\nTable Header:\n");
7428ef1a331SJung-uk Kim         AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
74359db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
74459db4265SNate Lawson 
74559db4265SNate Lawson         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
7468ef1a331SJung-uk Kim         AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
7478ef1a331SJung-uk Kim             Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
74859db4265SNate Lawson     }
74959db4265SNate Lawson 
7508ef1a331SJung-uk Kim     return (AE_OK);
75159db4265SNate Lawson }
75259db4265SNate Lawson 
75359db4265SNate Lawson 
754*7cf3e94aSJung-uk Kim /*******************************************************************************
755*7cf3e94aSJung-uk Kim  *
756*7cf3e94aSJung-uk Kim  * FUNCTION:    AdStoreTable
757*7cf3e94aSJung-uk Kim  *
758*7cf3e94aSJung-uk Kim  * PARAMETERS:  Table               - Table header
759*7cf3e94aSJung-uk Kim  *              TableIndex          - Where the table index is returned
760*7cf3e94aSJung-uk Kim  *
761*7cf3e94aSJung-uk Kim  * RETURN:      Status and table index.
762*7cf3e94aSJung-uk Kim  *
763*7cf3e94aSJung-uk Kim  * DESCRIPTION: Add an ACPI table to the global table list
764*7cf3e94aSJung-uk Kim  *
765*7cf3e94aSJung-uk Kim  ******************************************************************************/
766*7cf3e94aSJung-uk Kim 
767*7cf3e94aSJung-uk Kim static ACPI_STATUS
768*7cf3e94aSJung-uk Kim AdStoreTable (
769*7cf3e94aSJung-uk Kim     ACPI_TABLE_HEADER       *Table,
770*7cf3e94aSJung-uk Kim     UINT32                  *TableIndex)
771*7cf3e94aSJung-uk Kim {
772*7cf3e94aSJung-uk Kim     ACPI_STATUS             Status;
773*7cf3e94aSJung-uk Kim     ACPI_TABLE_DESC         *TableDesc;
774*7cf3e94aSJung-uk Kim 
775*7cf3e94aSJung-uk Kim 
776*7cf3e94aSJung-uk Kim     Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
777*7cf3e94aSJung-uk Kim     if (ACPI_FAILURE (Status))
778*7cf3e94aSJung-uk Kim     {
779*7cf3e94aSJung-uk Kim         return (Status);
780*7cf3e94aSJung-uk Kim     }
781*7cf3e94aSJung-uk Kim 
782*7cf3e94aSJung-uk Kim     /* Initialize added table */
783*7cf3e94aSJung-uk Kim 
784*7cf3e94aSJung-uk Kim     AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
785*7cf3e94aSJung-uk Kim         ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
786*7cf3e94aSJung-uk Kim     AcpiTbValidateTable (TableDesc);
787*7cf3e94aSJung-uk Kim     return (AE_OK);
788*7cf3e94aSJung-uk Kim }
789*7cf3e94aSJung-uk Kim 
790*7cf3e94aSJung-uk Kim 
79159db4265SNate Lawson /******************************************************************************
79259db4265SNate Lawson  *
79359db4265SNate Lawson  * FUNCTION:    AdGetLocalTables
79459db4265SNate Lawson  *
795313a0c13SJung-uk Kim  * PARAMETERS:  None
79659db4265SNate Lawson  *
797fba7fc7eSJung-uk Kim  * RETURN:      Status
79859db4265SNate Lawson  *
79959db4265SNate Lawson  * DESCRIPTION: Get the ACPI tables from either memory or a file
80059db4265SNate Lawson  *
80159db4265SNate Lawson  *****************************************************************************/
80259db4265SNate Lawson 
80359db4265SNate Lawson ACPI_STATUS
80459db4265SNate Lawson AdGetLocalTables (
805313a0c13SJung-uk Kim     void)
80659db4265SNate Lawson {
80759db4265SNate Lawson     ACPI_STATUS             Status;
80859db4265SNate Lawson     ACPI_TABLE_HEADER       TableHeader;
80959db4265SNate Lawson     ACPI_TABLE_HEADER       *NewTable;
810a9f12690SJung-uk Kim     UINT32                  TableIndex;
81159db4265SNate Lawson 
81259db4265SNate Lawson 
813313a0c13SJung-uk Kim     /* Get the DSDT via table override */
81459db4265SNate Lawson 
8151a39cfb0SJung-uk Kim     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
81659db4265SNate Lawson     AcpiOsTableOverride (&TableHeader, &NewTable);
817313a0c13SJung-uk Kim     if (!NewTable)
81859db4265SNate Lawson     {
819313a0c13SJung-uk Kim         fprintf (stderr, "Could not obtain DSDT\n");
820313a0c13SJung-uk Kim         return (AE_NO_ACPI_TABLES);
821313a0c13SJung-uk Kim     }
822313a0c13SJung-uk Kim 
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 
828*7cf3e94aSJung-uk Kim     Status = AdStoreTable (NewTable, &TableIndex);
829f556842eSJung-uk Kim     if (ACPI_FAILURE (Status))
830f556842eSJung-uk Kim     {
831f556842eSJung-uk Kim         fprintf (stderr, "Could not store DSDT\n");
8328ef1a331SJung-uk Kim         return (AE_NO_ACPI_TABLES);
833f556842eSJung-uk Kim     }
83459db4265SNate Lawson 
8358ef1a331SJung-uk Kim     return (AE_OK);
83659db4265SNate Lawson }
83759db4265SNate Lawson 
8381a39cfb0SJung-uk Kim 
83959db4265SNate Lawson /******************************************************************************
84059db4265SNate Lawson  *
84159db4265SNate Lawson  * FUNCTION:    AdParseTable
84259db4265SNate Lawson  *
843fba7fc7eSJung-uk Kim  * PARAMETERS:  Table               - Pointer to the raw table
844a9f12690SJung-uk Kim  *              OwnerId             - Returned OwnerId of the table
845a9f12690SJung-uk Kim  *              LoadTable           - If add table to the global table list
846a9f12690SJung-uk Kim  *              External            - If this is an external table
84759db4265SNate Lawson  *
84859db4265SNate Lawson  * RETURN:      Status
84959db4265SNate Lawson  *
85059db4265SNate Lawson  * DESCRIPTION: Parse the DSDT.
85159db4265SNate Lawson  *
85259db4265SNate Lawson  *****************************************************************************/
85359db4265SNate Lawson 
85459db4265SNate Lawson ACPI_STATUS
85559db4265SNate Lawson AdParseTable (
856a9f12690SJung-uk Kim     ACPI_TABLE_HEADER       *Table,
857a9f12690SJung-uk Kim     ACPI_OWNER_ID           *OwnerId,
858a9f12690SJung-uk Kim     BOOLEAN                 LoadTable,
859a9f12690SJung-uk Kim     BOOLEAN                 External)
86059db4265SNate Lawson {
86159db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
86259db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
86359db4265SNate Lawson     UINT8                   *AmlStart;
86459db4265SNate Lawson     UINT32                  AmlLength;
865a9f12690SJung-uk Kim     UINT32                  TableIndex;
86659db4265SNate Lawson 
86759db4265SNate Lawson 
86859db4265SNate Lawson     if (!Table)
86959db4265SNate Lawson     {
8708ef1a331SJung-uk Kim         return (AE_NOT_EXIST);
87159db4265SNate Lawson     }
87259db4265SNate Lawson 
87359db4265SNate Lawson     /* Pass 1:  Parse everything except control method bodies */
87459db4265SNate Lawson 
87559db4265SNate Lawson     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
87659db4265SNate Lawson 
87759db4265SNate Lawson     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
87859db4265SNate Lawson     AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
87959db4265SNate Lawson 
88059db4265SNate Lawson     /* Create the root object */
88159db4265SNate Lawson 
8821a39cfb0SJung-uk Kim     AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
8831a39cfb0SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
88459db4265SNate Lawson     {
8858ef1a331SJung-uk Kim         return (AE_NO_MEMORY);
88659db4265SNate Lawson     }
88759db4265SNate Lawson 
88859db4265SNate Lawson     /* Create and initialize a new walk state */
88959db4265SNate Lawson 
89059db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0,
8911a39cfb0SJung-uk Kim                         AcpiGbl_ParseOpRoot, NULL, NULL);
89259db4265SNate Lawson     if (!WalkState)
89359db4265SNate Lawson     {
89459db4265SNate Lawson         return (AE_NO_MEMORY);
89559db4265SNate Lawson     }
89659db4265SNate Lawson 
8971a39cfb0SJung-uk Kim     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
8981a39cfb0SJung-uk Kim                 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
89959db4265SNate Lawson     if (ACPI_FAILURE (Status))
90059db4265SNate Lawson     {
90159db4265SNate Lawson         return (Status);
90259db4265SNate Lawson     }
90359db4265SNate Lawson 
90459db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
905fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
90659db4265SNate Lawson 
90759db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
90859db4265SNate Lawson     if (ACPI_FAILURE (Status))
90959db4265SNate Lawson     {
9108ef1a331SJung-uk Kim         return (Status);
91159db4265SNate Lawson     }
91259db4265SNate Lawson 
913a9f12690SJung-uk Kim     /* If LoadTable is FALSE, we are parsing the last loaded table */
914a9f12690SJung-uk Kim 
9153f5e024cSJung-uk Kim     TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
916a9f12690SJung-uk Kim 
91759db4265SNate Lawson     /* Pass 2 */
91859db4265SNate Lawson 
919a9f12690SJung-uk Kim     if (LoadTable)
920a9f12690SJung-uk Kim     {
921*7cf3e94aSJung-uk Kim         Status = AdStoreTable (Table, &TableIndex);
9221a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
9231a39cfb0SJung-uk Kim         {
9248ef1a331SJung-uk Kim             return (Status);
9251a39cfb0SJung-uk Kim         }
926a9f12690SJung-uk Kim         Status = AcpiTbAllocateOwnerId (TableIndex);
927a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
928a9f12690SJung-uk Kim         {
9298ef1a331SJung-uk Kim             return (Status);
930a9f12690SJung-uk Kim         }
931a9f12690SJung-uk Kim         if (OwnerId)
932a9f12690SJung-uk Kim         {
933a9f12690SJung-uk Kim             Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
934a9f12690SJung-uk Kim             if (ACPI_FAILURE (Status))
935a9f12690SJung-uk Kim             {
9368ef1a331SJung-uk Kim                 return (Status);
937a9f12690SJung-uk Kim             }
938a9f12690SJung-uk Kim         }
939a9f12690SJung-uk Kim     }
94059db4265SNate Lawson 
9411a39cfb0SJung-uk Kim     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
9421a39cfb0SJung-uk Kim 
943a9f12690SJung-uk Kim     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
94459db4265SNate Lawson     if (ACPI_FAILURE (Status))
94559db4265SNate Lawson     {
94659db4265SNate Lawson         return (Status);
94759db4265SNate Lawson     }
94859db4265SNate Lawson 
949a9f12690SJung-uk Kim     /* No need to parse control methods of external table */
950a9f12690SJung-uk Kim 
951a9f12690SJung-uk Kim     if (External)
952a9f12690SJung-uk Kim     {
9538ef1a331SJung-uk Kim         return (AE_OK);
954a9f12690SJung-uk Kim     }
955a9f12690SJung-uk Kim 
956313a0c13SJung-uk Kim     /*
957313a0c13SJung-uk Kim      * Pass 3: Parse control methods and link their parse trees
958313a0c13SJung-uk Kim      * into the main parse tree
959313a0c13SJung-uk Kim      */
960313a0c13SJung-uk Kim     fprintf (stderr,
961313a0c13SJung-uk Kim         "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
962ed17e06eSJung-uk Kim     Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
963ed17e06eSJung-uk Kim     fprintf (stderr, "\n");
9641a39cfb0SJung-uk Kim 
9651a39cfb0SJung-uk Kim     /* Process Resource Templates */
9661a39cfb0SJung-uk Kim 
9671a39cfb0SJung-uk Kim     AcpiDmFindResources (AcpiGbl_ParseOpRoot);
96859db4265SNate Lawson 
96959db4265SNate Lawson     fprintf (stderr, "Parsing completed\n");
9708ef1a331SJung-uk Kim     return (AE_OK);
97159db4265SNate Lawson }
972