xref: /freebsd/sys/contrib/dev/acpica/common/adisasm.c (revision fba7fc7e34e95963b681b882698b951b35d1ba48)
159db4265SNate Lawson /******************************************************************************
259db4265SNate Lawson  *
359db4265SNate Lawson  * Module Name: adisasm - Application-level disassembler routines
4fba7fc7eSJung-uk Kim  *              $Revision: 1.77 $
559db4265SNate Lawson  *
659db4265SNate Lawson  *****************************************************************************/
759db4265SNate Lawson 
859db4265SNate Lawson /******************************************************************************
959db4265SNate Lawson  *
1059db4265SNate Lawson  * 1. Copyright Notice
1159db4265SNate Lawson  *
12fba7fc7eSJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
1359db4265SNate Lawson  * All rights reserved.
1459db4265SNate Lawson  *
1559db4265SNate Lawson  * 2. License
1659db4265SNate Lawson  *
1759db4265SNate Lawson  * 2.1. This is your license from Intel Corp. under its intellectual property
1859db4265SNate Lawson  * rights.  You may have additional license terms from the party that provided
1959db4265SNate Lawson  * you this software, covering your right to use that party's intellectual
2059db4265SNate Lawson  * property rights.
2159db4265SNate Lawson  *
2259db4265SNate Lawson  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2359db4265SNate Lawson  * copy of the source code appearing in this file ("Covered Code") an
2459db4265SNate Lawson  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2559db4265SNate Lawson  * base code distributed originally by Intel ("Original Intel Code") to copy,
2659db4265SNate Lawson  * make derivatives, distribute, use and display any portion of the Covered
2759db4265SNate Lawson  * Code in any form, with the right to sublicense such rights; and
2859db4265SNate Lawson  *
2959db4265SNate Lawson  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3059db4265SNate Lawson  * license (with the right to sublicense), under only those claims of Intel
3159db4265SNate Lawson  * patents that are infringed by the Original Intel Code, to make, use, sell,
3259db4265SNate Lawson  * offer to sell, and import the Covered Code and derivative works thereof
3359db4265SNate Lawson  * solely to the minimum extent necessary to exercise the above copyright
3459db4265SNate Lawson  * license, and in no event shall the patent license extend to any additions
3559db4265SNate Lawson  * to or modifications of the Original Intel Code.  No other license or right
3659db4265SNate Lawson  * is granted directly or by implication, estoppel or otherwise;
3759db4265SNate Lawson  *
3859db4265SNate Lawson  * The above copyright and patent license is granted only if the following
3959db4265SNate Lawson  * conditions are met:
4059db4265SNate Lawson  *
4159db4265SNate Lawson  * 3. Conditions
4259db4265SNate Lawson  *
4359db4265SNate Lawson  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4459db4265SNate Lawson  * Redistribution of source code of any substantial portion of the Covered
4559db4265SNate Lawson  * Code or modification with rights to further distribute source must include
4659db4265SNate Lawson  * the above Copyright Notice, the above License, this list of Conditions,
4759db4265SNate Lawson  * and the following Disclaimer and Export Compliance provision.  In addition,
4859db4265SNate Lawson  * Licensee must cause all Covered Code to which Licensee contributes to
4959db4265SNate Lawson  * contain a file documenting the changes Licensee made to create that Covered
5059db4265SNate Lawson  * Code and the date of any change.  Licensee must include in that file the
5159db4265SNate Lawson  * documentation of any changes made by any predecessor Licensee.  Licensee
5259db4265SNate Lawson  * must include a prominent statement that the modification is derived,
5359db4265SNate Lawson  * directly or indirectly, from Original Intel Code.
5459db4265SNate Lawson  *
5559db4265SNate Lawson  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5659db4265SNate Lawson  * Redistribution of source code of any substantial portion of the Covered
5759db4265SNate Lawson  * Code or modification without rights to further distribute source must
5859db4265SNate Lawson  * include the following Disclaimer and Export Compliance provision in the
5959db4265SNate Lawson  * documentation and/or other materials provided with distribution.  In
6059db4265SNate Lawson  * addition, Licensee may not authorize further sublicense of source of any
6159db4265SNate Lawson  * portion of the Covered Code, and must include terms to the effect that the
6259db4265SNate Lawson  * license from Licensee to its licensee is limited to the intellectual
6359db4265SNate Lawson  * property embodied in the software Licensee provides to its licensee, and
6459db4265SNate Lawson  * not to intellectual property embodied in modifications its licensee may
6559db4265SNate Lawson  * make.
6659db4265SNate Lawson  *
6759db4265SNate Lawson  * 3.3. Redistribution of Executable. Redistribution in executable form of any
6859db4265SNate Lawson  * substantial portion of the Covered Code or modification must reproduce the
6959db4265SNate Lawson  * above Copyright Notice, and the following Disclaimer and Export Compliance
7059db4265SNate Lawson  * provision in the documentation and/or other materials provided with the
7159db4265SNate Lawson  * distribution.
7259db4265SNate Lawson  *
7359db4265SNate Lawson  * 3.4. Intel retains all right, title, and interest in and to the Original
7459db4265SNate Lawson  * Intel Code.
7559db4265SNate Lawson  *
7659db4265SNate Lawson  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7759db4265SNate Lawson  * Intel shall be used in advertising or otherwise to promote the sale, use or
7859db4265SNate Lawson  * other dealings in products derived from or relating to the Covered Code
7959db4265SNate Lawson  * without prior written authorization from Intel.
8059db4265SNate Lawson  *
8159db4265SNate Lawson  * 4. Disclaimer and Export Compliance
8259db4265SNate Lawson  *
8359db4265SNate Lawson  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8459db4265SNate Lawson  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8559db4265SNate Lawson  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8659db4265SNate Lawson  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8759db4265SNate Lawson  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8859db4265SNate Lawson  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
8959db4265SNate Lawson  * PARTICULAR PURPOSE.
9059db4265SNate Lawson  *
9159db4265SNate Lawson  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9259db4265SNate Lawson  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9359db4265SNate Lawson  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9459db4265SNate Lawson  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9559db4265SNate Lawson  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9659db4265SNate Lawson  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9759db4265SNate Lawson  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9859db4265SNate Lawson  * LIMITED REMEDY.
9959db4265SNate Lawson  *
10059db4265SNate Lawson  * 4.3. Licensee shall not export, either directly or indirectly, any of this
10159db4265SNate Lawson  * software or system incorporating such software without first obtaining any
10259db4265SNate Lawson  * required license or other approval from the U. S. Department of Commerce or
10359db4265SNate Lawson  * any other agency or department of the United States Government.  In the
10459db4265SNate Lawson  * event Licensee exports any such software from the United States or
10559db4265SNate Lawson  * re-exports any such software from a foreign destination, Licensee shall
10659db4265SNate Lawson  * ensure that the distribution and export/re-export of the software is in
10759db4265SNate Lawson  * compliance with all laws, regulations, orders, or other restrictions of the
10859db4265SNate Lawson  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
10959db4265SNate Lawson  * any of its subsidiaries will export/re-export any technical data, process,
11059db4265SNate Lawson  * software, or service, directly or indirectly, to any country for which the
11159db4265SNate Lawson  * United States government or any agency thereof requires an export license,
11259db4265SNate Lawson  * other governmental approval, or letter of assurance, without first obtaining
11359db4265SNate Lawson  * such license, approval or letter.
11459db4265SNate Lawson  *
11559db4265SNate Lawson  *****************************************************************************/
11659db4265SNate Lawson 
11759db4265SNate Lawson 
118fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/acpi.h>
119fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/acparser.h>
120fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/amlcode.h>
121fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/acdebug.h>
122fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/acdisasm.h>
123fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/acdispat.h>
124fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/acnamesp.h>
125fba7fc7eSJung-uk Kim #include <contrib/dev/acpica/acapps.h>
12659db4265SNate Lawson 
12759db4265SNate Lawson #include <stdio.h>
12859db4265SNate Lawson #include <string.h>
12959db4265SNate Lawson #include <time.h>
13059db4265SNate Lawson 
13159db4265SNate Lawson 
13259db4265SNate Lawson #define _COMPONENT          ACPI_TOOLS
13359db4265SNate Lawson         ACPI_MODULE_NAME    ("adisasm")
13459db4265SNate Lawson 
13559db4265SNate Lawson 
13659db4265SNate Lawson ACPI_PARSE_OBJECT       *AcpiGbl_ParsedNamespaceRoot;
13759db4265SNate Lawson 
13859db4265SNate Lawson 
139fba7fc7eSJung-uk Kim #ifndef ACPI_ASL_COMPILER
14059db4265SNate Lawson BOOLEAN
14159db4265SNate Lawson AcpiDsIsResultUsed (
14259db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
14359db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
14459db4265SNate Lawson {
14559db4265SNate Lawson     return TRUE;
14659db4265SNate Lawson }
14759db4265SNate Lawson #endif
14859db4265SNate Lawson 
14959db4265SNate Lawson ACPI_STATUS
15059db4265SNate Lawson AcpiDsRestartControlMethod (
15159db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
15259db4265SNate Lawson     ACPI_OPERAND_OBJECT     *ReturnDesc)
15359db4265SNate Lawson {
15459db4265SNate Lawson     return (AE_OK);
15559db4265SNate Lawson }
15659db4265SNate Lawson 
157fba7fc7eSJung-uk Kim void
15859db4265SNate Lawson AcpiDsTerminateControlMethod (
15959db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
16059db4265SNate Lawson {
161fba7fc7eSJung-uk Kim     return;
16259db4265SNate Lawson }
16359db4265SNate Lawson 
16459db4265SNate Lawson ACPI_STATUS
16559db4265SNate Lawson AcpiDsCallControlMethod (
16659db4265SNate Lawson     ACPI_THREAD_STATE       *Thread,
16759db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
16859db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op)
16959db4265SNate Lawson {
17059db4265SNate Lawson     return (AE_OK);
17159db4265SNate Lawson }
17259db4265SNate Lawson 
17359db4265SNate Lawson ACPI_STATUS
17459db4265SNate Lawson AcpiDsMethodDataInitArgs (
17559db4265SNate Lawson     ACPI_OPERAND_OBJECT     **Params,
17659db4265SNate Lawson     UINT32                  MaxParamCount,
17759db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
17859db4265SNate Lawson {
17959db4265SNate Lawson     return (AE_OK);
18059db4265SNate Lawson }
18159db4265SNate Lawson 
18259db4265SNate Lawson 
18359db4265SNate Lawson #define FILE_SUFFIX_DISASSEMBLY     "dsl"
18459db4265SNate Lawson #define ACPI_TABLE_FILE_SUFFIX      ".dat"
18559db4265SNate Lawson char                        FilenameBuf[20];
18659db4265SNate Lawson 
18759db4265SNate Lawson /******************************************************************************
18859db4265SNate Lawson  *
18959db4265SNate Lawson  * FUNCTION:    AfGenerateFilename
19059db4265SNate Lawson  *
191fba7fc7eSJung-uk Kim  * PARAMETERS:  Prefix      - prefix string
192fba7fc7eSJung-uk Kim  *              TableId     - The table ID
19359db4265SNate Lawson  *
194fba7fc7eSJung-uk Kim  * RETURN:      Pointer to the completed string
19559db4265SNate Lawson  *
19659db4265SNate Lawson  * DESCRIPTION: Build an output filename from an ACPI table ID string
19759db4265SNate Lawson  *
19859db4265SNate Lawson  ******************************************************************************/
19959db4265SNate Lawson 
20059db4265SNate Lawson char *
20159db4265SNate Lawson AdGenerateFilename (
20259db4265SNate Lawson     char                    *Prefix,
20359db4265SNate Lawson     char                    *TableId)
20459db4265SNate Lawson {
20559db4265SNate Lawson     ACPI_NATIVE_UINT         i;
20659db4265SNate Lawson     ACPI_NATIVE_UINT         j;
20759db4265SNate Lawson 
20859db4265SNate Lawson 
20959db4265SNate Lawson     for (i = 0; Prefix[i]; i++)
21059db4265SNate Lawson     {
21159db4265SNate Lawson         FilenameBuf[i] = Prefix[i];
21259db4265SNate Lawson     }
21359db4265SNate Lawson 
21459db4265SNate Lawson     FilenameBuf[i] = '_';
21559db4265SNate Lawson     i++;
21659db4265SNate Lawson 
21759db4265SNate Lawson     for (j = 0; j < 8 && (TableId[j] != ' ') && (TableId[j] != 0); i++, j++)
21859db4265SNate Lawson     {
21959db4265SNate Lawson         FilenameBuf[i] = TableId[j];
22059db4265SNate Lawson     }
22159db4265SNate Lawson 
22259db4265SNate Lawson     FilenameBuf[i] = 0;
22359db4265SNate Lawson     strcat (FilenameBuf, ACPI_TABLE_FILE_SUFFIX);
22459db4265SNate Lawson     return FilenameBuf;
22559db4265SNate Lawson }
22659db4265SNate Lawson 
22759db4265SNate Lawson 
22859db4265SNate Lawson /******************************************************************************
22959db4265SNate Lawson  *
23059db4265SNate Lawson  * FUNCTION:    AfWriteBuffer
23159db4265SNate Lawson  *
232fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename        - name of file
233fba7fc7eSJung-uk Kim  *              Buffer          - data to write
234fba7fc7eSJung-uk Kim  *              Length          - length of data
23559db4265SNate Lawson  *
236fba7fc7eSJung-uk Kim  * RETURN:      Actual number of bytes written
23759db4265SNate Lawson  *
23859db4265SNate Lawson  * DESCRIPTION: Open a file and write out a single buffer
23959db4265SNate Lawson  *
24059db4265SNate Lawson  ******************************************************************************/
24159db4265SNate Lawson 
24259db4265SNate Lawson ACPI_NATIVE_INT
24359db4265SNate Lawson AdWriteBuffer (
24459db4265SNate Lawson     char                *Filename,
24559db4265SNate Lawson     char                *Buffer,
24659db4265SNate Lawson     UINT32              Length)
24759db4265SNate Lawson {
24859db4265SNate Lawson     FILE                *fp;
24959db4265SNate Lawson     ACPI_NATIVE_INT     Actual;
25059db4265SNate Lawson 
25159db4265SNate Lawson 
25259db4265SNate Lawson     fp = fopen (Filename, "wb");
25359db4265SNate Lawson     if (!fp)
25459db4265SNate Lawson     {
25559db4265SNate Lawson         printf ("Couldn't open %s\n", Filename);
25659db4265SNate Lawson         return -1;
25759db4265SNate Lawson     }
25859db4265SNate Lawson 
25959db4265SNate Lawson     Actual = fwrite (Buffer, (size_t) Length, 1, fp);
26059db4265SNate Lawson     fclose (fp);
26159db4265SNate Lawson     return Actual;
26259db4265SNate Lawson }
26359db4265SNate Lawson 
26459db4265SNate Lawson 
26559db4265SNate Lawson /******************************************************************************
26659db4265SNate Lawson  *
26759db4265SNate Lawson  * FUNCTION:    AfWriteTable
26859db4265SNate Lawson  *
269fba7fc7eSJung-uk Kim  * PARAMETERS:  Table       - pointer to the ACPI table
270fba7fc7eSJung-uk Kim  *              Length      - length of the table
271fba7fc7eSJung-uk Kim  *              TableName   - the table signature
272fba7fc7eSJung-uk Kim  *              OemTableID  - from the table header
27359db4265SNate Lawson  *
274fba7fc7eSJung-uk Kim  * RETURN:      None
27559db4265SNate Lawson  *
27659db4265SNate Lawson  * DESCRIPTION: Dump the loaded tables to a file (or files)
27759db4265SNate Lawson  *
27859db4265SNate Lawson  ******************************************************************************/
27959db4265SNate Lawson 
28059db4265SNate Lawson void
28159db4265SNate Lawson AdWriteTable (
28259db4265SNate Lawson     ACPI_TABLE_HEADER       *Table,
28359db4265SNate Lawson     UINT32                  Length,
28459db4265SNate Lawson     char                    *TableName,
28559db4265SNate Lawson     char                    *OemTableId)
28659db4265SNate Lawson {
28759db4265SNate Lawson     char                    *Filename;
28859db4265SNate Lawson 
28959db4265SNate Lawson 
29059db4265SNate Lawson     Filename = AdGenerateFilename (TableName, OemTableId);
29159db4265SNate Lawson     AdWriteBuffer (Filename, (char *) Table, Length);
29259db4265SNate Lawson 
29359db4265SNate Lawson     AcpiOsPrintf ("Table [%s] written to \"%s\"\n", TableName, Filename);
29459db4265SNate Lawson }
29559db4265SNate Lawson 
29659db4265SNate Lawson 
29759db4265SNate Lawson /*******************************************************************************
29859db4265SNate Lawson  *
29959db4265SNate Lawson  * FUNCTION:    AdInitialize
30059db4265SNate Lawson  *
30159db4265SNate Lawson  * PARAMETERS:  None.
30259db4265SNate Lawson  *
30359db4265SNate Lawson  * RETURN:      Status
30459db4265SNate Lawson  *
30559db4265SNate Lawson  * DESCRIPTION: CA initialization
30659db4265SNate Lawson  *
30759db4265SNate Lawson  ******************************************************************************/
30859db4265SNate Lawson 
30959db4265SNate Lawson ACPI_STATUS
31059db4265SNate Lawson AdInitialize (
31159db4265SNate Lawson     void)
31259db4265SNate Lawson {
31359db4265SNate Lawson     ACPI_STATUS             Status;
31459db4265SNate Lawson 
31559db4265SNate Lawson 
31659db4265SNate Lawson     /* ACPI CA subsystem initialization */
31759db4265SNate Lawson 
31859db4265SNate Lawson     AcpiUtInitGlobals ();
31959db4265SNate Lawson     Status = AcpiUtMutexInitialize ();
32059db4265SNate Lawson     if (ACPI_FAILURE (Status))
32159db4265SNate Lawson     {
32259db4265SNate Lawson         return Status;
32359db4265SNate Lawson     }
32459db4265SNate Lawson 
32559db4265SNate Lawson     Status = AcpiNsRootInitialize ();
32659db4265SNate Lawson     return Status;
32759db4265SNate Lawson }
32859db4265SNate Lawson 
32959db4265SNate Lawson 
33059db4265SNate Lawson /*******************************************************************************
33159db4265SNate Lawson  *
33259db4265SNate Lawson  * FUNCTION:    FlGenerateFilename
33359db4265SNate Lawson  *
33459db4265SNate Lawson  * PARAMETERS:  InputFilename       - Original ASL source filename
33559db4265SNate Lawson  *              Suffix              - New extension.
33659db4265SNate Lawson  *
33759db4265SNate Lawson  * RETURN:      New filename containing the original base + the new suffix
33859db4265SNate Lawson  *
33959db4265SNate Lawson  * DESCRIPTION: Generate a new filename from the ASL source filename and a new
34059db4265SNate Lawson  *              extension.  Used to create the *.LST, *.TXT, etc. files.
34159db4265SNate Lawson  *
34259db4265SNate Lawson  ******************************************************************************/
34359db4265SNate Lawson 
34459db4265SNate Lawson char *
34559db4265SNate Lawson FlGenerateFilename (
34659db4265SNate Lawson     char                    *InputFilename,
34759db4265SNate Lawson     char                    *Suffix)
34859db4265SNate Lawson {
34959db4265SNate Lawson     char                    *Position;
35059db4265SNate Lawson     char                    *NewFilename;
35159db4265SNate Lawson 
35259db4265SNate Lawson 
35359db4265SNate Lawson     /* Copy the original filename to a new buffer */
35459db4265SNate Lawson 
35559db4265SNate Lawson     NewFilename = ACPI_MEM_CALLOCATE (strlen (InputFilename) + strlen (Suffix));
35659db4265SNate Lawson     strcpy (NewFilename, InputFilename);
35759db4265SNate Lawson 
35859db4265SNate Lawson     /* Try to find the last dot in the filename */
35959db4265SNate Lawson 
36059db4265SNate Lawson     Position = strrchr (NewFilename, '.');
36159db4265SNate Lawson     if (Position)
36259db4265SNate Lawson     {
36359db4265SNate Lawson         /* Tack on the new suffix */
36459db4265SNate Lawson 
36559db4265SNate Lawson         Position++;
36659db4265SNate Lawson         *Position = 0;
36759db4265SNate Lawson         strcat (Position, Suffix);
36859db4265SNate Lawson     }
36959db4265SNate Lawson     else
37059db4265SNate Lawson     {
37159db4265SNate Lawson         /* No dot, add one and then the suffix */
37259db4265SNate Lawson 
37359db4265SNate Lawson         strcat (NewFilename, ".");
37459db4265SNate Lawson         strcat (NewFilename, Suffix);
37559db4265SNate Lawson     }
37659db4265SNate Lawson 
37759db4265SNate Lawson     return NewFilename;
37859db4265SNate Lawson }
37959db4265SNate Lawson 
38059db4265SNate Lawson 
38159db4265SNate Lawson /*******************************************************************************
38259db4265SNate Lawson  *
38359db4265SNate Lawson  * FUNCTION:    FlSplitInputPathname
38459db4265SNate Lawson  *
38559db4265SNate Lawson  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
38659db4265SNate Lawson  *                                    compiled
387fba7fc7eSJung-uk Kim  *              OutDirectoryPath    - Where the directory path prefix is
388fba7fc7eSJung-uk Kim  *                                    returned
389fba7fc7eSJung-uk Kim  *              OutFilename         - Where the filename part is returned
39059db4265SNate Lawson  *
39159db4265SNate Lawson  * RETURN:      Status
39259db4265SNate Lawson  *
39359db4265SNate Lawson  * DESCRIPTION: Split the input path into a directory and filename part
39459db4265SNate Lawson  *              1) Directory part used to open include files
39559db4265SNate Lawson  *              2) Filename part used to generate output filenames
39659db4265SNate Lawson  *
39759db4265SNate Lawson  ******************************************************************************/
39859db4265SNate Lawson 
39959db4265SNate Lawson ACPI_STATUS
40059db4265SNate Lawson FlSplitInputPathname (
40159db4265SNate Lawson     char                    *InputPath,
40259db4265SNate Lawson     char                    **OutDirectoryPath,
40359db4265SNate Lawson     char                    **OutFilename)
40459db4265SNate Lawson {
40559db4265SNate Lawson     char                    *Substring;
40659db4265SNate Lawson     char                    *DirectoryPath;
40759db4265SNate Lawson     char                    *Filename;
40859db4265SNate Lawson 
40959db4265SNate Lawson 
41059db4265SNate Lawson     *OutDirectoryPath = NULL;
41159db4265SNate Lawson     *OutFilename = NULL;
41259db4265SNate Lawson 
41359db4265SNate Lawson     if (!InputPath)
41459db4265SNate Lawson     {
41559db4265SNate Lawson         return (AE_OK);
41659db4265SNate Lawson     }
41759db4265SNate Lawson 
41859db4265SNate Lawson     /* Get the path to the input filename's directory */
41959db4265SNate Lawson 
42059db4265SNate Lawson     DirectoryPath = strdup (InputPath);
42159db4265SNate Lawson     if (!DirectoryPath)
42259db4265SNate Lawson     {
42359db4265SNate Lawson         return (AE_NO_MEMORY);
42459db4265SNate Lawson     }
42559db4265SNate Lawson 
42659db4265SNate Lawson     Substring = strrchr (DirectoryPath, '\\');
42759db4265SNate Lawson     if (!Substring)
42859db4265SNate Lawson     {
42959db4265SNate Lawson         Substring = strrchr (DirectoryPath, '/');
43059db4265SNate Lawson         if (!Substring)
43159db4265SNate Lawson         {
43259db4265SNate Lawson             Substring = strrchr (DirectoryPath, ':');
43359db4265SNate Lawson         }
43459db4265SNate Lawson     }
43559db4265SNate Lawson 
43659db4265SNate Lawson     if (!Substring)
43759db4265SNate Lawson     {
43859db4265SNate Lawson         DirectoryPath[0] = 0;
43959db4265SNate Lawson         Filename = strdup (InputPath);
44059db4265SNate Lawson     }
44159db4265SNate Lawson     else
44259db4265SNate Lawson     {
44359db4265SNate Lawson         Filename = strdup (Substring + 1);
44459db4265SNate Lawson         *(Substring+1) = 0;
44559db4265SNate Lawson     }
44659db4265SNate Lawson 
44759db4265SNate Lawson     if (!Filename)
44859db4265SNate Lawson     {
44959db4265SNate Lawson         return (AE_NO_MEMORY);
45059db4265SNate Lawson     }
45159db4265SNate Lawson 
45259db4265SNate Lawson     *OutDirectoryPath = DirectoryPath;
45359db4265SNate Lawson     *OutFilename = Filename;
45459db4265SNate Lawson 
45559db4265SNate Lawson     return (AE_OK);
45659db4265SNate Lawson }
45759db4265SNate Lawson 
45859db4265SNate Lawson 
45959db4265SNate Lawson /******************************************************************************
46059db4265SNate Lawson  *
46159db4265SNate Lawson  * FUNCTION:    AdAmlDisassemble
46259db4265SNate Lawson  *
463fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename        - AML input filename
464fba7fc7eSJung-uk Kim  *              OutToFile       - TRUE if output should go to a file
465fba7fc7eSJung-uk Kim  *              Prefix          - Path prefix for output
466fba7fc7eSJung-uk Kim  *              OutFilename     - where the filename is returned
467fba7fc7eSJung-uk Kim  *              GetAllTables    - TRUE if all tables are desired
46859db4265SNate Lawson  *
46959db4265SNate Lawson  * RETURN:      Status
47059db4265SNate Lawson  *
47159db4265SNate Lawson  * DESCRIPTION: Disassemble an entire ACPI table
47259db4265SNate Lawson  *
47359db4265SNate Lawson  *****************************************************************************/
47459db4265SNate Lawson 
47559db4265SNate Lawson ACPI_STATUS
47659db4265SNate Lawson AdAmlDisassemble (
47759db4265SNate Lawson     BOOLEAN                 OutToFile,
47859db4265SNate Lawson     char                    *Filename,
47959db4265SNate Lawson     char                    *Prefix,
48059db4265SNate Lawson     char                    **OutFilename,
48159db4265SNate Lawson     BOOLEAN                 GetAllTables)
48259db4265SNate Lawson {
48359db4265SNate Lawson     ACPI_STATUS             Status;
48459db4265SNate Lawson     char                    *DisasmFilename = NULL;
48559db4265SNate Lawson     FILE                    *File = NULL;
48659db4265SNate Lawson     ACPI_TABLE_HEADER       *Table;
48759db4265SNate Lawson 
48859db4265SNate Lawson 
48959db4265SNate Lawson     /*
49059db4265SNate Lawson      * Input:  AML Code from either a file,
49159db4265SNate Lawson      *         or via GetTables (memory or registry)
49259db4265SNate Lawson      */
49359db4265SNate Lawson     if (Filename)
49459db4265SNate Lawson     {
49559db4265SNate Lawson         Status = AcpiDbGetTableFromFile (Filename, &Table);
49659db4265SNate Lawson         if (ACPI_FAILURE (Status))
49759db4265SNate Lawson         {
49859db4265SNate Lawson             return Status;
49959db4265SNate Lawson         }
50059db4265SNate Lawson     }
50159db4265SNate Lawson     else
50259db4265SNate Lawson     {
50359db4265SNate Lawson         Status = AdGetLocalTables (Filename, GetAllTables);
50459db4265SNate Lawson         if (ACPI_FAILURE (Status))
50559db4265SNate Lawson         {
50659db4265SNate Lawson             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
50759db4265SNate Lawson                 AcpiFormatException (Status));
50859db4265SNate Lawson             return Status;
50959db4265SNate Lawson         }
51059db4265SNate Lawson 
51159db4265SNate Lawson         if (!AcpiGbl_DbOpt_disasm)
51259db4265SNate Lawson         {
51359db4265SNate Lawson             return AE_OK;
51459db4265SNate Lawson         }
51559db4265SNate Lawson 
51659db4265SNate Lawson         /* Obtained the local tables, just disassmeble the DSDT */
51759db4265SNate Lawson 
51859db4265SNate Lawson         Table = AcpiGbl_DSDT;
51959db4265SNate Lawson         AcpiOsPrintf ("\nDisassembly of DSDT\n");
52059db4265SNate Lawson         Prefix = AdGenerateFilename ("dsdt", AcpiGbl_DSDT->OemTableId);
52159db4265SNate Lawson     }
52259db4265SNate Lawson 
52359db4265SNate Lawson     /*
52459db4265SNate Lawson      * Output:  ASL code.
52559db4265SNate Lawson      *          Redirect to a file if requested
52659db4265SNate Lawson      */
52759db4265SNate Lawson     if (OutToFile)
52859db4265SNate Lawson     {
52959db4265SNate Lawson         /* Create/Open a disassembly output file */
53059db4265SNate Lawson 
53159db4265SNate Lawson         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
53259db4265SNate Lawson         if (!OutFilename)
53359db4265SNate Lawson         {
53459db4265SNate Lawson             fprintf (stderr, "Could not generate output filename\n");
535e50beb51SNate Lawson             Status = AE_ERROR;
536e50beb51SNate Lawson             goto Cleanup;
53759db4265SNate Lawson         }
53859db4265SNate Lawson 
53959db4265SNate Lawson         File = fopen (DisasmFilename, "w+");
54059db4265SNate Lawson         if (!File)
54159db4265SNate Lawson         {
54259db4265SNate Lawson             fprintf (stderr, "Could not open output file\n");
543e50beb51SNate Lawson             Status = AE_ERROR;
544e50beb51SNate Lawson             goto Cleanup;
54559db4265SNate Lawson         }
54659db4265SNate Lawson 
54759db4265SNate Lawson         AcpiOsRedirectOutput (File);
54859db4265SNate Lawson     }
54959db4265SNate Lawson 
55059db4265SNate Lawson     *OutFilename = DisasmFilename;
55159db4265SNate Lawson 
55259db4265SNate Lawson     /* Always parse the tables, only option is what to display */
55359db4265SNate Lawson 
55459db4265SNate Lawson     Status = AdParseTable (Table);
55559db4265SNate Lawson     if (ACPI_FAILURE (Status))
55659db4265SNate Lawson     {
55759db4265SNate Lawson         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
55859db4265SNate Lawson             AcpiFormatException (Status));
55959db4265SNate Lawson         goto Cleanup;
56059db4265SNate Lawson     }
56159db4265SNate Lawson 
562e0ef747bSNate Lawson     /*
563e0ef747bSNate Lawson      * TBD: We want to cross reference the namespace here, in order to
564e0ef747bSNate Lawson      * generate External() statements.  The problem is that the parse
565e0ef747bSNate Lawson      * tree is in run-time (interpreter) format, not compiler format,
566e0ef747bSNate Lawson      * so we cannot directly use the function below:
567e0ef747bSNate Lawson      *
568e0ef747bSNate Lawson      *    Status = LkCrossReferenceNamespace ();
569e0ef747bSNate Lawson      *
570e0ef747bSNate Lawson      * We need to either convert the parse tree or create a new
571e0ef747bSNate Lawson      * cross ref function that can handle interpreter parse trees
572e0ef747bSNate Lawson      */
573e0ef747bSNate Lawson 
57459db4265SNate Lawson     /* Optional displays */
57559db4265SNate Lawson 
57659db4265SNate Lawson     if (AcpiGbl_DbOpt_disasm)
57759db4265SNate Lawson     {
57859db4265SNate Lawson         AdDisplayTables (Filename, Table);
57959db4265SNate Lawson         fprintf (stderr, "Disassembly completed, written to \"%s\"\n", DisasmFilename);
58059db4265SNate Lawson     }
58159db4265SNate Lawson 
58259db4265SNate Lawson Cleanup:
58359db4265SNate Lawson     if (OutToFile)
58459db4265SNate Lawson     {
58559db4265SNate Lawson         fclose (File);
58659db4265SNate Lawson         AcpiOsRedirectOutput (stdout);
58759db4265SNate Lawson     }
58859db4265SNate Lawson 
58959db4265SNate Lawson     AcpiPsDeleteParseTree (AcpiGbl_ParsedNamespaceRoot);
590e50beb51SNate Lawson     return Status;
59159db4265SNate Lawson }
59259db4265SNate Lawson 
59359db4265SNate Lawson 
59459db4265SNate Lawson /******************************************************************************
59559db4265SNate Lawson  *
59659db4265SNate Lawson  * FUNCTION:    AdCreateTableHeader
59759db4265SNate Lawson  *
59859db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
59959db4265SNate Lawson  *              Table               - Pointer to the raw table
60059db4265SNate Lawson  *
60159db4265SNate Lawson  * RETURN:      None
60259db4265SNate Lawson  *
60359db4265SNate Lawson  * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
60459db4265SNate Lawson  *              current time and date.
60559db4265SNate Lawson  *
60659db4265SNate Lawson  *****************************************************************************/
60759db4265SNate Lawson 
60859db4265SNate Lawson void
60959db4265SNate Lawson AdCreateTableHeader (
61059db4265SNate Lawson     char                    *Filename,
61159db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
61259db4265SNate Lawson {
61359db4265SNate Lawson     time_t                  Timer;
61459db4265SNate Lawson 
61559db4265SNate Lawson 
61659db4265SNate Lawson     time (&Timer);
61759db4265SNate Lawson 
61859db4265SNate Lawson     AcpiOsPrintf ("/*\n * Intel ACPI Component Architecture\n");
61959db4265SNate Lawson     AcpiOsPrintf (" * AML Disassembler version %8.8X\n", ACPI_CA_VERSION);
62059db4265SNate Lawson     AcpiOsPrintf (" *\n * Disassembly of %s, %s */\n", Filename, ctime (&Timer));
62159db4265SNate Lawson 
62259db4265SNate Lawson     AcpiOsPrintf (
623fba7fc7eSJung-uk Kim         "DefinitionBlock (\"%4.4s.aml\", \"%4.4s\", %hd, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
62459db4265SNate Lawson         Table->Signature, Table->Signature, Table->Revision,
62559db4265SNate Lawson         Table->OemId, Table->OemTableId, Table->OemRevision);
62659db4265SNate Lawson }
62759db4265SNate Lawson 
62859db4265SNate Lawson 
62959db4265SNate Lawson /******************************************************************************
63059db4265SNate Lawson  *
63159db4265SNate Lawson  * FUNCTION:    AdDisplayTables
63259db4265SNate Lawson  *
63359db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
634fba7fc7eSJung-uk Kim  *              Table               - Pointer to the raw table
63559db4265SNate Lawson  *
63659db4265SNate Lawson  * RETURN:      Status
63759db4265SNate Lawson  *
63859db4265SNate Lawson  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
63959db4265SNate Lawson  *
64059db4265SNate Lawson  *****************************************************************************/
64159db4265SNate Lawson 
64259db4265SNate Lawson ACPI_STATUS
64359db4265SNate Lawson AdDisplayTables (
64459db4265SNate Lawson     char                    *Filename,
64559db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
64659db4265SNate Lawson {
64759db4265SNate Lawson 
64859db4265SNate Lawson 
64959db4265SNate Lawson     if (!AcpiGbl_ParsedNamespaceRoot)
65059db4265SNate Lawson     {
65159db4265SNate Lawson         return AE_NOT_EXIST;
65259db4265SNate Lawson     }
65359db4265SNate Lawson 
65459db4265SNate Lawson     if (!AcpiGbl_DbOpt_verbose)
65559db4265SNate Lawson     {
65659db4265SNate Lawson         AdCreateTableHeader (Filename, Table);
65759db4265SNate Lawson     }
65859db4265SNate Lawson 
65959db4265SNate Lawson     AcpiDmDisassemble (NULL, AcpiGbl_ParsedNamespaceRoot, ACPI_UINT32_MAX);
66059db4265SNate Lawson 
66159db4265SNate Lawson     if (AcpiGbl_DbOpt_verbose)
66259db4265SNate Lawson     {
66359db4265SNate Lawson         AcpiOsPrintf ("\n\nTable Header:\n");
66459db4265SNate Lawson         AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
66559db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
66659db4265SNate Lawson 
66759db4265SNate Lawson         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
66859db4265SNate Lawson         AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
66959db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
67059db4265SNate Lawson     }
67159db4265SNate Lawson 
67259db4265SNate Lawson     return AE_OK;
67359db4265SNate Lawson }
67459db4265SNate Lawson 
67559db4265SNate Lawson 
67659db4265SNate Lawson /******************************************************************************
67759db4265SNate Lawson  *
67859db4265SNate Lawson  * FUNCTION:    AdDeferredParse
67959db4265SNate Lawson  *
68059db4265SNate Lawson  * PARAMETERS:  Op              - Root Op of the deferred opcode
68159db4265SNate Lawson  *              Aml             - Pointer to the raw AML
68259db4265SNate Lawson  *              AmlLength       - Length of the AML
68359db4265SNate Lawson  *
68459db4265SNate Lawson  * RETURN:      Status
68559db4265SNate Lawson  *
68659db4265SNate Lawson  * DESCRIPTION: Parse one deferred opcode
68759db4265SNate Lawson  *              (Methods, operation regions, etc.)
68859db4265SNate Lawson  *
68959db4265SNate Lawson  *****************************************************************************/
69059db4265SNate Lawson 
69159db4265SNate Lawson ACPI_STATUS
69259db4265SNate Lawson AdDeferredParse (
69359db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
69459db4265SNate Lawson     UINT8                   *Aml,
69559db4265SNate Lawson     UINT32                  AmlLength)
69659db4265SNate Lawson {
69759db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
69859db4265SNate Lawson     ACPI_STATUS             Status;
69959db4265SNate Lawson     ACPI_PARSE_OBJECT       *SearchOp;
70059db4265SNate Lawson     ACPI_PARSE_OBJECT       *StartOp;
70159db4265SNate Lawson     UINT32                  BaseAmlOffset;
70259db4265SNate Lawson     ACPI_PARSE_OBJECT       *ExtraOp;
70359db4265SNate Lawson 
70459db4265SNate Lawson 
70559db4265SNate Lawson     ACPI_FUNCTION_TRACE ("AdDeferredParse");
70659db4265SNate Lawson 
70759db4265SNate Lawson 
70859db4265SNate Lawson     fprintf (stderr, ".");
70959db4265SNate Lawson 
71059db4265SNate Lawson     if (!Aml || !AmlLength)
71159db4265SNate Lawson     {
71259db4265SNate Lawson         return_ACPI_STATUS (AE_OK);
71359db4265SNate Lawson     }
71459db4265SNate Lawson 
71559db4265SNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
71659db4265SNate Lawson         Op->Common.AmlOpName, (char *) &Op->Named.Name));
71759db4265SNate Lawson 
71859db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
71959db4265SNate Lawson     if (!WalkState)
72059db4265SNate Lawson     {
72159db4265SNate Lawson         return_ACPI_STATUS (AE_NO_MEMORY);
72259db4265SNate Lawson     }
72359db4265SNate Lawson 
72459db4265SNate Lawson     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
725a5a81f7cSNate Lawson                     AmlLength, NULL, 1);
72659db4265SNate Lawson     if (ACPI_FAILURE (Status))
72759db4265SNate Lawson     {
72859db4265SNate Lawson         return_ACPI_STATUS (Status);
72959db4265SNate Lawson     }
73059db4265SNate Lawson 
73159db4265SNate Lawson     /* Parse the method */
73259db4265SNate Lawson 
73359db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
734fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
73559db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
73659db4265SNate Lawson 
73759db4265SNate Lawson     /*
73859db4265SNate Lawson      * We need to update all of the Aml offsets, since the parser thought
73959db4265SNate Lawson      * that the method began at offset zero.  In reality, it began somewhere
74059db4265SNate Lawson      * within the ACPI table, at the BaseAmlOffset.  Walk the entire tree that
74159db4265SNate Lawson      * was just created and update the AmlOffset in each Op
74259db4265SNate Lawson      */
74359db4265SNate Lawson     BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
74459db4265SNate Lawson     StartOp = (Op->Common.Value.Arg)->Common.Next;
74559db4265SNate Lawson     SearchOp = StartOp;
74659db4265SNate Lawson 
74759db4265SNate Lawson     /* Walk the parse tree */
74859db4265SNate Lawson 
74959db4265SNate Lawson     while (SearchOp)
75059db4265SNate Lawson     {
75159db4265SNate Lawson         SearchOp->Common.AmlOffset += BaseAmlOffset;
75259db4265SNate Lawson         SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
75359db4265SNate Lawson     }
75459db4265SNate Lawson 
75559db4265SNate Lawson     /*
75659db4265SNate Lawson      * Link the newly parsed subtree into the main parse tree
75759db4265SNate Lawson      */
75859db4265SNate Lawson     switch (Op->Common.AmlOpcode)
75959db4265SNate Lawson     {
76059db4265SNate Lawson     case AML_BUFFER_OP:
76159db4265SNate Lawson     case AML_PACKAGE_OP:
76259db4265SNate Lawson     case AML_VAR_PACKAGE_OP:
76359db4265SNate Lawson 
76459db4265SNate Lawson         switch (Op->Common.AmlOpcode)
76559db4265SNate Lawson         {
76659db4265SNate Lawson         case AML_PACKAGE_OP:
76759db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
76859db4265SNate Lawson             ExtraOp = ExtraOp->Common.Next;
76959db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
77059db4265SNate Lawson             break;
77159db4265SNate Lawson 
772fba7fc7eSJung-uk Kim         case AML_VAR_PACKAGE_OP:
77359db4265SNate Lawson         case AML_BUFFER_OP:
77459db4265SNate Lawson         default:
77559db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
77659db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
77759db4265SNate Lawson             break;
77859db4265SNate Lawson         }
77959db4265SNate Lawson 
78059db4265SNate Lawson         /* Must point all parents to the main tree */
78159db4265SNate Lawson 
78259db4265SNate Lawson         StartOp = Op;
78359db4265SNate Lawson         SearchOp = StartOp;
78459db4265SNate Lawson         while (SearchOp)
78559db4265SNate Lawson         {
78659db4265SNate Lawson             if (SearchOp->Common.Parent == ExtraOp)
78759db4265SNate Lawson             {
78859db4265SNate Lawson                 SearchOp->Common.Parent = Op;
78959db4265SNate Lawson             }
79059db4265SNate Lawson             SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
79159db4265SNate Lawson         }
79259db4265SNate Lawson         break;
79359db4265SNate Lawson 
79459db4265SNate Lawson     default:
79559db4265SNate Lawson         break;
79659db4265SNate Lawson     }
79759db4265SNate Lawson 
79859db4265SNate Lawson     return_ACPI_STATUS (AE_OK);
79959db4265SNate Lawson }
80059db4265SNate Lawson 
80159db4265SNate Lawson 
80259db4265SNate Lawson /******************************************************************************
80359db4265SNate Lawson  *
80459db4265SNate Lawson  * FUNCTION:    AdParseDeferredOps
80559db4265SNate Lawson  *
80659db4265SNate Lawson  * PARAMETERS:  Root            - Root of the parse tree
80759db4265SNate Lawson  *
80859db4265SNate Lawson  * RETURN:      Status
80959db4265SNate Lawson  *
81059db4265SNate Lawson  * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
81159db4265SNate Lawson  *
81259db4265SNate Lawson  *****************************************************************************/
81359db4265SNate Lawson 
81459db4265SNate Lawson ACPI_STATUS
81559db4265SNate Lawson AdParseDeferredOps (
81659db4265SNate Lawson     ACPI_PARSE_OBJECT       *Root)
81759db4265SNate Lawson {
81859db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op = Root;
81959db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
82059db4265SNate Lawson     const ACPI_OPCODE_INFO  *OpInfo;
82159db4265SNate Lawson 
82259db4265SNate Lawson 
82359db4265SNate Lawson     ACPI_FUNCTION_NAME ("AdParseDeferredOps");
82459db4265SNate Lawson     fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
82559db4265SNate Lawson 
82659db4265SNate Lawson     while (Op)
82759db4265SNate Lawson     {
82859db4265SNate Lawson         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
82959db4265SNate Lawson         if (!(OpInfo->Flags & AML_DEFER))
83059db4265SNate Lawson         {
83159db4265SNate Lawson             Op = AcpiPsGetDepthNext (Root, Op);
83259db4265SNate Lawson             continue;
83359db4265SNate Lawson         }
83459db4265SNate Lawson 
83559db4265SNate Lawson         switch (Op->Common.AmlOpcode)
83659db4265SNate Lawson         {
83759db4265SNate Lawson         case AML_METHOD_OP:
83859db4265SNate Lawson         case AML_BUFFER_OP:
83959db4265SNate Lawson         case AML_PACKAGE_OP:
84059db4265SNate Lawson         case AML_VAR_PACKAGE_OP:
84159db4265SNate Lawson 
84259db4265SNate Lawson             Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
84359db4265SNate Lawson             if (ACPI_FAILURE (Status))
84459db4265SNate Lawson             {
84559db4265SNate Lawson                 return_ACPI_STATUS (Status);
84659db4265SNate Lawson             }
84759db4265SNate Lawson             break;
84859db4265SNate Lawson 
84959db4265SNate Lawson         case AML_REGION_OP:
85059db4265SNate Lawson         case AML_CREATE_QWORD_FIELD_OP:
85159db4265SNate Lawson         case AML_CREATE_DWORD_FIELD_OP:
85259db4265SNate Lawson         case AML_CREATE_WORD_FIELD_OP:
85359db4265SNate Lawson         case AML_CREATE_BYTE_FIELD_OP:
85459db4265SNate Lawson         case AML_CREATE_BIT_FIELD_OP:
85559db4265SNate Lawson         case AML_CREATE_FIELD_OP:
85659db4265SNate Lawson 
85759db4265SNate Lawson             /* Nothing to do in these cases */
85859db4265SNate Lawson 
85959db4265SNate Lawson             break;
86059db4265SNate Lawson 
86159db4265SNate Lawson         default:
86259db4265SNate Lawson             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unhandled deferred opcode [%s]\n",
86359db4265SNate Lawson                 Op->Common.AmlOpName));
86459db4265SNate Lawson             break;
86559db4265SNate Lawson         }
86659db4265SNate Lawson 
86759db4265SNate Lawson         Op = AcpiPsGetDepthNext (Root, Op);
86859db4265SNate Lawson     }
86959db4265SNate Lawson 
87059db4265SNate Lawson     fprintf (stderr, "\n");
87159db4265SNate Lawson     return Status;
87259db4265SNate Lawson }
87359db4265SNate Lawson 
87459db4265SNate Lawson 
87559db4265SNate Lawson /******************************************************************************
87659db4265SNate Lawson  *
87759db4265SNate Lawson  * FUNCTION:    AdGetLocalTables
87859db4265SNate Lawson  *
879fba7fc7eSJung-uk Kim  * PARAMETERS:  Filename        - Not used
880fba7fc7eSJung-uk Kim  *              GetAllTables    - TRUE if all tables are desired
88159db4265SNate Lawson  *
882fba7fc7eSJung-uk Kim  * RETURN:      Status
88359db4265SNate Lawson  *
88459db4265SNate Lawson  * DESCRIPTION: Get the ACPI tables from either memory or a file
88559db4265SNate Lawson  *
88659db4265SNate Lawson  *****************************************************************************/
88759db4265SNate Lawson 
88859db4265SNate Lawson ACPI_STATUS
88959db4265SNate Lawson AdGetLocalTables (
89059db4265SNate Lawson     char                    *Filename,
89159db4265SNate Lawson     BOOLEAN                 GetAllTables)
89259db4265SNate Lawson {
89359db4265SNate Lawson     ACPI_STATUS             Status;
89459db4265SNate Lawson     ACPI_TABLE_HEADER       TableHeader;
89559db4265SNate Lawson     ACPI_TABLE_HEADER       *NewTable;
89659db4265SNate Lawson     UINT32                  NumTables;
89759db4265SNate Lawson     UINT32                  PointerSize;
898c8466860SMark Santcroos     char                    *FacsSuffix = "";
89959db4265SNate Lawson 
90059db4265SNate Lawson 
90159db4265SNate Lawson     if (GetAllTables)
90259db4265SNate Lawson     {
903e50beb51SNate Lawson         ACPI_STRNCPY (TableHeader.Signature, RSDT_SIG, 4);
90459db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
905e50beb51SNate Lawson         if (!NewTable)
906e50beb51SNate Lawson         {
907e50beb51SNate Lawson             fprintf (stderr, "Could not obtain RSDT\n");
908e50beb51SNate Lawson             return AE_NO_ACPI_TABLES;
909e50beb51SNate Lawson         }
91059db4265SNate Lawson 
91159db4265SNate Lawson #if ACPI_MACHINE_WIDTH != 64
91259db4265SNate Lawson 
913e50beb51SNate Lawson         if (!ACPI_STRNCMP (NewTable->Signature, RSDT_SIG, 4))
91459db4265SNate Lawson         {
91559db4265SNate Lawson             PointerSize = sizeof (UINT32);
91659db4265SNate Lawson         }
91759db4265SNate Lawson         else
91859db4265SNate Lawson #endif
91959db4265SNate Lawson         {
92059db4265SNate Lawson             PointerSize = sizeof (UINT64);
92159db4265SNate Lawson         }
92259db4265SNate Lawson 
92359db4265SNate Lawson         /*
92459db4265SNate Lawson          * Determine the number of tables pointed to by the RSDT/XSDT.
92559db4265SNate Lawson          * This is defined by the ACPI Specification to be the number of
92659db4265SNate Lawson          * pointers contained within the RSDT/XSDT.  The size of the pointers
92759db4265SNate Lawson          * is architecture-dependent.
92859db4265SNate Lawson          */
92959db4265SNate Lawson         NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
93059db4265SNate Lawson         AcpiOsPrintf ("There are %d tables defined in the %4.4s\n\n",
93159db4265SNate Lawson             NumTables, NewTable->Signature);
93259db4265SNate Lawson 
93359db4265SNate Lawson         /* Get the FADT */
93459db4265SNate Lawson 
935e50beb51SNate Lawson         ACPI_STRNCPY (TableHeader.Signature, FADT_SIG, 4);
93659db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
93759db4265SNate Lawson         if (NewTable)
93859db4265SNate Lawson         {
93959db4265SNate Lawson             AcpiGbl_FADT = (void *) NewTable;
94059db4265SNate Lawson             AdWriteTable (NewTable, NewTable->Length,
941e50beb51SNate Lawson                 FADT_SIG, NewTable->OemTableId);
942c8466860SMark Santcroos 
943c8466860SMark Santcroos             /* Use the FADT tableID for the FACS, since FACS has no ID */
944c8466860SMark Santcroos 
945c8466860SMark Santcroos             FacsSuffix = AcpiGbl_FADT->OemTableId;
94659db4265SNate Lawson         }
94759db4265SNate Lawson         AcpiOsPrintf ("\n");
94859db4265SNate Lawson 
94959db4265SNate Lawson         /* Get the FACS */
95059db4265SNate Lawson 
951e50beb51SNate Lawson         ACPI_STRNCPY (TableHeader.Signature, FACS_SIG, 4);
95259db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
95359db4265SNate Lawson         if (NewTable)
95459db4265SNate Lawson         {
95559db4265SNate Lawson             AcpiGbl_FACS = (void *) NewTable;
95659db4265SNate Lawson             AdWriteTable (NewTable, AcpiGbl_FACS->Length,
957c8466860SMark Santcroos                 FACS_SIG, FacsSuffix);
95859db4265SNate Lawson         }
95959db4265SNate Lawson         AcpiOsPrintf ("\n");
96059db4265SNate Lawson     }
96159db4265SNate Lawson 
96259db4265SNate Lawson     /* Always get the DSDT */
96359db4265SNate Lawson 
96459db4265SNate Lawson     ACPI_STRNCPY (TableHeader.Signature, DSDT_SIG, 4);
96559db4265SNate Lawson     AcpiOsTableOverride (&TableHeader, &NewTable);
96659db4265SNate Lawson     if (NewTable)
96759db4265SNate Lawson     {
96859db4265SNate Lawson         Status = AE_OK;
96959db4265SNate Lawson         AcpiGbl_DSDT = NewTable;
97059db4265SNate Lawson         AdWriteTable (AcpiGbl_DSDT, AcpiGbl_DSDT->Length,
97159db4265SNate Lawson             "DSDT", AcpiGbl_DSDT->OemTableId);
97259db4265SNate Lawson     }
97359db4265SNate Lawson     else
97459db4265SNate Lawson     {
97559db4265SNate Lawson         fprintf (stderr, "Could not obtain DSDT\n");
976e50beb51SNate Lawson         return AE_NO_ACPI_TABLES;
97759db4265SNate Lawson     }
97859db4265SNate Lawson 
97959db4265SNate Lawson     AcpiOsPrintf ("\n");
98059db4265SNate Lawson 
98159db4265SNate Lawson     /* Get all SSDTs */
98259db4265SNate Lawson 
98359db4265SNate Lawson     ACPI_STRNCPY (TableHeader.Signature, SSDT_SIG, 4);
98459db4265SNate Lawson     Status = AcpiOsTableOverride (&TableHeader, &NewTable);
98559db4265SNate Lawson     if (NewTable)
98659db4265SNate Lawson     {
98759db4265SNate Lawson         while (NewTable)
98859db4265SNate Lawson         {
98959db4265SNate Lawson             Status = AcpiOsTableOverride (&TableHeader, &NewTable);
99059db4265SNate Lawson         }
99159db4265SNate Lawson     }
99259db4265SNate Lawson 
99359db4265SNate Lawson     return AE_OK;
99459db4265SNate Lawson }
99559db4265SNate Lawson 
99659db4265SNate Lawson /******************************************************************************
99759db4265SNate Lawson  *
99859db4265SNate Lawson  * FUNCTION:    AdParseTable
99959db4265SNate Lawson  *
1000fba7fc7eSJung-uk Kim  * PARAMETERS:  Table           - Pointer to the raw table
100159db4265SNate Lawson  *
100259db4265SNate Lawson  * RETURN:      Status
100359db4265SNate Lawson  *
100459db4265SNate Lawson  * DESCRIPTION: Parse the DSDT.
100559db4265SNate Lawson  *
100659db4265SNate Lawson  *****************************************************************************/
100759db4265SNate Lawson 
100859db4265SNate Lawson ACPI_STATUS
100959db4265SNate Lawson AdParseTable (
101059db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
101159db4265SNate Lawson {
101259db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
101359db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
101459db4265SNate Lawson     ACPI_TABLE_DESC         TableDesc;
101559db4265SNate Lawson     UINT8                   *AmlStart;
101659db4265SNate Lawson     UINT32                  AmlLength;
101759db4265SNate Lawson 
101859db4265SNate Lawson 
101959db4265SNate Lawson     if (!Table)
102059db4265SNate Lawson     {
102159db4265SNate Lawson         return AE_NOT_EXIST;
102259db4265SNate Lawson     }
102359db4265SNate Lawson 
102459db4265SNate Lawson     /* Pass 1:  Parse everything except control method bodies */
102559db4265SNate Lawson 
102659db4265SNate Lawson     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
102759db4265SNate Lawson 
102859db4265SNate Lawson     AmlLength  = Table->Length  - sizeof (ACPI_TABLE_HEADER);
102959db4265SNate Lawson     AmlStart   = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
103059db4265SNate Lawson 
103159db4265SNate Lawson     /* Create the root object */
103259db4265SNate Lawson 
103359db4265SNate Lawson     AcpiGbl_ParsedNamespaceRoot = AcpiPsCreateScopeOp ();
103459db4265SNate Lawson     if (!AcpiGbl_ParsedNamespaceRoot)
103559db4265SNate Lawson     {
103659db4265SNate Lawson         return AE_NO_MEMORY;
103759db4265SNate Lawson     }
103859db4265SNate Lawson 
103959db4265SNate Lawson     /* Create and initialize a new walk state */
104059db4265SNate Lawson 
104159db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0,
104259db4265SNate Lawson                         AcpiGbl_ParsedNamespaceRoot, NULL, NULL);
104359db4265SNate Lawson     if (!WalkState)
104459db4265SNate Lawson     {
104559db4265SNate Lawson         return (AE_NO_MEMORY);
104659db4265SNate Lawson     }
104759db4265SNate Lawson 
104859db4265SNate Lawson     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParsedNamespaceRoot,
1049a5a81f7cSNate Lawson                 NULL, AmlStart, AmlLength, NULL, 1);
105059db4265SNate Lawson     if (ACPI_FAILURE (Status))
105159db4265SNate Lawson     {
105259db4265SNate Lawson         return (Status);
105359db4265SNate Lawson     }
105459db4265SNate Lawson 
105559db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1056fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
105759db4265SNate Lawson 
105859db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
105959db4265SNate Lawson     if (ACPI_FAILURE (Status))
106059db4265SNate Lawson     {
106159db4265SNate Lawson         return Status;
106259db4265SNate Lawson     }
106359db4265SNate Lawson 
106459db4265SNate Lawson     /* Pass 2 */
106559db4265SNate Lawson 
106659db4265SNate Lawson     TableDesc.AmlStart = AmlStart;
106759db4265SNate Lawson     TableDesc.AmlLength = AmlLength;
106859db4265SNate Lawson     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
1069fba7fc7eSJung-uk Kim     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
107059db4265SNate Lawson 
107159db4265SNate Lawson     Status = AcpiNsOneCompleteParse (2, &TableDesc);
107259db4265SNate Lawson     if (ACPI_FAILURE (Status))
107359db4265SNate Lawson     {
107459db4265SNate Lawson         return (Status);
107559db4265SNate Lawson     }
107659db4265SNate Lawson 
107759db4265SNate Lawson     /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
107859db4265SNate Lawson 
107959db4265SNate Lawson     Status = AdParseDeferredOps (AcpiGbl_ParsedNamespaceRoot);
108059db4265SNate Lawson 
108159db4265SNate Lawson     fprintf (stderr, "Parsing completed\n");
108259db4265SNate Lawson     return AE_OK;
108359db4265SNate Lawson }
108459db4265SNate Lawson 
108559db4265SNate Lawson 
1086