xref: /freebsd/sys/contrib/dev/acpica/common/adisasm.c (revision ab6f3bf9cb8ad195aecd9165d8d4b1a93aed3c8d)
159db4265SNate Lawson /******************************************************************************
259db4265SNate Lawson  *
359db4265SNate Lawson  * Module Name: adisasm - Application-level disassembler routines
459db4265SNate Lawson  *
559db4265SNate Lawson  *****************************************************************************/
659db4265SNate Lawson 
759db4265SNate Lawson /******************************************************************************
859db4265SNate Lawson  *
959db4265SNate Lawson  * 1. Copyright Notice
1059db4265SNate Lawson  *
11a9f12690SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
1259db4265SNate Lawson  * All rights reserved.
1359db4265SNate Lawson  *
1459db4265SNate Lawson  * 2. License
1559db4265SNate Lawson  *
1659db4265SNate Lawson  * 2.1. This is your license from Intel Corp. under its intellectual property
1759db4265SNate Lawson  * rights.  You may have additional license terms from the party that provided
1859db4265SNate Lawson  * you this software, covering your right to use that party's intellectual
1959db4265SNate Lawson  * property rights.
2059db4265SNate Lawson  *
2159db4265SNate Lawson  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2259db4265SNate Lawson  * copy of the source code appearing in this file ("Covered Code") an
2359db4265SNate Lawson  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2459db4265SNate Lawson  * base code distributed originally by Intel ("Original Intel Code") to copy,
2559db4265SNate Lawson  * make derivatives, distribute, use and display any portion of the Covered
2659db4265SNate Lawson  * Code in any form, with the right to sublicense such rights; and
2759db4265SNate Lawson  *
2859db4265SNate Lawson  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
2959db4265SNate Lawson  * license (with the right to sublicense), under only those claims of Intel
3059db4265SNate Lawson  * patents that are infringed by the Original Intel Code, to make, use, sell,
3159db4265SNate Lawson  * offer to sell, and import the Covered Code and derivative works thereof
3259db4265SNate Lawson  * solely to the minimum extent necessary to exercise the above copyright
3359db4265SNate Lawson  * license, and in no event shall the patent license extend to any additions
3459db4265SNate Lawson  * to or modifications of the Original Intel Code.  No other license or right
3559db4265SNate Lawson  * is granted directly or by implication, estoppel or otherwise;
3659db4265SNate Lawson  *
3759db4265SNate Lawson  * The above copyright and patent license is granted only if the following
3859db4265SNate Lawson  * conditions are met:
3959db4265SNate Lawson  *
4059db4265SNate Lawson  * 3. Conditions
4159db4265SNate Lawson  *
4259db4265SNate Lawson  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4359db4265SNate Lawson  * Redistribution of source code of any substantial portion of the Covered
4459db4265SNate Lawson  * Code or modification with rights to further distribute source must include
4559db4265SNate Lawson  * the above Copyright Notice, the above License, this list of Conditions,
4659db4265SNate Lawson  * and the following Disclaimer and Export Compliance provision.  In addition,
4759db4265SNate Lawson  * Licensee must cause all Covered Code to which Licensee contributes to
4859db4265SNate Lawson  * contain a file documenting the changes Licensee made to create that Covered
4959db4265SNate Lawson  * Code and the date of any change.  Licensee must include in that file the
5059db4265SNate Lawson  * documentation of any changes made by any predecessor Licensee.  Licensee
5159db4265SNate Lawson  * must include a prominent statement that the modification is derived,
5259db4265SNate Lawson  * directly or indirectly, from Original Intel Code.
5359db4265SNate Lawson  *
5459db4265SNate Lawson  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5559db4265SNate Lawson  * Redistribution of source code of any substantial portion of the Covered
5659db4265SNate Lawson  * Code or modification without rights to further distribute source must
5759db4265SNate Lawson  * include the following Disclaimer and Export Compliance provision in the
5859db4265SNate Lawson  * documentation and/or other materials provided with distribution.  In
5959db4265SNate Lawson  * addition, Licensee may not authorize further sublicense of source of any
6059db4265SNate Lawson  * portion of the Covered Code, and must include terms to the effect that the
6159db4265SNate Lawson  * license from Licensee to its licensee is limited to the intellectual
6259db4265SNate Lawson  * property embodied in the software Licensee provides to its licensee, and
6359db4265SNate Lawson  * not to intellectual property embodied in modifications its licensee may
6459db4265SNate Lawson  * make.
6559db4265SNate Lawson  *
6659db4265SNate Lawson  * 3.3. Redistribution of Executable. Redistribution in executable form of any
6759db4265SNate Lawson  * substantial portion of the Covered Code or modification must reproduce the
6859db4265SNate Lawson  * above Copyright Notice, and the following Disclaimer and Export Compliance
6959db4265SNate Lawson  * provision in the documentation and/or other materials provided with the
7059db4265SNate Lawson  * distribution.
7159db4265SNate Lawson  *
7259db4265SNate Lawson  * 3.4. Intel retains all right, title, and interest in and to the Original
7359db4265SNate Lawson  * Intel Code.
7459db4265SNate Lawson  *
7559db4265SNate Lawson  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7659db4265SNate Lawson  * Intel shall be used in advertising or otherwise to promote the sale, use or
7759db4265SNate Lawson  * other dealings in products derived from or relating to the Covered Code
7859db4265SNate Lawson  * without prior written authorization from Intel.
7959db4265SNate Lawson  *
8059db4265SNate Lawson  * 4. Disclaimer and Export Compliance
8159db4265SNate Lawson  *
8259db4265SNate Lawson  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8359db4265SNate Lawson  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8459db4265SNate Lawson  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8559db4265SNate Lawson  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8659db4265SNate Lawson  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8759db4265SNate Lawson  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8859db4265SNate Lawson  * PARTICULAR PURPOSE.
8959db4265SNate Lawson  *
9059db4265SNate Lawson  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9159db4265SNate Lawson  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9259db4265SNate Lawson  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9359db4265SNate Lawson  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9459db4265SNate Lawson  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9559db4265SNate Lawson  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9659db4265SNate Lawson  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9759db4265SNate Lawson  * LIMITED REMEDY.
9859db4265SNate Lawson  *
9959db4265SNate Lawson  * 4.3. Licensee shall not export, either directly or indirectly, any of this
10059db4265SNate Lawson  * software or system incorporating such software without first obtaining any
10159db4265SNate Lawson  * required license or other approval from the U. S. Department of Commerce or
10259db4265SNate Lawson  * any other agency or department of the United States Government.  In the
10359db4265SNate Lawson  * event Licensee exports any such software from the United States or
10459db4265SNate Lawson  * re-exports any such software from a foreign destination, Licensee shall
10559db4265SNate Lawson  * ensure that the distribution and export/re-export of the software is in
10659db4265SNate Lawson  * compliance with all laws, regulations, orders, or other restrictions of the
10759db4265SNate Lawson  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10859db4265SNate Lawson  * any of its subsidiaries will export/re-export any technical data, process,
10959db4265SNate Lawson  * software, or service, directly or indirectly, to any country for which the
11059db4265SNate Lawson  * United States government or any agency thereof requires an export license,
11159db4265SNate Lawson  * other governmental approval, or letter of assurance, without first obtaining
11259db4265SNate Lawson  * such license, approval or letter.
11359db4265SNate Lawson  *
11459db4265SNate Lawson  *****************************************************************************/
11559db4265SNate Lawson 
11659db4265SNate Lawson 
117ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
118ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
119ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
120ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
121ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdebug.h>
122ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdisasm.h>
123ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
124ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
125ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
126ab6f3bf9SJung-uk Kim #include <contrib/dev/acpica/include/acapps.h>
12759db4265SNate Lawson 
12859db4265SNate Lawson #include <stdio.h>
12959db4265SNate Lawson #include <time.h>
13059db4265SNate Lawson 
13159db4265SNate Lawson 
13259db4265SNate Lawson #define _COMPONENT          ACPI_TOOLS
13359db4265SNate Lawson         ACPI_MODULE_NAME    ("adisasm")
13459db4265SNate Lawson 
1351a39cfb0SJung-uk Kim extern int                          AslCompilerdebug;
13659db4265SNate Lawson 
1371a39cfb0SJung-uk Kim ACPI_STATUS
1381a39cfb0SJung-uk Kim LsDisplayNamespace (
1391a39cfb0SJung-uk Kim     void);
14059db4265SNate Lawson 
1411a39cfb0SJung-uk Kim void
1421a39cfb0SJung-uk Kim LsSetupNsList (void * Handle);
1431a39cfb0SJung-uk Kim 
1441a39cfb0SJung-uk Kim 
1451a39cfb0SJung-uk Kim /* Local prototypes */
1461a39cfb0SJung-uk Kim 
1471a39cfb0SJung-uk Kim void
1481a39cfb0SJung-uk Kim AdCreateTableHeader (
1491a39cfb0SJung-uk Kim     char                    *Filename,
1501a39cfb0SJung-uk Kim     ACPI_TABLE_HEADER       *Table);
1511a39cfb0SJung-uk Kim 
1521a39cfb0SJung-uk Kim void
1531a39cfb0SJung-uk Kim AdDisassemblerHeader (
1541a39cfb0SJung-uk Kim     char                    *Filename);
1551a39cfb0SJung-uk Kim 
156a9f12690SJung-uk Kim void
157a9f12690SJung-uk Kim AdAddExternalsToNamespace (
158a9f12690SJung-uk Kim     void);
159a9f12690SJung-uk Kim 
160a9f12690SJung-uk Kim UINT32
161a9f12690SJung-uk Kim AdMethodExternalCount (
162a9f12690SJung-uk Kim     void);
163a9f12690SJung-uk Kim 
164a9f12690SJung-uk Kim ACPI_STATUS
165a9f12690SJung-uk Kim AdDeferredParse (
166a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
167a9f12690SJung-uk Kim     UINT8                   *Aml,
168a9f12690SJung-uk Kim     UINT32                  AmlLength);
169a9f12690SJung-uk Kim 
170a9f12690SJung-uk Kim ACPI_STATUS
171a9f12690SJung-uk Kim AdParseDeferredOps (
172a9f12690SJung-uk Kim     ACPI_PARSE_OBJECT       *Root);
173a9f12690SJung-uk Kim 
1741a39cfb0SJung-uk Kim ACPI_PARSE_OBJECT           *AcpiGbl_ParseOpRoot;
1751a39cfb0SJung-uk Kim 
1761a39cfb0SJung-uk Kim 
1771a39cfb0SJung-uk Kim /* Stubs for ASL compiler */
17859db4265SNate Lawson 
179fba7fc7eSJung-uk Kim #ifndef ACPI_ASL_COMPILER
18059db4265SNate Lawson BOOLEAN
18159db4265SNate Lawson AcpiDsIsResultUsed (
18259db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
18359db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
18459db4265SNate Lawson {
18559db4265SNate Lawson     return TRUE;
18659db4265SNate Lawson }
1871a39cfb0SJung-uk Kim 
1881a39cfb0SJung-uk Kim ACPI_STATUS
1891a39cfb0SJung-uk Kim AcpiDsMethodError (
1901a39cfb0SJung-uk Kim     ACPI_STATUS             Status,
1911a39cfb0SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
1921a39cfb0SJung-uk Kim {
1931a39cfb0SJung-uk Kim     return (Status);
1941a39cfb0SJung-uk Kim }
1951a39cfb0SJung-uk Kim 
19659db4265SNate Lawson #endif
19759db4265SNate Lawson 
19859db4265SNate Lawson ACPI_STATUS
1991a39cfb0SJung-uk Kim AcpiNsLoadTable (
200a9f12690SJung-uk Kim     UINT32                  TableIndex,
2011a39cfb0SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node)
2021a39cfb0SJung-uk Kim {
2031a39cfb0SJung-uk Kim     return (AE_NOT_IMPLEMENTED);
2041a39cfb0SJung-uk Kim }
2051a39cfb0SJung-uk Kim 
2061a39cfb0SJung-uk Kim ACPI_STATUS
20759db4265SNate Lawson AcpiDsRestartControlMethod (
20859db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
20959db4265SNate Lawson     ACPI_OPERAND_OBJECT     *ReturnDesc)
21059db4265SNate Lawson {
21159db4265SNate Lawson     return (AE_OK);
21259db4265SNate Lawson }
21359db4265SNate Lawson 
214fba7fc7eSJung-uk Kim void
21559db4265SNate Lawson AcpiDsTerminateControlMethod (
2161a39cfb0SJung-uk Kim     ACPI_OPERAND_OBJECT     *MethodDesc,
21759db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
21859db4265SNate Lawson {
219fba7fc7eSJung-uk Kim     return;
22059db4265SNate Lawson }
22159db4265SNate Lawson 
22259db4265SNate Lawson ACPI_STATUS
22359db4265SNate Lawson AcpiDsCallControlMethod (
22459db4265SNate Lawson     ACPI_THREAD_STATE       *Thread,
22559db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
22659db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op)
22759db4265SNate Lawson {
22859db4265SNate Lawson     return (AE_OK);
22959db4265SNate Lawson }
23059db4265SNate Lawson 
23159db4265SNate Lawson ACPI_STATUS
23259db4265SNate Lawson AcpiDsMethodDataInitArgs (
23359db4265SNate Lawson     ACPI_OPERAND_OBJECT     **Params,
23459db4265SNate Lawson     UINT32                  MaxParamCount,
23559db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
23659db4265SNate Lawson {
23759db4265SNate Lawson     return (AE_OK);
23859db4265SNate Lawson }
23959db4265SNate Lawson 
24059db4265SNate Lawson 
2411a39cfb0SJung-uk Kim ACPI_TABLE_DESC             LocalTables[1];
24259db4265SNate Lawson 
24359db4265SNate Lawson 
24459db4265SNate Lawson /*******************************************************************************
24559db4265SNate Lawson  *
24659db4265SNate Lawson  * FUNCTION:    AdInitialize
24759db4265SNate Lawson  *
24859db4265SNate Lawson  * PARAMETERS:  None.
24959db4265SNate Lawson  *
25059db4265SNate Lawson  * RETURN:      Status
25159db4265SNate Lawson  *
25259db4265SNate Lawson  * DESCRIPTION: CA initialization
25359db4265SNate Lawson  *
25459db4265SNate Lawson  ******************************************************************************/
25559db4265SNate Lawson 
25659db4265SNate Lawson ACPI_STATUS
25759db4265SNate Lawson AdInitialize (
25859db4265SNate Lawson     void)
25959db4265SNate Lawson {
26059db4265SNate Lawson     ACPI_STATUS             Status;
26159db4265SNate Lawson 
26259db4265SNate Lawson 
26359db4265SNate Lawson     /* ACPI CA subsystem initialization */
26459db4265SNate Lawson 
2651a39cfb0SJung-uk Kim     Status = AcpiOsInitialize ();
266a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
267a9f12690SJung-uk Kim     {
268a9f12690SJung-uk Kim         return (Status);
269a9f12690SJung-uk Kim     }
270a9f12690SJung-uk Kim 
271a9f12690SJung-uk Kim     Status = AcpiUtInitGlobals ();
272a9f12690SJung-uk Kim     if (ACPI_FAILURE (Status))
273a9f12690SJung-uk Kim     {
274a9f12690SJung-uk Kim         return (Status);
275a9f12690SJung-uk Kim     }
2761a39cfb0SJung-uk Kim 
27759db4265SNate Lawson     Status = AcpiUtMutexInitialize ();
27859db4265SNate Lawson     if (ACPI_FAILURE (Status))
27959db4265SNate Lawson     {
280a9f12690SJung-uk Kim         return (Status);
28159db4265SNate Lawson     }
28259db4265SNate Lawson 
28359db4265SNate Lawson     Status = AcpiNsRootInitialize ();
2841a39cfb0SJung-uk Kim     if (ACPI_FAILURE (Status))
2851a39cfb0SJung-uk Kim     {
286a9f12690SJung-uk Kim         return (Status);
2871a39cfb0SJung-uk Kim     }
2881a39cfb0SJung-uk Kim 
2891a39cfb0SJung-uk Kim     /* Setup the Table Manager (cheat - there is no RSDT) */
2901a39cfb0SJung-uk Kim 
2911a39cfb0SJung-uk Kim     AcpiGbl_RootTableList.Size = 1;
2921a39cfb0SJung-uk Kim     AcpiGbl_RootTableList.Count = 0;
2931a39cfb0SJung-uk Kim     AcpiGbl_RootTableList.Tables = LocalTables;
2941a39cfb0SJung-uk Kim 
295a9f12690SJung-uk Kim     return (Status);
29659db4265SNate Lawson }
29759db4265SNate Lawson 
29859db4265SNate Lawson 
29959db4265SNate Lawson /*******************************************************************************
30059db4265SNate Lawson  *
3011a39cfb0SJung-uk Kim  * FUNCTION:    AdAddExternalsToNamespace
30259db4265SNate Lawson  *
3031a39cfb0SJung-uk Kim  * PARAMETERS:
30459db4265SNate Lawson  *
305a9f12690SJung-uk Kim  * RETURN:      None
30659db4265SNate Lawson  *
3071a39cfb0SJung-uk Kim  * DESCRIPTION:
30859db4265SNate Lawson  *
30959db4265SNate Lawson  ******************************************************************************/
31059db4265SNate Lawson 
3111a39cfb0SJung-uk Kim void
3121a39cfb0SJung-uk Kim AdAddExternalsToNamespace (
3131a39cfb0SJung-uk Kim     void)
31459db4265SNate Lawson {
3151a39cfb0SJung-uk Kim     ACPI_STATUS             Status;
3161a39cfb0SJung-uk Kim     ACPI_NAMESPACE_NODE     *Node;
3171a39cfb0SJung-uk Kim     ACPI_EXTERNAL_LIST      *External = AcpiGbl_ExternalList;
3181a39cfb0SJung-uk Kim     ACPI_OPERAND_OBJECT     *MethodDesc;
31959db4265SNate Lawson 
32059db4265SNate Lawson 
3211a39cfb0SJung-uk Kim     while (External)
32259db4265SNate Lawson     {
3231a39cfb0SJung-uk Kim         Status = AcpiNsLookup (NULL, External->InternalPath, External->Type,
3241a39cfb0SJung-uk Kim                    ACPI_IMODE_LOAD_PASS1, ACPI_NS_EXTERNAL | ACPI_NS_DONT_OPEN_SCOPE,
3251a39cfb0SJung-uk Kim                    NULL, &Node);
32659db4265SNate Lawson 
3271a39cfb0SJung-uk Kim         if (External->Type == ACPI_TYPE_METHOD)
32859db4265SNate Lawson         {
3291a39cfb0SJung-uk Kim             MethodDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
3301a39cfb0SJung-uk Kim             MethodDesc->Method.ParamCount = (UINT8) External->Value;
3311a39cfb0SJung-uk Kim             Node->Object = MethodDesc;
33259db4265SNate Lawson         }
33359db4265SNate Lawson 
3341a39cfb0SJung-uk Kim         External = External->Next;
3351a39cfb0SJung-uk Kim     }
33659db4265SNate Lawson }
33759db4265SNate Lawson 
33859db4265SNate Lawson 
33959db4265SNate Lawson /*******************************************************************************
34059db4265SNate Lawson  *
3411a39cfb0SJung-uk Kim  * FUNCTION:    AdMethodExternalCount
34259db4265SNate Lawson  *
3431a39cfb0SJung-uk Kim  * PARAMETERS:  None
34459db4265SNate Lawson  *
34559db4265SNate Lawson  * RETURN:      Status
34659db4265SNate Lawson  *
3471a39cfb0SJung-uk Kim  * DESCRIPTION: Return the number of externals that have been generated
34859db4265SNate Lawson  *
34959db4265SNate Lawson  ******************************************************************************/
35059db4265SNate Lawson 
3511a39cfb0SJung-uk Kim UINT32
3521a39cfb0SJung-uk Kim AdMethodExternalCount (
3531a39cfb0SJung-uk Kim     void)
35459db4265SNate Lawson {
3551a39cfb0SJung-uk Kim     ACPI_EXTERNAL_LIST      *External = AcpiGbl_ExternalList;
3561a39cfb0SJung-uk Kim     UINT32                  Count = 0;
35759db4265SNate Lawson 
35859db4265SNate Lawson 
3591a39cfb0SJung-uk Kim     while (External)
36059db4265SNate Lawson     {
3611a39cfb0SJung-uk Kim         if (External->Type == ACPI_TYPE_METHOD)
3621a39cfb0SJung-uk Kim         {
3631a39cfb0SJung-uk Kim             Count++;
36459db4265SNate Lawson         }
36559db4265SNate Lawson 
3661a39cfb0SJung-uk Kim         External = External->Next;
36759db4265SNate Lawson     }
36859db4265SNate Lawson 
3691a39cfb0SJung-uk Kim     return (Count);
37059db4265SNate Lawson }
37159db4265SNate Lawson 
37259db4265SNate Lawson 
37359db4265SNate Lawson /******************************************************************************
37459db4265SNate Lawson  *
37559db4265SNate Lawson  * FUNCTION:    AdAmlDisassemble
37659db4265SNate Lawson  *
377fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename        - AML input filename
378fba7fc7eSJung-uk Kim  *              OutToFile       - TRUE if output should go to a file
379fba7fc7eSJung-uk Kim  *              Prefix          - Path prefix for output
380fba7fc7eSJung-uk Kim  *              OutFilename     - where the filename is returned
381fba7fc7eSJung-uk Kim  *              GetAllTables    - TRUE if all tables are desired
38259db4265SNate Lawson  *
38359db4265SNate Lawson  * RETURN:      Status
38459db4265SNate Lawson  *
38559db4265SNate Lawson  * DESCRIPTION: Disassemble an entire ACPI table
38659db4265SNate Lawson  *
38759db4265SNate Lawson  *****************************************************************************/
38859db4265SNate Lawson 
3891a39cfb0SJung-uk Kim extern char *Gbl_ExternalFilename;
3901a39cfb0SJung-uk Kim 
39159db4265SNate Lawson ACPI_STATUS
39259db4265SNate Lawson AdAmlDisassemble (
39359db4265SNate Lawson     BOOLEAN                 OutToFile,
39459db4265SNate Lawson     char                    *Filename,
39559db4265SNate Lawson     char                    *Prefix,
39659db4265SNate Lawson     char                    **OutFilename,
39759db4265SNate Lawson     BOOLEAN                 GetAllTables)
39859db4265SNate Lawson {
39959db4265SNate Lawson     ACPI_STATUS             Status;
40059db4265SNate Lawson     char                    *DisasmFilename = NULL;
401a9f12690SJung-uk Kim     char                    *ExternalFilename;
40259db4265SNate Lawson     FILE                    *File = NULL;
403a9f12690SJung-uk Kim     ACPI_TABLE_HEADER       *Table = NULL;
4041a39cfb0SJung-uk Kim     ACPI_TABLE_HEADER       *ExternalTable;
405a9f12690SJung-uk Kim     ACPI_OWNER_ID           OwnerId;
406a9f12690SJung-uk Kim     ACPI_EXTERNAL_LIST      *NextExternal;
40759db4265SNate Lawson 
40859db4265SNate Lawson 
40959db4265SNate Lawson     /*
41059db4265SNate Lawson      * Input: AML Code from either a file,
41159db4265SNate Lawson      *        or via GetTables (memory or registry)
41259db4265SNate Lawson      */
41359db4265SNate Lawson     if (Filename)
41459db4265SNate Lawson     {
41559db4265SNate Lawson         Status = AcpiDbGetTableFromFile (Filename, &Table);
41659db4265SNate Lawson         if (ACPI_FAILURE (Status))
41759db4265SNate Lawson         {
41859db4265SNate Lawson             return Status;
41959db4265SNate Lawson         }
4201a39cfb0SJung-uk Kim 
421a9f12690SJung-uk Kim         /*
422a9f12690SJung-uk Kim          * External filenames separated by commas
423a9f12690SJung-uk Kim          * Example: iasl -e file1,file2,file3 -d xxx.aml
424a9f12690SJung-uk Kim          */
4251a39cfb0SJung-uk Kim         if (Gbl_ExternalFilename)
4261a39cfb0SJung-uk Kim         {
427a9f12690SJung-uk Kim             ExternalFilename = strtok (Gbl_ExternalFilename, ",");
428a9f12690SJung-uk Kim 
429a9f12690SJung-uk Kim             while (ExternalFilename)
430a9f12690SJung-uk Kim             {
431a9f12690SJung-uk Kim                 Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
4321a39cfb0SJung-uk Kim                 if (ACPI_FAILURE (Status))
4331a39cfb0SJung-uk Kim                 {
4341a39cfb0SJung-uk Kim                     return Status;
4351a39cfb0SJung-uk Kim                 }
436a9f12690SJung-uk Kim 
437a9f12690SJung-uk Kim                 /* Load external table for symbol resolution */
438a9f12690SJung-uk Kim 
439a9f12690SJung-uk Kim                 if (ExternalTable)
440a9f12690SJung-uk Kim                 {
441a9f12690SJung-uk Kim                     Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
442a9f12690SJung-uk Kim                     if (ACPI_FAILURE (Status))
443a9f12690SJung-uk Kim                     {
444a9f12690SJung-uk Kim                         AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
445a9f12690SJung-uk Kim                             AcpiFormatException (Status));
446a9f12690SJung-uk Kim                         return Status;
447a9f12690SJung-uk Kim                     }
448a9f12690SJung-uk Kim 
449a9f12690SJung-uk Kim                     /*
450a9f12690SJung-uk Kim                      * Load namespace from names created within control methods
451a9f12690SJung-uk Kim                      * Set owner id of nodes in external table
452a9f12690SJung-uk Kim                      */
453a9f12690SJung-uk Kim                     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
454a9f12690SJung-uk Kim                         AcpiGbl_RootNode, OwnerId);
455a9f12690SJung-uk Kim                     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
456a9f12690SJung-uk Kim                 }
457a9f12690SJung-uk Kim 
458a9f12690SJung-uk Kim                 /* Next external file name */
459a9f12690SJung-uk Kim 
460a9f12690SJung-uk Kim                 ExternalFilename = strtok (NULL, ",");
461a9f12690SJung-uk Kim             }
462a9f12690SJung-uk Kim 
463a9f12690SJung-uk Kim             /* Clear external list generated by Scope in external tables */
464a9f12690SJung-uk Kim 
465a9f12690SJung-uk Kim             while (AcpiGbl_ExternalList)
466a9f12690SJung-uk Kim             {
467a9f12690SJung-uk Kim                 NextExternal = AcpiGbl_ExternalList->Next;
468a9f12690SJung-uk Kim                 ACPI_FREE (AcpiGbl_ExternalList->Path);
469a9f12690SJung-uk Kim                 ACPI_FREE (AcpiGbl_ExternalList);
470a9f12690SJung-uk Kim                 AcpiGbl_ExternalList = NextExternal;
471a9f12690SJung-uk Kim             }
4721a39cfb0SJung-uk Kim         }
47359db4265SNate Lawson     }
47459db4265SNate Lawson     else
47559db4265SNate Lawson     {
47659db4265SNate Lawson         Status = AdGetLocalTables (Filename, GetAllTables);
47759db4265SNate Lawson         if (ACPI_FAILURE (Status))
47859db4265SNate Lawson         {
47959db4265SNate Lawson             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
48059db4265SNate Lawson                 AcpiFormatException (Status));
48159db4265SNate Lawson             return Status;
48259db4265SNate Lawson         }
48359db4265SNate Lawson 
48459db4265SNate Lawson         if (!AcpiGbl_DbOpt_disasm)
48559db4265SNate Lawson         {
48659db4265SNate Lawson             return AE_OK;
48759db4265SNate Lawson         }
48859db4265SNate Lawson 
4891a39cfb0SJung-uk Kim         /* Obtained the local tables, just disassemble the DSDT */
49059db4265SNate Lawson 
4911a39cfb0SJung-uk Kim         Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
4921a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
4931a39cfb0SJung-uk Kim         {
4941a39cfb0SJung-uk Kim             AcpiOsPrintf ("Could not get DSDT, %s\n",
4951a39cfb0SJung-uk Kim                 AcpiFormatException (Status));
4961a39cfb0SJung-uk Kim             return Status;
4971a39cfb0SJung-uk Kim         }
4981a39cfb0SJung-uk Kim 
49959db4265SNate Lawson         AcpiOsPrintf ("\nDisassembly of DSDT\n");
5001a39cfb0SJung-uk Kim         Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
50159db4265SNate Lawson     }
50259db4265SNate Lawson 
50359db4265SNate Lawson     /*
50459db4265SNate Lawson      * Output:  ASL code.
50559db4265SNate Lawson      *          Redirect to a file if requested
50659db4265SNate Lawson      */
50759db4265SNate Lawson     if (OutToFile)
50859db4265SNate Lawson     {
50959db4265SNate Lawson         /* Create/Open a disassembly output file */
51059db4265SNate Lawson 
51159db4265SNate Lawson         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
51259db4265SNate Lawson         if (!OutFilename)
51359db4265SNate Lawson         {
51459db4265SNate Lawson             fprintf (stderr, "Could not generate output filename\n");
515e50beb51SNate Lawson             Status = AE_ERROR;
516e50beb51SNate Lawson             goto Cleanup;
51759db4265SNate Lawson         }
51859db4265SNate Lawson 
51959db4265SNate Lawson         File = fopen (DisasmFilename, "w+");
52059db4265SNate Lawson         if (!File)
52159db4265SNate Lawson         {
5221a39cfb0SJung-uk Kim             fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
523e50beb51SNate Lawson             Status = AE_ERROR;
524e50beb51SNate Lawson             goto Cleanup;
52559db4265SNate Lawson         }
52659db4265SNate Lawson 
52759db4265SNate Lawson         AcpiOsRedirectOutput (File);
52859db4265SNate Lawson     }
52959db4265SNate Lawson 
53059db4265SNate Lawson     *OutFilename = DisasmFilename;
53159db4265SNate Lawson 
5321a39cfb0SJung-uk Kim     if (!AcpiUtIsAmlTable (Table))
5331a39cfb0SJung-uk Kim     {
5341a39cfb0SJung-uk Kim         AdDisassemblerHeader (Filename);
5351a39cfb0SJung-uk Kim         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
5361a39cfb0SJung-uk Kim             Table->Signature);
5371a39cfb0SJung-uk Kim         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  FieldName : FieldValue\n */\n\n");
5381a39cfb0SJung-uk Kim 
5391a39cfb0SJung-uk Kim         AcpiDmDumpDataTable (Table);
5401a39cfb0SJung-uk Kim         fprintf (stderr, "Acpi Data Table [%4.4s] decoded, written to \"%s\"\n",
5411a39cfb0SJung-uk Kim             Table->Signature, DisasmFilename);
5421a39cfb0SJung-uk Kim     }
5431a39cfb0SJung-uk Kim     else
5441a39cfb0SJung-uk Kim     {
54559db4265SNate Lawson         /* Always parse the tables, only option is what to display */
54659db4265SNate Lawson 
547a9f12690SJung-uk Kim         Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
54859db4265SNate Lawson         if (ACPI_FAILURE (Status))
54959db4265SNate Lawson         {
55059db4265SNate Lawson             AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
55159db4265SNate Lawson                 AcpiFormatException (Status));
55259db4265SNate Lawson             goto Cleanup;
55359db4265SNate Lawson         }
55459db4265SNate Lawson 
5551a39cfb0SJung-uk Kim         if (AslCompilerdebug)
5561a39cfb0SJung-uk Kim         {
5571a39cfb0SJung-uk Kim             AcpiOsPrintf ("/**** Before second load\n");
5581a39cfb0SJung-uk Kim 
5591a39cfb0SJung-uk Kim             LsSetupNsList (File);
5601a39cfb0SJung-uk Kim             LsDisplayNamespace ();
5611a39cfb0SJung-uk Kim             AcpiOsPrintf ("*****/\n");
5621a39cfb0SJung-uk Kim         }
5631a39cfb0SJung-uk Kim 
564e0ef747bSNate Lawson         /*
5651a39cfb0SJung-uk Kim          * Load namespace from names created within control methods
566e0ef747bSNate Lawson          */
567a9f12690SJung-uk Kim         AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
5681a39cfb0SJung-uk Kim 
5691a39cfb0SJung-uk Kim         /*
5701a39cfb0SJung-uk Kim          * Cross reference the namespace here, in order to generate External() statements
5711a39cfb0SJung-uk Kim          */
572a9f12690SJung-uk Kim         AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
5731a39cfb0SJung-uk Kim 
5741a39cfb0SJung-uk Kim         if (AslCompilerdebug)
5751a39cfb0SJung-uk Kim         {
5761a39cfb0SJung-uk Kim             AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
5771a39cfb0SJung-uk Kim         }
5781a39cfb0SJung-uk Kim 
5791a39cfb0SJung-uk Kim         /* Find possible calls to external control methods */
5801a39cfb0SJung-uk Kim 
5811a39cfb0SJung-uk Kim         AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
5821a39cfb0SJung-uk Kim 
5831a39cfb0SJung-uk Kim         /* Convert fixed-offset references to resource descriptors to symbolic references */
5841a39cfb0SJung-uk Kim 
5851a39cfb0SJung-uk Kim         AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
5861a39cfb0SJung-uk Kim 
5871a39cfb0SJung-uk Kim         /*
5881a39cfb0SJung-uk Kim          * If we found any external control methods, we must reparse the entire
5891a39cfb0SJung-uk Kim          * tree with the new information (namely, the number of arguments per
5901a39cfb0SJung-uk Kim          * method)
5911a39cfb0SJung-uk Kim          */
5921a39cfb0SJung-uk Kim         if (AdMethodExternalCount ())
5931a39cfb0SJung-uk Kim         {
5941a39cfb0SJung-uk Kim             fprintf (stderr,
5951a39cfb0SJung-uk Kim                 "\nFound %d external control methods, reparsing with new information\n",
5961a39cfb0SJung-uk Kim                 AdMethodExternalCount());
5971a39cfb0SJung-uk Kim 
5981a39cfb0SJung-uk Kim             /*
5991a39cfb0SJung-uk Kim              * Reparse, rebuild namespace. no need to xref namespace
6001a39cfb0SJung-uk Kim              */
6011a39cfb0SJung-uk Kim             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
6021a39cfb0SJung-uk Kim             AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
6031a39cfb0SJung-uk Kim 
6041a39cfb0SJung-uk Kim             AcpiGbl_RootNode                    = NULL;
6051a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
6061a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
6071a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
6081a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Child        = NULL;
6091a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Peer         = NULL;
6101a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Object       = NULL;
6111a39cfb0SJung-uk Kim             AcpiGbl_RootNodeStruct.Flags        = ANOBJ_END_OF_PEER_LIST;
6121a39cfb0SJung-uk Kim 
6131a39cfb0SJung-uk Kim             Status = AcpiNsRootInitialize ();
6141a39cfb0SJung-uk Kim             AdAddExternalsToNamespace ();
6151a39cfb0SJung-uk Kim 
616a9f12690SJung-uk Kim             /* Parse table. No need to reload it, however (FALSE) */
617a9f12690SJung-uk Kim 
618a9f12690SJung-uk Kim             Status = AdParseTable (Table, NULL, FALSE, FALSE);
6191a39cfb0SJung-uk Kim             if (ACPI_FAILURE (Status))
6201a39cfb0SJung-uk Kim             {
6211a39cfb0SJung-uk Kim                 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
6221a39cfb0SJung-uk Kim                     AcpiFormatException (Status));
6231a39cfb0SJung-uk Kim                 goto Cleanup;
6241a39cfb0SJung-uk Kim             }
6251a39cfb0SJung-uk Kim 
6261a39cfb0SJung-uk Kim             if (AslCompilerdebug)
6271a39cfb0SJung-uk Kim             {
628a9f12690SJung-uk Kim                 AcpiOsPrintf ("/**** After second load and resource conversion\n");
629a9f12690SJung-uk Kim                 LsSetupNsList (File);
630a9f12690SJung-uk Kim                 LsDisplayNamespace ();
631a9f12690SJung-uk Kim                 AcpiOsPrintf ("*****/\n");
632a9f12690SJung-uk Kim 
6331a39cfb0SJung-uk Kim                 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
6341a39cfb0SJung-uk Kim             }
6351a39cfb0SJung-uk Kim         }
636e0ef747bSNate Lawson 
63759db4265SNate Lawson         /* Optional displays */
63859db4265SNate Lawson 
63959db4265SNate Lawson         if (AcpiGbl_DbOpt_disasm)
64059db4265SNate Lawson         {
64159db4265SNate Lawson             AdDisplayTables (Filename, Table);
6421a39cfb0SJung-uk Kim             fprintf (stderr,
6431a39cfb0SJung-uk Kim                 "Disassembly completed, written to \"%s\"\n",
6441a39cfb0SJung-uk Kim                 DisasmFilename);
6451a39cfb0SJung-uk Kim         }
64659db4265SNate Lawson     }
64759db4265SNate Lawson 
64859db4265SNate Lawson Cleanup:
649a9f12690SJung-uk Kim 
650a9f12690SJung-uk Kim     if (Table && !AcpiUtIsAmlTable (Table))
651a9f12690SJung-uk Kim     {
652a9f12690SJung-uk Kim         ACPI_FREE (Table);
653a9f12690SJung-uk Kim     }
654a9f12690SJung-uk Kim 
655a9f12690SJung-uk Kim     if (DisasmFilename)
656a9f12690SJung-uk Kim     {
657a9f12690SJung-uk Kim         ACPI_FREE (DisasmFilename);
658a9f12690SJung-uk Kim     }
659a9f12690SJung-uk Kim 
6601a39cfb0SJung-uk Kim     if (OutToFile && File)
66159db4265SNate Lawson     {
6621a39cfb0SJung-uk Kim 
6631a39cfb0SJung-uk Kim #ifdef ASL_DISASM_DEBUG
6641a39cfb0SJung-uk Kim         LsSetupNsList (File);
6651a39cfb0SJung-uk Kim         LsDisplayNamespace ();
6661a39cfb0SJung-uk Kim #endif
66759db4265SNate Lawson         fclose (File);
66859db4265SNate Lawson         AcpiOsRedirectOutput (stdout);
66959db4265SNate Lawson     }
67059db4265SNate Lawson 
6711a39cfb0SJung-uk Kim     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
672a9f12690SJung-uk Kim     AcpiGbl_ParseOpRoot = NULL;
673a9f12690SJung-uk Kim     return (Status);
67459db4265SNate Lawson }
67559db4265SNate Lawson 
67659db4265SNate Lawson 
67759db4265SNate Lawson /******************************************************************************
67859db4265SNate Lawson  *
6791a39cfb0SJung-uk Kim  * FUNCTION:    AdDisassemblerHeader
6801a39cfb0SJung-uk Kim  *
6811a39cfb0SJung-uk Kim  * PARAMETERS:  Filename            - Input file for the table
6821a39cfb0SJung-uk Kim  *
6831a39cfb0SJung-uk Kim  * RETURN:      None
6841a39cfb0SJung-uk Kim  *
6851a39cfb0SJung-uk Kim  * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
6861a39cfb0SJung-uk Kim  *              current time and date.
6871a39cfb0SJung-uk Kim  *
6881a39cfb0SJung-uk Kim  *****************************************************************************/
6891a39cfb0SJung-uk Kim 
6901a39cfb0SJung-uk Kim void
6911a39cfb0SJung-uk Kim AdDisassemblerHeader (
6921a39cfb0SJung-uk Kim     char                    *Filename)
6931a39cfb0SJung-uk Kim {
6941a39cfb0SJung-uk Kim     time_t                  Timer;
6951a39cfb0SJung-uk Kim 
6961a39cfb0SJung-uk Kim     time (&Timer);
6971a39cfb0SJung-uk Kim 
6981a39cfb0SJung-uk Kim     /* Header and input table info */
6991a39cfb0SJung-uk Kim 
7001a39cfb0SJung-uk Kim     AcpiOsPrintf ("/*\n * Intel ACPI Component Architecture\n");
7011a39cfb0SJung-uk Kim     AcpiOsPrintf (" * AML Disassembler version %8.8X\n", ACPI_CA_VERSION);
7021a39cfb0SJung-uk Kim 
7031a39cfb0SJung-uk Kim     AcpiOsPrintf (" *\n * Disassembly of %s, %s", Filename, ctime (&Timer));
7041a39cfb0SJung-uk Kim     AcpiOsPrintf (" *\n");
7051a39cfb0SJung-uk Kim }
7061a39cfb0SJung-uk Kim 
7071a39cfb0SJung-uk Kim 
7081a39cfb0SJung-uk Kim /******************************************************************************
7091a39cfb0SJung-uk Kim  *
71059db4265SNate Lawson  * FUNCTION:    AdCreateTableHeader
71159db4265SNate Lawson  *
71259db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
71359db4265SNate Lawson  *              Table               - Pointer to the raw table
71459db4265SNate Lawson  *
71559db4265SNate Lawson  * RETURN:      None
71659db4265SNate Lawson  *
71759db4265SNate Lawson  * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
71859db4265SNate Lawson  *              current time and date.
71959db4265SNate Lawson  *
72059db4265SNate Lawson  *****************************************************************************/
72159db4265SNate Lawson 
72259db4265SNate Lawson void
72359db4265SNate Lawson AdCreateTableHeader (
72459db4265SNate Lawson     char                    *Filename,
72559db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
72659db4265SNate Lawson {
7271a39cfb0SJung-uk Kim     char                    *NewFilename;
728a9f12690SJung-uk Kim     UINT8                   Checksum;
72959db4265SNate Lawson 
73059db4265SNate Lawson 
731a9f12690SJung-uk Kim     /*
732a9f12690SJung-uk Kim      * Print file header and dump original table header
733a9f12690SJung-uk Kim      */
7341a39cfb0SJung-uk Kim     AdDisassemblerHeader (Filename);
73559db4265SNate Lawson 
7361a39cfb0SJung-uk Kim     AcpiOsPrintf (" *\n * Original Table Header:\n");
7371a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     Signature        \"%4.4s\"\n",    Table->Signature);
7381a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     Length           0x%8.8X (%u)\n", Table->Length, Table->Length);
739a9f12690SJung-uk Kim 
740a9f12690SJung-uk Kim     /* Print and validate the revision */
741a9f12690SJung-uk Kim 
742a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Revision         0x%2.2X",      Table->Revision);
743a9f12690SJung-uk Kim 
744a9f12690SJung-uk Kim     switch (Table->Revision)
745a9f12690SJung-uk Kim     {
746a9f12690SJung-uk Kim     case 0:
747a9f12690SJung-uk Kim         AcpiOsPrintf (" **** Invalid Revision");
748a9f12690SJung-uk Kim         break;
749a9f12690SJung-uk Kim 
750a9f12690SJung-uk Kim     case 1:
751a9f12690SJung-uk Kim         /* Revision of DSDT controls the ACPI integer width */
752a9f12690SJung-uk Kim 
753a9f12690SJung-uk Kim         if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
754a9f12690SJung-uk Kim         {
755a9f12690SJung-uk Kim             AcpiOsPrintf (" **** ACPI 1.0, no 64-bit math support");
756a9f12690SJung-uk Kim         }
757a9f12690SJung-uk Kim         break;
758a9f12690SJung-uk Kim 
759a9f12690SJung-uk Kim     default:
760a9f12690SJung-uk Kim         break;
761a9f12690SJung-uk Kim     }
762a9f12690SJung-uk Kim     AcpiOsPrintf ("\n");
763a9f12690SJung-uk Kim 
764a9f12690SJung-uk Kim     /* Print and validate the table checksum */
765a9f12690SJung-uk Kim 
766a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Checksum         0x%2.2X",        Table->Checksum);
767a9f12690SJung-uk Kim 
768a9f12690SJung-uk Kim     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
769a9f12690SJung-uk Kim     if (Checksum)
770a9f12690SJung-uk Kim     {
771a9f12690SJung-uk Kim         AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
772a9f12690SJung-uk Kim             (UINT8) (Table->Checksum - Checksum));
773a9f12690SJung-uk Kim     }
774a9f12690SJung-uk Kim     AcpiOsPrintf ("\n");
775a9f12690SJung-uk Kim 
7761a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM ID           \"%.6s\"\n",     Table->OemId);
7771a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM Table ID     \"%.8s\"\n",     Table->OemTableId);
7781a39cfb0SJung-uk Kim     AcpiOsPrintf (" *     OEM Revision     0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
779a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Compiler ID      \"%.4s\"\n",     Table->AslCompilerId);
780a9f12690SJung-uk Kim     AcpiOsPrintf (" *     Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
7811a39cfb0SJung-uk Kim     AcpiOsPrintf (" */\n");
7821a39cfb0SJung-uk Kim 
7831a39cfb0SJung-uk Kim     /* Create AML output filename based on input filename */
7841a39cfb0SJung-uk Kim 
7851a39cfb0SJung-uk Kim     if (Filename)
7861a39cfb0SJung-uk Kim     {
7871a39cfb0SJung-uk Kim         NewFilename = FlGenerateFilename (Filename, "aml");
7881a39cfb0SJung-uk Kim     }
7891a39cfb0SJung-uk Kim     else
7901a39cfb0SJung-uk Kim     {
7911a39cfb0SJung-uk Kim         NewFilename = ACPI_ALLOCATE_ZEROED (9);
7921a39cfb0SJung-uk Kim         strncat (NewFilename, Table->Signature, 4);
7931a39cfb0SJung-uk Kim         strcat (NewFilename, ".aml");
7941a39cfb0SJung-uk Kim     }
7951a39cfb0SJung-uk Kim 
7961a39cfb0SJung-uk Kim     /* Open the ASL definition block */
79759db4265SNate Lawson 
79859db4265SNate Lawson     AcpiOsPrintf (
7991a39cfb0SJung-uk Kim         "DefinitionBlock (\"%s\", \"%4.4s\", %hd, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
8001a39cfb0SJung-uk Kim         NewFilename, Table->Signature, Table->Revision,
80159db4265SNate Lawson         Table->OemId, Table->OemTableId, Table->OemRevision);
802a9f12690SJung-uk Kim 
803a9f12690SJung-uk Kim     ACPI_FREE (NewFilename);
80459db4265SNate Lawson }
80559db4265SNate Lawson 
80659db4265SNate Lawson 
80759db4265SNate Lawson /******************************************************************************
80859db4265SNate Lawson  *
80959db4265SNate Lawson  * FUNCTION:    AdDisplayTables
81059db4265SNate Lawson  *
81159db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
812fba7fc7eSJung-uk Kim  *              Table               - Pointer to the raw table
81359db4265SNate Lawson  *
81459db4265SNate Lawson  * RETURN:      Status
81559db4265SNate Lawson  *
81659db4265SNate Lawson  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
81759db4265SNate Lawson  *
81859db4265SNate Lawson  *****************************************************************************/
81959db4265SNate Lawson 
82059db4265SNate Lawson ACPI_STATUS
82159db4265SNate Lawson AdDisplayTables (
82259db4265SNate Lawson     char                    *Filename,
82359db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
82459db4265SNate Lawson {
82559db4265SNate Lawson 
82659db4265SNate Lawson 
8271a39cfb0SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
82859db4265SNate Lawson     {
82959db4265SNate Lawson         return AE_NOT_EXIST;
83059db4265SNate Lawson     }
83159db4265SNate Lawson 
83259db4265SNate Lawson     if (!AcpiGbl_DbOpt_verbose)
83359db4265SNate Lawson     {
83459db4265SNate Lawson         AdCreateTableHeader (Filename, Table);
83559db4265SNate Lawson     }
83659db4265SNate Lawson 
8371a39cfb0SJung-uk Kim     AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
83859db4265SNate Lawson 
83959db4265SNate Lawson     if (AcpiGbl_DbOpt_verbose)
84059db4265SNate Lawson     {
84159db4265SNate Lawson         AcpiOsPrintf ("\n\nTable Header:\n");
84259db4265SNate Lawson         AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
84359db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
84459db4265SNate Lawson 
84559db4265SNate Lawson         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
84659db4265SNate Lawson         AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
84759db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
84859db4265SNate Lawson     }
84959db4265SNate Lawson 
85059db4265SNate Lawson     return AE_OK;
85159db4265SNate Lawson }
85259db4265SNate Lawson 
85359db4265SNate Lawson 
85459db4265SNate Lawson /******************************************************************************
85559db4265SNate Lawson  *
85659db4265SNate Lawson  * FUNCTION:    AdDeferredParse
85759db4265SNate Lawson  *
85859db4265SNate Lawson  * PARAMETERS:  Op              - Root Op of the deferred opcode
85959db4265SNate Lawson  *              Aml             - Pointer to the raw AML
86059db4265SNate Lawson  *              AmlLength       - Length of the AML
86159db4265SNate Lawson  *
86259db4265SNate Lawson  * RETURN:      Status
86359db4265SNate Lawson  *
86459db4265SNate Lawson  * DESCRIPTION: Parse one deferred opcode
86559db4265SNate Lawson  *              (Methods, operation regions, etc.)
86659db4265SNate Lawson  *
86759db4265SNate Lawson  *****************************************************************************/
86859db4265SNate Lawson 
86959db4265SNate Lawson ACPI_STATUS
87059db4265SNate Lawson AdDeferredParse (
87159db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
87259db4265SNate Lawson     UINT8                   *Aml,
87359db4265SNate Lawson     UINT32                  AmlLength)
87459db4265SNate Lawson {
87559db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
87659db4265SNate Lawson     ACPI_STATUS             Status;
87759db4265SNate Lawson     ACPI_PARSE_OBJECT       *SearchOp;
87859db4265SNate Lawson     ACPI_PARSE_OBJECT       *StartOp;
87959db4265SNate Lawson     UINT32                  BaseAmlOffset;
88059db4265SNate Lawson     ACPI_PARSE_OBJECT       *ExtraOp;
88159db4265SNate Lawson 
88259db4265SNate Lawson 
8831a39cfb0SJung-uk Kim     ACPI_FUNCTION_TRACE (AdDeferredParse);
88459db4265SNate Lawson 
88559db4265SNate Lawson 
88659db4265SNate Lawson     fprintf (stderr, ".");
88759db4265SNate Lawson 
88859db4265SNate Lawson     if (!Aml || !AmlLength)
88959db4265SNate Lawson     {
89059db4265SNate Lawson         return_ACPI_STATUS (AE_OK);
89159db4265SNate Lawson     }
89259db4265SNate Lawson 
89359db4265SNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
89459db4265SNate Lawson         Op->Common.AmlOpName, (char *) &Op->Named.Name));
89559db4265SNate Lawson 
89659db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
89759db4265SNate Lawson     if (!WalkState)
89859db4265SNate Lawson     {
89959db4265SNate Lawson         return_ACPI_STATUS (AE_NO_MEMORY);
90059db4265SNate Lawson     }
90159db4265SNate Lawson 
90259db4265SNate Lawson     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
9031a39cfb0SJung-uk Kim                     AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
90459db4265SNate Lawson     if (ACPI_FAILURE (Status))
90559db4265SNate Lawson     {
90659db4265SNate Lawson         return_ACPI_STATUS (Status);
90759db4265SNate Lawson     }
90859db4265SNate Lawson 
90959db4265SNate Lawson     /* Parse the method */
91059db4265SNate Lawson 
91159db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
912fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
91359db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
91459db4265SNate Lawson 
91559db4265SNate Lawson     /*
91659db4265SNate Lawson      * We need to update all of the Aml offsets, since the parser thought
91759db4265SNate Lawson      * that the method began at offset zero.  In reality, it began somewhere
91859db4265SNate Lawson      * within the ACPI table, at the BaseAmlOffset.  Walk the entire tree that
91959db4265SNate Lawson      * was just created and update the AmlOffset in each Op
92059db4265SNate Lawson      */
92159db4265SNate Lawson     BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
92259db4265SNate Lawson     StartOp = (Op->Common.Value.Arg)->Common.Next;
92359db4265SNate Lawson     SearchOp = StartOp;
92459db4265SNate Lawson 
92559db4265SNate Lawson     /* Walk the parse tree */
92659db4265SNate Lawson 
92759db4265SNate Lawson     while (SearchOp)
92859db4265SNate Lawson     {
92959db4265SNate Lawson         SearchOp->Common.AmlOffset += BaseAmlOffset;
93059db4265SNate Lawson         SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
93159db4265SNate Lawson     }
93259db4265SNate Lawson 
93359db4265SNate Lawson     /*
93459db4265SNate Lawson      * Link the newly parsed subtree into the main parse tree
93559db4265SNate Lawson      */
93659db4265SNate Lawson     switch (Op->Common.AmlOpcode)
93759db4265SNate Lawson     {
93859db4265SNate Lawson     case AML_BUFFER_OP:
93959db4265SNate Lawson     case AML_PACKAGE_OP:
94059db4265SNate Lawson     case AML_VAR_PACKAGE_OP:
94159db4265SNate Lawson 
94259db4265SNate Lawson         switch (Op->Common.AmlOpcode)
94359db4265SNate Lawson         {
94459db4265SNate Lawson         case AML_PACKAGE_OP:
94559db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
94659db4265SNate Lawson             ExtraOp = ExtraOp->Common.Next;
94759db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
94859db4265SNate Lawson             break;
94959db4265SNate Lawson 
950fba7fc7eSJung-uk Kim         case AML_VAR_PACKAGE_OP:
95159db4265SNate Lawson         case AML_BUFFER_OP:
95259db4265SNate Lawson         default:
95359db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
95459db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
95559db4265SNate Lawson             break;
95659db4265SNate Lawson         }
95759db4265SNate Lawson 
95859db4265SNate Lawson         /* Must point all parents to the main tree */
95959db4265SNate Lawson 
96059db4265SNate Lawson         StartOp = Op;
96159db4265SNate Lawson         SearchOp = StartOp;
96259db4265SNate Lawson         while (SearchOp)
96359db4265SNate Lawson         {
96459db4265SNate Lawson             if (SearchOp->Common.Parent == ExtraOp)
96559db4265SNate Lawson             {
96659db4265SNate Lawson                 SearchOp->Common.Parent = Op;
96759db4265SNate Lawson             }
96859db4265SNate Lawson             SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
96959db4265SNate Lawson         }
97059db4265SNate Lawson         break;
97159db4265SNate Lawson 
97259db4265SNate Lawson     default:
97359db4265SNate Lawson         break;
97459db4265SNate Lawson     }
97559db4265SNate Lawson 
97659db4265SNate Lawson     return_ACPI_STATUS (AE_OK);
97759db4265SNate Lawson }
97859db4265SNate Lawson 
97959db4265SNate Lawson 
98059db4265SNate Lawson /******************************************************************************
98159db4265SNate Lawson  *
98259db4265SNate Lawson  * FUNCTION:    AdParseDeferredOps
98359db4265SNate Lawson  *
98459db4265SNate Lawson  * PARAMETERS:  Root            - Root of the parse tree
98559db4265SNate Lawson  *
98659db4265SNate Lawson  * RETURN:      Status
98759db4265SNate Lawson  *
98859db4265SNate Lawson  * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
98959db4265SNate Lawson  *
99059db4265SNate Lawson  *****************************************************************************/
99159db4265SNate Lawson 
99259db4265SNate Lawson ACPI_STATUS
99359db4265SNate Lawson AdParseDeferredOps (
99459db4265SNate Lawson     ACPI_PARSE_OBJECT       *Root)
99559db4265SNate Lawson {
99659db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op = Root;
99759db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
99859db4265SNate Lawson     const ACPI_OPCODE_INFO  *OpInfo;
99959db4265SNate Lawson 
100059db4265SNate Lawson 
10011a39cfb0SJung-uk Kim     ACPI_FUNCTION_NAME (AdParseDeferredOps);
100259db4265SNate Lawson     fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
100359db4265SNate Lawson 
100459db4265SNate Lawson     while (Op)
100559db4265SNate Lawson     {
100659db4265SNate Lawson         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
100759db4265SNate Lawson         if (!(OpInfo->Flags & AML_DEFER))
100859db4265SNate Lawson         {
100959db4265SNate Lawson             Op = AcpiPsGetDepthNext (Root, Op);
101059db4265SNate Lawson             continue;
101159db4265SNate Lawson         }
101259db4265SNate Lawson 
101359db4265SNate Lawson         switch (Op->Common.AmlOpcode)
101459db4265SNate Lawson         {
101559db4265SNate Lawson         case AML_METHOD_OP:
101659db4265SNate Lawson         case AML_BUFFER_OP:
101759db4265SNate Lawson         case AML_PACKAGE_OP:
101859db4265SNate Lawson         case AML_VAR_PACKAGE_OP:
101959db4265SNate Lawson 
102059db4265SNate Lawson             Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
102159db4265SNate Lawson             if (ACPI_FAILURE (Status))
102259db4265SNate Lawson             {
102359db4265SNate Lawson                 return_ACPI_STATUS (Status);
102459db4265SNate Lawson             }
102559db4265SNate Lawson             break;
102659db4265SNate Lawson 
102759db4265SNate Lawson         case AML_REGION_OP:
102859db4265SNate Lawson         case AML_CREATE_QWORD_FIELD_OP:
102959db4265SNate Lawson         case AML_CREATE_DWORD_FIELD_OP:
103059db4265SNate Lawson         case AML_CREATE_WORD_FIELD_OP:
103159db4265SNate Lawson         case AML_CREATE_BYTE_FIELD_OP:
103259db4265SNate Lawson         case AML_CREATE_BIT_FIELD_OP:
103359db4265SNate Lawson         case AML_CREATE_FIELD_OP:
1034a9f12690SJung-uk Kim         case AML_BANK_FIELD_OP:
103559db4265SNate Lawson 
103659db4265SNate Lawson             /* Nothing to do in these cases */
103759db4265SNate Lawson 
103859db4265SNate Lawson             break;
103959db4265SNate Lawson 
104059db4265SNate Lawson         default:
10411a39cfb0SJung-uk Kim             ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
104259db4265SNate Lawson                 Op->Common.AmlOpName));
104359db4265SNate Lawson             break;
104459db4265SNate Lawson         }
104559db4265SNate Lawson 
104659db4265SNate Lawson         Op = AcpiPsGetDepthNext (Root, Op);
104759db4265SNate Lawson     }
104859db4265SNate Lawson 
104959db4265SNate Lawson     fprintf (stderr, "\n");
105059db4265SNate Lawson     return Status;
105159db4265SNate Lawson }
105259db4265SNate Lawson 
105359db4265SNate Lawson 
105459db4265SNate Lawson /******************************************************************************
105559db4265SNate Lawson  *
105659db4265SNate Lawson  * FUNCTION:    AdGetLocalTables
105759db4265SNate Lawson  *
1058fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename        - Not used
1059fba7fc7eSJung-uk Kim  *              GetAllTables    - TRUE if all tables are desired
106059db4265SNate Lawson  *
1061fba7fc7eSJung-uk Kim  * RETURN:      Status
106259db4265SNate Lawson  *
106359db4265SNate Lawson  * DESCRIPTION: Get the ACPI tables from either memory or a file
106459db4265SNate Lawson  *
106559db4265SNate Lawson  *****************************************************************************/
106659db4265SNate Lawson 
106759db4265SNate Lawson ACPI_STATUS
106859db4265SNate Lawson AdGetLocalTables (
106959db4265SNate Lawson     char                    *Filename,
107059db4265SNate Lawson     BOOLEAN                 GetAllTables)
107159db4265SNate Lawson {
107259db4265SNate Lawson     ACPI_STATUS             Status;
107359db4265SNate Lawson     ACPI_TABLE_HEADER       TableHeader;
107459db4265SNate Lawson     ACPI_TABLE_HEADER       *NewTable;
107559db4265SNate Lawson     UINT32                  NumTables;
107659db4265SNate Lawson     UINT32                  PointerSize;
1077a9f12690SJung-uk Kim     UINT32                  TableIndex;
107859db4265SNate Lawson 
107959db4265SNate Lawson 
108059db4265SNate Lawson     if (GetAllTables)
108159db4265SNate Lawson     {
10821a39cfb0SJung-uk Kim         ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
108359db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
1084e50beb51SNate Lawson         if (!NewTable)
1085e50beb51SNate Lawson         {
1086e50beb51SNate Lawson             fprintf (stderr, "Could not obtain RSDT\n");
1087e50beb51SNate Lawson             return AE_NO_ACPI_TABLES;
1088e50beb51SNate Lawson         }
1089a9f12690SJung-uk Kim         else
1090a9f12690SJung-uk Kim         {
1091a9f12690SJung-uk Kim             AdWriteTable (NewTable, NewTable->Length,
1092a9f12690SJung-uk Kim                 ACPI_SIG_RSDT, NewTable->OemTableId);
1093a9f12690SJung-uk Kim         }
109459db4265SNate Lawson 
10951a39cfb0SJung-uk Kim         if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
109659db4265SNate Lawson         {
109759db4265SNate Lawson             PointerSize = sizeof (UINT32);
109859db4265SNate Lawson         }
109959db4265SNate Lawson         else
110059db4265SNate Lawson         {
110159db4265SNate Lawson             PointerSize = sizeof (UINT64);
110259db4265SNate Lawson         }
110359db4265SNate Lawson 
110459db4265SNate Lawson         /*
110559db4265SNate Lawson          * Determine the number of tables pointed to by the RSDT/XSDT.
110659db4265SNate Lawson          * This is defined by the ACPI Specification to be the number of
110759db4265SNate Lawson          * pointers contained within the RSDT/XSDT.  The size of the pointers
110859db4265SNate Lawson          * is architecture-dependent.
110959db4265SNate Lawson          */
111059db4265SNate Lawson         NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
111159db4265SNate Lawson         AcpiOsPrintf ("There are %d tables defined in the %4.4s\n\n",
111259db4265SNate Lawson             NumTables, NewTable->Signature);
111359db4265SNate Lawson 
111459db4265SNate Lawson         /* Get the FADT */
111559db4265SNate Lawson 
11161a39cfb0SJung-uk Kim         ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
111759db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
111859db4265SNate Lawson         if (NewTable)
111959db4265SNate Lawson         {
112059db4265SNate Lawson             AdWriteTable (NewTable, NewTable->Length,
11211a39cfb0SJung-uk Kim                 ACPI_SIG_FADT, NewTable->OemTableId);
112259db4265SNate Lawson         }
112359db4265SNate Lawson         AcpiOsPrintf ("\n");
112459db4265SNate Lawson 
11251a39cfb0SJung-uk Kim         /* Don't bother with FACS, it is usually all zeros */
112659db4265SNate Lawson     }
112759db4265SNate Lawson 
112859db4265SNate Lawson     /* Always get the DSDT */
112959db4265SNate Lawson 
11301a39cfb0SJung-uk Kim     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
113159db4265SNate Lawson     AcpiOsTableOverride (&TableHeader, &NewTable);
113259db4265SNate Lawson     if (NewTable)
113359db4265SNate Lawson     {
11341a39cfb0SJung-uk Kim         AdWriteTable (NewTable, NewTable->Length,
11351a39cfb0SJung-uk Kim             ACPI_SIG_DSDT, NewTable->OemTableId);
11361a39cfb0SJung-uk Kim 
11371a39cfb0SJung-uk Kim         /* Store DSDT in the Table Manager */
11381a39cfb0SJung-uk Kim 
11391a39cfb0SJung-uk Kim         Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
11401a39cfb0SJung-uk Kim                     0, &TableIndex);
114159db4265SNate Lawson     }
114259db4265SNate Lawson     else
114359db4265SNate Lawson     {
114459db4265SNate Lawson         fprintf (stderr, "Could not obtain DSDT\n");
1145e50beb51SNate Lawson         return AE_NO_ACPI_TABLES;
114659db4265SNate Lawson     }
114759db4265SNate Lawson 
11481a39cfb0SJung-uk Kim #if 0
11491a39cfb0SJung-uk Kim     /* TBD: Future implementation */
11501a39cfb0SJung-uk Kim 
115159db4265SNate Lawson     AcpiOsPrintf ("\n");
115259db4265SNate Lawson 
115359db4265SNate Lawson     /* Get all SSDTs */
115459db4265SNate Lawson 
11551a39cfb0SJung-uk Kim     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
11561a39cfb0SJung-uk Kim     do
115759db4265SNate Lawson     {
11581a39cfb0SJung-uk Kim         NewTable = NULL;
115959db4265SNate Lawson         Status = AcpiOsTableOverride (&TableHeader, &NewTable);
11601a39cfb0SJung-uk Kim 
11611a39cfb0SJung-uk Kim     } while (NewTable);
11621a39cfb0SJung-uk Kim #endif
116359db4265SNate Lawson 
116459db4265SNate Lawson     return AE_OK;
116559db4265SNate Lawson }
116659db4265SNate Lawson 
11671a39cfb0SJung-uk Kim 
116859db4265SNate Lawson /******************************************************************************
116959db4265SNate Lawson  *
117059db4265SNate Lawson  * FUNCTION:    AdParseTable
117159db4265SNate Lawson  *
1172fba7fc7eSJung-uk Kim  * PARAMETERS:  Table           - Pointer to the raw table
1173a9f12690SJung-uk Kim  *              OwnerId         - Returned OwnerId of the table
1174a9f12690SJung-uk Kim  *              LoadTable       - If add table to the global table list
1175a9f12690SJung-uk Kim  *              External        - If this is an external table
117659db4265SNate Lawson  *
117759db4265SNate Lawson  * RETURN:      Status
117859db4265SNate Lawson  *
117959db4265SNate Lawson  * DESCRIPTION: Parse the DSDT.
118059db4265SNate Lawson  *
118159db4265SNate Lawson  *****************************************************************************/
118259db4265SNate Lawson 
118359db4265SNate Lawson ACPI_STATUS
118459db4265SNate Lawson AdParseTable (
1185a9f12690SJung-uk Kim     ACPI_TABLE_HEADER       *Table,
1186a9f12690SJung-uk Kim     ACPI_OWNER_ID           *OwnerId,
1187a9f12690SJung-uk Kim     BOOLEAN                 LoadTable,
1188a9f12690SJung-uk Kim     BOOLEAN                 External)
118959db4265SNate Lawson {
119059db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
119159db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
119259db4265SNate Lawson     UINT8                   *AmlStart;
119359db4265SNate Lawson     UINT32                  AmlLength;
1194a9f12690SJung-uk Kim     UINT32                  TableIndex;
119559db4265SNate Lawson 
119659db4265SNate Lawson 
119759db4265SNate Lawson     if (!Table)
119859db4265SNate Lawson     {
119959db4265SNate Lawson         return AE_NOT_EXIST;
120059db4265SNate Lawson     }
120159db4265SNate Lawson 
120259db4265SNate Lawson     /* Pass 1:  Parse everything except control method bodies */
120359db4265SNate Lawson 
120459db4265SNate Lawson     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
120559db4265SNate Lawson 
120659db4265SNate Lawson     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
120759db4265SNate Lawson     AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
120859db4265SNate Lawson 
120959db4265SNate Lawson     /* Create the root object */
121059db4265SNate Lawson 
12111a39cfb0SJung-uk Kim     AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
12121a39cfb0SJung-uk Kim     if (!AcpiGbl_ParseOpRoot)
121359db4265SNate Lawson     {
121459db4265SNate Lawson         return AE_NO_MEMORY;
121559db4265SNate Lawson     }
121659db4265SNate Lawson 
121759db4265SNate Lawson     /* Create and initialize a new walk state */
121859db4265SNate Lawson 
121959db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0,
12201a39cfb0SJung-uk Kim                         AcpiGbl_ParseOpRoot, NULL, NULL);
122159db4265SNate Lawson     if (!WalkState)
122259db4265SNate Lawson     {
122359db4265SNate Lawson         return (AE_NO_MEMORY);
122459db4265SNate Lawson     }
122559db4265SNate Lawson 
12261a39cfb0SJung-uk Kim     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
12271a39cfb0SJung-uk Kim                 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
122859db4265SNate Lawson     if (ACPI_FAILURE (Status))
122959db4265SNate Lawson     {
123059db4265SNate Lawson         return (Status);
123159db4265SNate Lawson     }
123259db4265SNate Lawson 
123359db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1234fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
123559db4265SNate Lawson 
123659db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
123759db4265SNate Lawson     if (ACPI_FAILURE (Status))
123859db4265SNate Lawson     {
123959db4265SNate Lawson         return Status;
124059db4265SNate Lawson     }
124159db4265SNate Lawson 
1242a9f12690SJung-uk Kim     /* If LoadTable is FALSE, we are parsing the last loaded table */
1243a9f12690SJung-uk Kim 
1244a9f12690SJung-uk Kim     TableIndex = AcpiGbl_RootTableList.Count - 1;
1245a9f12690SJung-uk Kim 
124659db4265SNate Lawson     /* Pass 2 */
124759db4265SNate Lawson 
1248a9f12690SJung-uk Kim     if (LoadTable)
1249a9f12690SJung-uk Kim     {
1250a9f12690SJung-uk Kim         Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
12511a39cfb0SJung-uk Kim                     Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
12521a39cfb0SJung-uk Kim         if (ACPI_FAILURE (Status))
12531a39cfb0SJung-uk Kim         {
12541a39cfb0SJung-uk Kim             return Status;
12551a39cfb0SJung-uk Kim         }
1256a9f12690SJung-uk Kim         Status = AcpiTbAllocateOwnerId (TableIndex);
1257a9f12690SJung-uk Kim         if (ACPI_FAILURE (Status))
1258a9f12690SJung-uk Kim         {
1259a9f12690SJung-uk Kim             return Status;
1260a9f12690SJung-uk Kim         }
1261a9f12690SJung-uk Kim         if (OwnerId)
1262a9f12690SJung-uk Kim         {
1263a9f12690SJung-uk Kim             Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
1264a9f12690SJung-uk Kim             if (ACPI_FAILURE (Status))
1265a9f12690SJung-uk Kim             {
1266a9f12690SJung-uk Kim                 return Status;
1267a9f12690SJung-uk Kim             }
1268a9f12690SJung-uk Kim         }
1269a9f12690SJung-uk Kim     }
127059db4265SNate Lawson 
12711a39cfb0SJung-uk Kim     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
12721a39cfb0SJung-uk Kim 
1273a9f12690SJung-uk Kim     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
127459db4265SNate Lawson     if (ACPI_FAILURE (Status))
127559db4265SNate Lawson     {
127659db4265SNate Lawson         return (Status);
127759db4265SNate Lawson     }
127859db4265SNate Lawson 
1279a9f12690SJung-uk Kim     /* No need to parse control methods of external table */
1280a9f12690SJung-uk Kim 
1281a9f12690SJung-uk Kim     if (External)
1282a9f12690SJung-uk Kim     {
1283a9f12690SJung-uk Kim         return AE_OK;
1284a9f12690SJung-uk Kim     }
1285a9f12690SJung-uk Kim 
128659db4265SNate Lawson     /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
128759db4265SNate Lawson 
12881a39cfb0SJung-uk Kim     Status = AdParseDeferredOps (AcpiGbl_ParseOpRoot);
12891a39cfb0SJung-uk Kim 
12901a39cfb0SJung-uk Kim     /* Process Resource Templates */
12911a39cfb0SJung-uk Kim 
12921a39cfb0SJung-uk Kim     AcpiDmFindResources (AcpiGbl_ParseOpRoot);
129359db4265SNate Lawson 
129459db4265SNate Lawson     fprintf (stderr, "Parsing completed\n");
129559db4265SNate Lawson     return AE_OK;
129659db4265SNate Lawson }
129759db4265SNate Lawson 
129859db4265SNate Lawson 
1299