xref: /freebsd/sys/contrib/dev/acpica/common/adisasm.c (revision 59db4265c5cf1ef9400027c7325c66c55a3ad065)
159db4265SNate Lawson /******************************************************************************
259db4265SNate Lawson  *
359db4265SNate Lawson  * Module Name: adisasm - Application-level disassembler routines
459db4265SNate Lawson  *              $Revision: 58 $
559db4265SNate Lawson  *
659db4265SNate Lawson  *****************************************************************************/
759db4265SNate Lawson 
859db4265SNate Lawson /******************************************************************************
959db4265SNate Lawson  *
1059db4265SNate Lawson  * 1. Copyright Notice
1159db4265SNate Lawson  *
1259db4265SNate Lawson  * Some or all of this work - Copyright (c) 1999 - 2003, 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 
11859db4265SNate Lawson #include "acpi.h"
11959db4265SNate Lawson #include "acparser.h"
12059db4265SNate Lawson #include "amlcode.h"
12159db4265SNate Lawson #include "acdebug.h"
12259db4265SNate Lawson #include "acdisasm.h"
12359db4265SNate Lawson #include "acdispat.h"
12459db4265SNate Lawson #include "acnamesp.h"
12559db4265SNate Lawson #include "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 
13959db4265SNate Lawson #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 
15059db4265SNate Lawson ACPI_STATUS
15159db4265SNate Lawson AcpiDsRestartControlMethod (
15259db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
15359db4265SNate Lawson     ACPI_OPERAND_OBJECT     *ReturnDesc)
15459db4265SNate Lawson {
15559db4265SNate Lawson     return (AE_OK);
15659db4265SNate Lawson }
15759db4265SNate Lawson 
15859db4265SNate Lawson ACPI_STATUS
15959db4265SNate Lawson AcpiDsTerminateControlMethod (
16059db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
16159db4265SNate Lawson {
16259db4265SNate Lawson     return (AE_OK);
16359db4265SNate Lawson }
16459db4265SNate Lawson 
16559db4265SNate Lawson ACPI_STATUS
16659db4265SNate Lawson AcpiDsCallControlMethod (
16759db4265SNate Lawson     ACPI_THREAD_STATE       *Thread,
16859db4265SNate Lawson     ACPI_WALK_STATE         *WalkState,
16959db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op)
17059db4265SNate Lawson {
17159db4265SNate Lawson     return (AE_OK);
17259db4265SNate Lawson }
17359db4265SNate Lawson 
17459db4265SNate Lawson ACPI_STATUS
17559db4265SNate Lawson AcpiDsMethodDataInitArgs (
17659db4265SNate Lawson     ACPI_OPERAND_OBJECT     **Params,
17759db4265SNate Lawson     UINT32                  MaxParamCount,
17859db4265SNate Lawson     ACPI_WALK_STATE         *WalkState)
17959db4265SNate Lawson {
18059db4265SNate Lawson     return (AE_OK);
18159db4265SNate Lawson }
18259db4265SNate Lawson 
18359db4265SNate Lawson 
18459db4265SNate Lawson #define FILE_SUFFIX_DISASSEMBLY     "dsl"
18559db4265SNate Lawson #define ACPI_TABLE_FILE_SUFFIX      ".dat"
18659db4265SNate Lawson char                        FilenameBuf[20];
18759db4265SNate Lawson 
18859db4265SNate Lawson /******************************************************************************
18959db4265SNate Lawson  *
19059db4265SNate Lawson  * FUNCTION:    AfGenerateFilename
19159db4265SNate Lawson  *
19259db4265SNate Lawson  * PARAMETERS:
19359db4265SNate Lawson  *
19459db4265SNate Lawson  * RETURN:
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  *
23259db4265SNate Lawson  * PARAMETERS:
23359db4265SNate Lawson  *
23459db4265SNate Lawson  * RETURN:
23559db4265SNate Lawson  *
23659db4265SNate Lawson  * DESCRIPTION: Open a file and write out a single buffer
23759db4265SNate Lawson  *
23859db4265SNate Lawson  ******************************************************************************/
23959db4265SNate Lawson 
24059db4265SNate Lawson ACPI_NATIVE_INT
24159db4265SNate Lawson AdWriteBuffer (
24259db4265SNate Lawson     char                *Filename,
24359db4265SNate Lawson     char                *Buffer,
24459db4265SNate Lawson     UINT32              Length)
24559db4265SNate Lawson {
24659db4265SNate Lawson     FILE                *fp;
24759db4265SNate Lawson     ACPI_NATIVE_INT     Actual;
24859db4265SNate Lawson 
24959db4265SNate Lawson 
25059db4265SNate Lawson     fp = fopen (Filename, "wb");
25159db4265SNate Lawson     if (!fp)
25259db4265SNate Lawson     {
25359db4265SNate Lawson         printf ("Couldn't open %s\n", Filename);
25459db4265SNate Lawson         return -1;
25559db4265SNate Lawson     }
25659db4265SNate Lawson 
25759db4265SNate Lawson     Actual = fwrite (Buffer, (size_t) Length, 1, fp);
25859db4265SNate Lawson     fclose (fp);
25959db4265SNate Lawson     return Actual;
26059db4265SNate Lawson }
26159db4265SNate Lawson 
26259db4265SNate Lawson 
26359db4265SNate Lawson /******************************************************************************
26459db4265SNate Lawson  *
26559db4265SNate Lawson  * FUNCTION:    AfWriteTable
26659db4265SNate Lawson  *
26759db4265SNate Lawson  * PARAMETERS:
26859db4265SNate Lawson  *
26959db4265SNate Lawson  * RETURN:
27059db4265SNate Lawson  *
27159db4265SNate Lawson  * DESCRIPTION: Dump the loaded tables to a file (or files)
27259db4265SNate Lawson  *
27359db4265SNate Lawson  ******************************************************************************/
27459db4265SNate Lawson 
27559db4265SNate Lawson void
27659db4265SNate Lawson AdWriteTable (
27759db4265SNate Lawson     ACPI_TABLE_HEADER       *Table,
27859db4265SNate Lawson     UINT32                  Length,
27959db4265SNate Lawson     char                    *TableName,
28059db4265SNate Lawson     char                    *OemTableId)
28159db4265SNate Lawson {
28259db4265SNate Lawson     char                    *Filename;
28359db4265SNate Lawson 
28459db4265SNate Lawson 
28559db4265SNate Lawson     Filename = AdGenerateFilename (TableName, OemTableId);
28659db4265SNate Lawson     AdWriteBuffer (Filename, (char *) Table, Length);
28759db4265SNate Lawson 
28859db4265SNate Lawson     AcpiOsPrintf ("Table [%s] written to \"%s\"\n", TableName, Filename);
28959db4265SNate Lawson }
29059db4265SNate Lawson 
29159db4265SNate Lawson 
29259db4265SNate Lawson /*******************************************************************************
29359db4265SNate Lawson  *
29459db4265SNate Lawson  * FUNCTION:    AdInitialize
29559db4265SNate Lawson  *
29659db4265SNate Lawson  * PARAMETERS:  None.
29759db4265SNate Lawson  *
29859db4265SNate Lawson  * RETURN:      Status
29959db4265SNate Lawson  *
30059db4265SNate Lawson  * DESCRIPTION: CA initialization
30159db4265SNate Lawson  *
30259db4265SNate Lawson  ******************************************************************************/
30359db4265SNate Lawson 
30459db4265SNate Lawson ACPI_STATUS
30559db4265SNate Lawson AdInitialize (
30659db4265SNate Lawson     void)
30759db4265SNate Lawson {
30859db4265SNate Lawson     ACPI_STATUS             Status;
30959db4265SNate Lawson 
31059db4265SNate Lawson 
31159db4265SNate Lawson     /* ACPI CA subsystem initialization */
31259db4265SNate Lawson 
31359db4265SNate Lawson     AcpiUtInitGlobals ();
31459db4265SNate Lawson     Status = AcpiUtMutexInitialize ();
31559db4265SNate Lawson     if (ACPI_FAILURE (Status))
31659db4265SNate Lawson     {
31759db4265SNate Lawson         return Status;
31859db4265SNate Lawson     }
31959db4265SNate Lawson 
32059db4265SNate Lawson     Status = AcpiNsRootInitialize ();
32159db4265SNate Lawson     return Status;
32259db4265SNate Lawson }
32359db4265SNate Lawson 
32459db4265SNate Lawson 
32559db4265SNate Lawson /*******************************************************************************
32659db4265SNate Lawson  *
32759db4265SNate Lawson  * FUNCTION:    FlGenerateFilename
32859db4265SNate Lawson  *
32959db4265SNate Lawson  * PARAMETERS:  InputFilename       - Original ASL source filename
33059db4265SNate Lawson  *              Suffix              - New extension.
33159db4265SNate Lawson  *
33259db4265SNate Lawson  * RETURN:      New filename containing the original base + the new suffix
33359db4265SNate Lawson  *
33459db4265SNate Lawson  * DESCRIPTION: Generate a new filename from the ASL source filename and a new
33559db4265SNate Lawson  *              extension.  Used to create the *.LST, *.TXT, etc. files.
33659db4265SNate Lawson  *
33759db4265SNate Lawson  ******************************************************************************/
33859db4265SNate Lawson 
33959db4265SNate Lawson char *
34059db4265SNate Lawson FlGenerateFilename (
34159db4265SNate Lawson     char                    *InputFilename,
34259db4265SNate Lawson     char                    *Suffix)
34359db4265SNate Lawson {
34459db4265SNate Lawson     char                    *Position;
34559db4265SNate Lawson     char                    *NewFilename;
34659db4265SNate Lawson 
34759db4265SNate Lawson 
34859db4265SNate Lawson     /* Copy the original filename to a new buffer */
34959db4265SNate Lawson 
35059db4265SNate Lawson     NewFilename = ACPI_MEM_CALLOCATE (strlen (InputFilename) + strlen (Suffix));
35159db4265SNate Lawson     strcpy (NewFilename, InputFilename);
35259db4265SNate Lawson 
35359db4265SNate Lawson     /* Try to find the last dot in the filename */
35459db4265SNate Lawson 
35559db4265SNate Lawson     Position = strrchr (NewFilename, '.');
35659db4265SNate Lawson     if (Position)
35759db4265SNate Lawson     {
35859db4265SNate Lawson         /* Tack on the new suffix */
35959db4265SNate Lawson 
36059db4265SNate Lawson         Position++;
36159db4265SNate Lawson         *Position = 0;
36259db4265SNate Lawson         strcat (Position, Suffix);
36359db4265SNate Lawson     }
36459db4265SNate Lawson     else
36559db4265SNate Lawson     {
36659db4265SNate Lawson         /* No dot, add one and then the suffix */
36759db4265SNate Lawson 
36859db4265SNate Lawson         strcat (NewFilename, ".");
36959db4265SNate Lawson         strcat (NewFilename, Suffix);
37059db4265SNate Lawson     }
37159db4265SNate Lawson 
37259db4265SNate Lawson     return NewFilename;
37359db4265SNate Lawson }
37459db4265SNate Lawson 
37559db4265SNate Lawson 
37659db4265SNate Lawson /*******************************************************************************
37759db4265SNate Lawson  *
37859db4265SNate Lawson  * FUNCTION:    FlSplitInputPathname
37959db4265SNate Lawson  *
38059db4265SNate Lawson  * PARAMETERS:  InputFilename       - The user-specified ASL source file to be
38159db4265SNate Lawson  *                                    compiled
38259db4265SNate Lawson  *
38359db4265SNate Lawson  * RETURN:      Status
38459db4265SNate Lawson  *
38559db4265SNate Lawson  * DESCRIPTION: Split the input path into a directory and filename part
38659db4265SNate Lawson  *              1) Directory part used to open include files
38759db4265SNate Lawson  *              2) Filename part used to generate output filenames
38859db4265SNate Lawson  *
38959db4265SNate Lawson  ******************************************************************************/
39059db4265SNate Lawson 
39159db4265SNate Lawson ACPI_STATUS
39259db4265SNate Lawson FlSplitInputPathname (
39359db4265SNate Lawson     char                    *InputPath,
39459db4265SNate Lawson     char                    **OutDirectoryPath,
39559db4265SNate Lawson     char                    **OutFilename)
39659db4265SNate Lawson {
39759db4265SNate Lawson     char                    *Substring;
39859db4265SNate Lawson     char                    *DirectoryPath;
39959db4265SNate Lawson     char                    *Filename;
40059db4265SNate Lawson 
40159db4265SNate Lawson 
40259db4265SNate Lawson     *OutDirectoryPath = NULL;
40359db4265SNate Lawson     *OutFilename = NULL;
40459db4265SNate Lawson 
40559db4265SNate Lawson     if (!InputPath)
40659db4265SNate Lawson     {
40759db4265SNate Lawson         return (AE_OK);
40859db4265SNate Lawson     }
40959db4265SNate Lawson 
41059db4265SNate Lawson     /* Get the path to the input filename's directory */
41159db4265SNate Lawson 
41259db4265SNate Lawson     DirectoryPath = strdup (InputPath);
41359db4265SNate Lawson     if (!DirectoryPath)
41459db4265SNate Lawson     {
41559db4265SNate Lawson         return (AE_NO_MEMORY);
41659db4265SNate Lawson     }
41759db4265SNate Lawson 
41859db4265SNate Lawson     Substring = strrchr (DirectoryPath, '\\');
41959db4265SNate Lawson     if (!Substring)
42059db4265SNate Lawson     {
42159db4265SNate Lawson         Substring = strrchr (DirectoryPath, '/');
42259db4265SNate Lawson         if (!Substring)
42359db4265SNate Lawson         {
42459db4265SNate Lawson             Substring = strrchr (DirectoryPath, ':');
42559db4265SNate Lawson         }
42659db4265SNate Lawson     }
42759db4265SNate Lawson 
42859db4265SNate Lawson     if (!Substring)
42959db4265SNate Lawson     {
43059db4265SNate Lawson         DirectoryPath[0] = 0;
43159db4265SNate Lawson         Filename = strdup (InputPath);
43259db4265SNate Lawson     }
43359db4265SNate Lawson     else
43459db4265SNate Lawson     {
43559db4265SNate Lawson         Filename = strdup (Substring + 1);
43659db4265SNate Lawson         *(Substring+1) = 0;
43759db4265SNate Lawson     }
43859db4265SNate Lawson 
43959db4265SNate Lawson     if (!Filename)
44059db4265SNate Lawson     {
44159db4265SNate Lawson         return (AE_NO_MEMORY);
44259db4265SNate Lawson     }
44359db4265SNate Lawson 
44459db4265SNate Lawson     *OutDirectoryPath = DirectoryPath;
44559db4265SNate Lawson     *OutFilename = Filename;
44659db4265SNate Lawson 
44759db4265SNate Lawson     return (AE_OK);
44859db4265SNate Lawson }
44959db4265SNate Lawson 
45059db4265SNate Lawson 
45159db4265SNate Lawson /******************************************************************************
45259db4265SNate Lawson  *
45359db4265SNate Lawson  * FUNCTION:    AdAmlDisassemble
45459db4265SNate Lawson  *
45559db4265SNate Lawson  * PARAMETERS:  OutToFile       - TRUE if output should go to a file
45659db4265SNate Lawson  *              Filename        - AML input filename
45759db4265SNate Lawson  *
45859db4265SNate Lawson  * RETURN:      Status
45959db4265SNate Lawson  *
46059db4265SNate Lawson  * DESCRIPTION: Disassemble an entire ACPI table
46159db4265SNate Lawson  *
46259db4265SNate Lawson  *****************************************************************************/
46359db4265SNate Lawson 
46459db4265SNate Lawson ACPI_STATUS
46559db4265SNate Lawson AdAmlDisassemble (
46659db4265SNate Lawson     BOOLEAN                 OutToFile,
46759db4265SNate Lawson     char                    *Filename,
46859db4265SNate Lawson     char                    *Prefix,
46959db4265SNate Lawson     char                    **OutFilename,
47059db4265SNate Lawson     BOOLEAN                 GetAllTables)
47159db4265SNate Lawson {
47259db4265SNate Lawson     ACPI_STATUS             Status;
47359db4265SNate Lawson     char                    *DisasmFilename = NULL;
47459db4265SNate Lawson     FILE                    *File = NULL;
47559db4265SNate Lawson     ACPI_TABLE_HEADER       *Table;
47659db4265SNate Lawson 
47759db4265SNate Lawson 
47859db4265SNate Lawson     /*
47959db4265SNate Lawson      * Input:  AML Code from either a file,
48059db4265SNate Lawson      *         or via GetTables (memory or registry)
48159db4265SNate Lawson      */
48259db4265SNate Lawson     if (Filename)
48359db4265SNate Lawson     {
48459db4265SNate Lawson         Status = AcpiDbGetTableFromFile (Filename, &Table);
48559db4265SNate Lawson         if (ACPI_FAILURE (Status))
48659db4265SNate Lawson         {
48759db4265SNate Lawson             return Status;
48859db4265SNate Lawson         }
48959db4265SNate Lawson     }
49059db4265SNate Lawson     else
49159db4265SNate Lawson     {
49259db4265SNate Lawson         Status = AdGetLocalTables (Filename, GetAllTables);
49359db4265SNate Lawson         if (ACPI_FAILURE (Status))
49459db4265SNate Lawson         {
49559db4265SNate Lawson             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
49659db4265SNate Lawson                 AcpiFormatException (Status));
49759db4265SNate Lawson             return Status;
49859db4265SNate Lawson         }
49959db4265SNate Lawson 
50059db4265SNate Lawson         if (!AcpiGbl_DbOpt_disasm)
50159db4265SNate Lawson         {
50259db4265SNate Lawson             return AE_OK;
50359db4265SNate Lawson         }
50459db4265SNate Lawson 
50559db4265SNate Lawson         /* Obtained the local tables, just disassmeble the DSDT */
50659db4265SNate Lawson 
50759db4265SNate Lawson         Table = AcpiGbl_DSDT;
50859db4265SNate Lawson         AcpiOsPrintf ("\nDisassembly of DSDT\n");
50959db4265SNate Lawson         Prefix = AdGenerateFilename ("dsdt", AcpiGbl_DSDT->OemTableId);
51059db4265SNate Lawson     }
51159db4265SNate Lawson 
51259db4265SNate Lawson     /*
51359db4265SNate Lawson      * Output:  ASL code.
51459db4265SNate Lawson      *          Redirect to a file if requested
51559db4265SNate Lawson      */
51659db4265SNate Lawson     if (OutToFile)
51759db4265SNate Lawson     {
51859db4265SNate Lawson         /* Create/Open a disassembly output file */
51959db4265SNate Lawson 
52059db4265SNate Lawson         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
52159db4265SNate Lawson         if (!OutFilename)
52259db4265SNate Lawson         {
52359db4265SNate Lawson             fprintf (stderr, "Could not generate output filename\n");
52459db4265SNate Lawson         }
52559db4265SNate Lawson 
52659db4265SNate Lawson         File = fopen (DisasmFilename, "w+");
52759db4265SNate Lawson         if (!File)
52859db4265SNate Lawson         {
52959db4265SNate Lawson             fprintf (stderr, "Could not open output file\n");
53059db4265SNate Lawson         }
53159db4265SNate Lawson 
53259db4265SNate Lawson         AcpiOsRedirectOutput (File);
53359db4265SNate Lawson     }
53459db4265SNate Lawson 
53559db4265SNate Lawson     *OutFilename = DisasmFilename;
53659db4265SNate Lawson 
53759db4265SNate Lawson     /* Always parse the tables, only option is what to display */
53859db4265SNate Lawson 
53959db4265SNate Lawson     Status = AdParseTable (Table);
54059db4265SNate Lawson     if (ACPI_FAILURE (Status))
54159db4265SNate Lawson     {
54259db4265SNate Lawson         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
54359db4265SNate Lawson             AcpiFormatException (Status));
54459db4265SNate Lawson         goto Cleanup;
54559db4265SNate Lawson     }
54659db4265SNate Lawson 
54759db4265SNate Lawson     /* Optional displays */
54859db4265SNate Lawson 
54959db4265SNate Lawson     if (AcpiGbl_DbOpt_disasm)
55059db4265SNate Lawson     {
55159db4265SNate Lawson         AdDisplayTables (Filename, Table);
55259db4265SNate Lawson         fprintf (stderr, "Disassembly completed, written to \"%s\"\n", DisasmFilename);
55359db4265SNate Lawson     }
55459db4265SNate Lawson 
55559db4265SNate Lawson Cleanup:
55659db4265SNate Lawson     if (OutToFile)
55759db4265SNate Lawson     {
55859db4265SNate Lawson         fclose (File);
55959db4265SNate Lawson         AcpiOsRedirectOutput (stdout);
56059db4265SNate Lawson     }
56159db4265SNate Lawson 
56259db4265SNate Lawson     AcpiPsDeleteParseTree (AcpiGbl_ParsedNamespaceRoot);
56359db4265SNate Lawson     return AE_OK;
56459db4265SNate Lawson }
56559db4265SNate Lawson 
56659db4265SNate Lawson 
56759db4265SNate Lawson /******************************************************************************
56859db4265SNate Lawson  *
56959db4265SNate Lawson  * FUNCTION:    AdCreateTableHeader
57059db4265SNate Lawson  *
57159db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
57259db4265SNate Lawson  *              Table               - Pointer to the raw table
57359db4265SNate Lawson  *
57459db4265SNate Lawson  * RETURN:      None
57559db4265SNate Lawson  *
57659db4265SNate Lawson  * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
57759db4265SNate Lawson  *              current time and date.
57859db4265SNate Lawson  *
57959db4265SNate Lawson  *****************************************************************************/
58059db4265SNate Lawson 
58159db4265SNate Lawson void
58259db4265SNate Lawson AdCreateTableHeader (
58359db4265SNate Lawson     char                    *Filename,
58459db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
58559db4265SNate Lawson {
58659db4265SNate Lawson     time_t                  Timer;
58759db4265SNate Lawson 
58859db4265SNate Lawson 
58959db4265SNate Lawson     time (&Timer);
59059db4265SNate Lawson 
59159db4265SNate Lawson     AcpiOsPrintf ("/*\n * Intel ACPI Component Architecture\n");
59259db4265SNate Lawson     AcpiOsPrintf (" * AML Disassembler version %8.8X\n", ACPI_CA_VERSION);
59359db4265SNate Lawson     AcpiOsPrintf (" *\n * Disassembly of %s, %s */\n", Filename, ctime (&Timer));
59459db4265SNate Lawson 
59559db4265SNate Lawson     AcpiOsPrintf (
59659db4265SNate Lawson         "DefinitionBlock (\"%4.4s.aml\", \"%4.4s\", %hd, \"%.6s\", \"%.8s\", %d)\n",
59759db4265SNate Lawson         Table->Signature, Table->Signature, Table->Revision,
59859db4265SNate Lawson         Table->OemId, Table->OemTableId, Table->OemRevision);
59959db4265SNate Lawson }
60059db4265SNate Lawson 
60159db4265SNate Lawson 
60259db4265SNate Lawson /******************************************************************************
60359db4265SNate Lawson  *
60459db4265SNate Lawson  * FUNCTION:    AdDisplayTables
60559db4265SNate Lawson  *
60659db4265SNate Lawson  * PARAMETERS:  Filename            - Input file for the table
60759db4265SNate Lawson  *
60859db4265SNate Lawson  * RETURN:      Status
60959db4265SNate Lawson  *
61059db4265SNate Lawson  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
61159db4265SNate Lawson  *
61259db4265SNate Lawson  *****************************************************************************/
61359db4265SNate Lawson 
61459db4265SNate Lawson ACPI_STATUS
61559db4265SNate Lawson AdDisplayTables (
61659db4265SNate Lawson     char                    *Filename,
61759db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
61859db4265SNate Lawson {
61959db4265SNate Lawson 
62059db4265SNate Lawson 
62159db4265SNate Lawson     if (!AcpiGbl_ParsedNamespaceRoot)
62259db4265SNate Lawson     {
62359db4265SNate Lawson         return AE_NOT_EXIST;
62459db4265SNate Lawson     }
62559db4265SNate Lawson 
62659db4265SNate Lawson     if (!AcpiGbl_DbOpt_verbose)
62759db4265SNate Lawson     {
62859db4265SNate Lawson         AdCreateTableHeader (Filename, Table);
62959db4265SNate Lawson     }
63059db4265SNate Lawson 
63159db4265SNate Lawson     AcpiDmDisassemble (NULL, AcpiGbl_ParsedNamespaceRoot, ACPI_UINT32_MAX);
63259db4265SNate Lawson 
63359db4265SNate Lawson     if (AcpiGbl_DbOpt_verbose)
63459db4265SNate Lawson     {
63559db4265SNate Lawson         AcpiOsPrintf ("\n\nTable Header:\n");
63659db4265SNate Lawson         AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
63759db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
63859db4265SNate Lawson 
63959db4265SNate Lawson         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
64059db4265SNate Lawson         AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
64159db4265SNate Lawson             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
64259db4265SNate Lawson     }
64359db4265SNate Lawson 
64459db4265SNate Lawson     return AE_OK;
64559db4265SNate Lawson }
64659db4265SNate Lawson 
64759db4265SNate Lawson 
64859db4265SNate Lawson /******************************************************************************
64959db4265SNate Lawson  *
65059db4265SNate Lawson  * FUNCTION:    AdDeferredParse
65159db4265SNate Lawson  *
65259db4265SNate Lawson  * PARAMETERS:  Op              - Root Op of the deferred opcode
65359db4265SNate Lawson  *              Aml             - Pointer to the raw AML
65459db4265SNate Lawson  *              AmlLength       - Length of the AML
65559db4265SNate Lawson  *
65659db4265SNate Lawson  * RETURN:      Status
65759db4265SNate Lawson  *
65859db4265SNate Lawson  * DESCRIPTION: Parse one deferred opcode
65959db4265SNate Lawson  *              (Methods, operation regions, etc.)
66059db4265SNate Lawson  *
66159db4265SNate Lawson  *****************************************************************************/
66259db4265SNate Lawson 
66359db4265SNate Lawson ACPI_STATUS
66459db4265SNate Lawson AdDeferredParse (
66559db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op,
66659db4265SNate Lawson     UINT8                   *Aml,
66759db4265SNate Lawson     UINT32                  AmlLength)
66859db4265SNate Lawson {
66959db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
67059db4265SNate Lawson     ACPI_STATUS             Status;
67159db4265SNate Lawson     ACPI_PARSE_OBJECT       *SearchOp;
67259db4265SNate Lawson     ACPI_PARSE_OBJECT       *StartOp;
67359db4265SNate Lawson     UINT32                  BaseAmlOffset;
67459db4265SNate Lawson     ACPI_PARSE_OBJECT       *ExtraOp;
67559db4265SNate Lawson 
67659db4265SNate Lawson 
67759db4265SNate Lawson     ACPI_FUNCTION_TRACE ("AdDeferredParse");
67859db4265SNate Lawson 
67959db4265SNate Lawson 
68059db4265SNate Lawson     fprintf (stderr, ".");
68159db4265SNate Lawson 
68259db4265SNate Lawson     if (!Aml || !AmlLength)
68359db4265SNate Lawson     {
68459db4265SNate Lawson         return_ACPI_STATUS (AE_OK);
68559db4265SNate Lawson     }
68659db4265SNate Lawson 
68759db4265SNate Lawson     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
68859db4265SNate Lawson         Op->Common.AmlOpName, (char *) &Op->Named.Name));
68959db4265SNate Lawson 
69059db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
69159db4265SNate Lawson     if (!WalkState)
69259db4265SNate Lawson     {
69359db4265SNate Lawson         return_ACPI_STATUS (AE_NO_MEMORY);
69459db4265SNate Lawson     }
69559db4265SNate Lawson 
69659db4265SNate Lawson     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
69759db4265SNate Lawson                     AmlLength, NULL, NULL, 1);
69859db4265SNate Lawson     if (ACPI_FAILURE (Status))
69959db4265SNate Lawson     {
70059db4265SNate Lawson         return_ACPI_STATUS (Status);
70159db4265SNate Lawson     }
70259db4265SNate Lawson 
70359db4265SNate Lawson     /* Parse the method */
70459db4265SNate Lawson 
70559db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
70659db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
70759db4265SNate Lawson 
70859db4265SNate Lawson     /*
70959db4265SNate Lawson      * We need to update all of the Aml offsets, since the parser thought
71059db4265SNate Lawson      * that the method began at offset zero.  In reality, it began somewhere
71159db4265SNate Lawson      * within the ACPI table, at the BaseAmlOffset.  Walk the entire tree that
71259db4265SNate Lawson      * was just created and update the AmlOffset in each Op
71359db4265SNate Lawson      */
71459db4265SNate Lawson     BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
71559db4265SNate Lawson     StartOp = (Op->Common.Value.Arg)->Common.Next;
71659db4265SNate Lawson     SearchOp = StartOp;
71759db4265SNate Lawson 
71859db4265SNate Lawson     /* Walk the parse tree */
71959db4265SNate Lawson 
72059db4265SNate Lawson     while (SearchOp)
72159db4265SNate Lawson     {
72259db4265SNate Lawson         SearchOp->Common.AmlOffset += BaseAmlOffset;
72359db4265SNate Lawson         SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
72459db4265SNate Lawson     }
72559db4265SNate Lawson 
72659db4265SNate Lawson     /*
72759db4265SNate Lawson      * Link the newly parsed subtree into the main parse tree
72859db4265SNate Lawson      */
72959db4265SNate Lawson     switch (Op->Common.AmlOpcode)
73059db4265SNate Lawson     {
73159db4265SNate Lawson     case AML_BUFFER_OP:
73259db4265SNate Lawson     case AML_PACKAGE_OP:
73359db4265SNate Lawson     case AML_VAR_PACKAGE_OP:
73459db4265SNate Lawson 
73559db4265SNate Lawson         switch (Op->Common.AmlOpcode)
73659db4265SNate Lawson         {
73759db4265SNate Lawson         case AML_PACKAGE_OP:
73859db4265SNate Lawson         case AML_VAR_PACKAGE_OP:
73959db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
74059db4265SNate Lawson             ExtraOp = ExtraOp->Common.Next;
74159db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
74259db4265SNate Lawson             break;
74359db4265SNate Lawson 
74459db4265SNate Lawson         case AML_BUFFER_OP:
74559db4265SNate Lawson         default:
74659db4265SNate Lawson             ExtraOp = Op->Common.Value.Arg;
74759db4265SNate Lawson             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
74859db4265SNate Lawson             break;
74959db4265SNate Lawson         }
75059db4265SNate Lawson 
75159db4265SNate Lawson         /* Must point all parents to the main tree */
75259db4265SNate Lawson 
75359db4265SNate Lawson         StartOp = Op;
75459db4265SNate Lawson         SearchOp = StartOp;
75559db4265SNate Lawson         while (SearchOp)
75659db4265SNate Lawson         {
75759db4265SNate Lawson             if (SearchOp->Common.Parent == ExtraOp)
75859db4265SNate Lawson             {
75959db4265SNate Lawson                 SearchOp->Common.Parent = Op;
76059db4265SNate Lawson             }
76159db4265SNate Lawson             SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
76259db4265SNate Lawson         }
76359db4265SNate Lawson         break;
76459db4265SNate Lawson 
76559db4265SNate Lawson     default:
76659db4265SNate Lawson         break;
76759db4265SNate Lawson     }
76859db4265SNate Lawson 
76959db4265SNate Lawson     return_ACPI_STATUS (AE_OK);
77059db4265SNate Lawson }
77159db4265SNate Lawson 
77259db4265SNate Lawson 
77359db4265SNate Lawson /******************************************************************************
77459db4265SNate Lawson  *
77559db4265SNate Lawson  * FUNCTION:    AdParseDeferredOps
77659db4265SNate Lawson  *
77759db4265SNate Lawson  * PARAMETERS:  Root            - Root of the parse tree
77859db4265SNate Lawson  *
77959db4265SNate Lawson  * RETURN:      Status
78059db4265SNate Lawson  *
78159db4265SNate Lawson  * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
78259db4265SNate Lawson  *
78359db4265SNate Lawson  *****************************************************************************/
78459db4265SNate Lawson 
78559db4265SNate Lawson ACPI_STATUS
78659db4265SNate Lawson AdParseDeferredOps (
78759db4265SNate Lawson     ACPI_PARSE_OBJECT       *Root)
78859db4265SNate Lawson {
78959db4265SNate Lawson     ACPI_PARSE_OBJECT       *Op = Root;
79059db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
79159db4265SNate Lawson     const ACPI_OPCODE_INFO  *OpInfo;
79259db4265SNate Lawson 
79359db4265SNate Lawson 
79459db4265SNate Lawson     ACPI_FUNCTION_NAME ("AdParseDeferredOps");
79559db4265SNate Lawson     fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
79659db4265SNate Lawson 
79759db4265SNate Lawson     while (Op)
79859db4265SNate Lawson     {
79959db4265SNate Lawson         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
80059db4265SNate Lawson         if (!(OpInfo->Flags & AML_DEFER))
80159db4265SNate Lawson         {
80259db4265SNate Lawson             Op = AcpiPsGetDepthNext (Root, Op);
80359db4265SNate Lawson             continue;
80459db4265SNate Lawson         }
80559db4265SNate Lawson 
80659db4265SNate Lawson         switch (Op->Common.AmlOpcode)
80759db4265SNate Lawson         {
80859db4265SNate Lawson         case AML_METHOD_OP:
80959db4265SNate Lawson         case AML_BUFFER_OP:
81059db4265SNate Lawson         case AML_PACKAGE_OP:
81159db4265SNate Lawson         case AML_VAR_PACKAGE_OP:
81259db4265SNate Lawson 
81359db4265SNate Lawson             Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
81459db4265SNate Lawson             if (ACPI_FAILURE (Status))
81559db4265SNate Lawson             {
81659db4265SNate Lawson                 return_ACPI_STATUS (Status);
81759db4265SNate Lawson             }
81859db4265SNate Lawson             break;
81959db4265SNate Lawson 
82059db4265SNate Lawson         case AML_REGION_OP:
82159db4265SNate Lawson         case AML_CREATE_QWORD_FIELD_OP:
82259db4265SNate Lawson         case AML_CREATE_DWORD_FIELD_OP:
82359db4265SNate Lawson         case AML_CREATE_WORD_FIELD_OP:
82459db4265SNate Lawson         case AML_CREATE_BYTE_FIELD_OP:
82559db4265SNate Lawson         case AML_CREATE_BIT_FIELD_OP:
82659db4265SNate Lawson         case AML_CREATE_FIELD_OP:
82759db4265SNate Lawson 
82859db4265SNate Lawson             /* Nothing to do in these cases */
82959db4265SNate Lawson 
83059db4265SNate Lawson             break;
83159db4265SNate Lawson 
83259db4265SNate Lawson         default:
83359db4265SNate Lawson             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unhandled deferred opcode [%s]\n",
83459db4265SNate Lawson                 Op->Common.AmlOpName));
83559db4265SNate Lawson             break;
83659db4265SNate Lawson         }
83759db4265SNate Lawson 
83859db4265SNate Lawson         Op = AcpiPsGetDepthNext (Root, Op);
83959db4265SNate Lawson     }
84059db4265SNate Lawson 
84159db4265SNate Lawson     fprintf (stderr, "\n");
84259db4265SNate Lawson     return Status;
84359db4265SNate Lawson }
84459db4265SNate Lawson 
84559db4265SNate Lawson 
84659db4265SNate Lawson /******************************************************************************
84759db4265SNate Lawson  *
84859db4265SNate Lawson  * FUNCTION:    AdGetLocalTables
84959db4265SNate Lawson  *
85059db4265SNate Lawson  * PARAMETERS:
85159db4265SNate Lawson  *
85259db4265SNate Lawson  * RETURN:      None
85359db4265SNate Lawson  *
85459db4265SNate Lawson  * DESCRIPTION: Get the ACPI tables from either memory or a file
85559db4265SNate Lawson  *
85659db4265SNate Lawson  *****************************************************************************/
85759db4265SNate Lawson 
85859db4265SNate Lawson ACPI_STATUS
85959db4265SNate Lawson AdGetLocalTables (
86059db4265SNate Lawson     char                    *Filename,
86159db4265SNate Lawson     BOOLEAN                 GetAllTables)
86259db4265SNate Lawson {
86359db4265SNate Lawson     ACPI_STATUS             Status;
86459db4265SNate Lawson     ACPI_TABLE_HEADER       TableHeader;
86559db4265SNate Lawson     ACPI_TABLE_HEADER       *NewTable;
86659db4265SNate Lawson     UINT32                  NumTables;
86759db4265SNate Lawson     UINT32                  PointerSize;
86859db4265SNate Lawson 
86959db4265SNate Lawson 
87059db4265SNate Lawson     if (GetAllTables)
87159db4265SNate Lawson     {
87259db4265SNate Lawson         ACPI_STRNCPY (TableHeader.Signature, "RSDT", 4);
87359db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
87459db4265SNate Lawson 
87559db4265SNate Lawson #if ACPI_MACHINE_WIDTH != 64
87659db4265SNate Lawson 
87759db4265SNate Lawson         if (!ACPI_STRNCMP (NewTable->Signature, "RSDT", 4))
87859db4265SNate Lawson         {
87959db4265SNate Lawson             PointerSize = sizeof (UINT32);
88059db4265SNate Lawson         }
88159db4265SNate Lawson         else
88259db4265SNate Lawson #endif
88359db4265SNate Lawson         {
88459db4265SNate Lawson             PointerSize = sizeof (UINT64);
88559db4265SNate Lawson         }
88659db4265SNate Lawson 
88759db4265SNate Lawson         /*
88859db4265SNate Lawson          * Determine the number of tables pointed to by the RSDT/XSDT.
88959db4265SNate Lawson          * This is defined by the ACPI Specification to be the number of
89059db4265SNate Lawson          * pointers contained within the RSDT/XSDT.  The size of the pointers
89159db4265SNate Lawson          * is architecture-dependent.
89259db4265SNate Lawson          */
89359db4265SNate Lawson         NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
89459db4265SNate Lawson         AcpiOsPrintf ("There are %d tables defined in the %4.4s\n\n",
89559db4265SNate Lawson             NumTables, NewTable->Signature);
89659db4265SNate Lawson 
89759db4265SNate Lawson         /* Get the FADT */
89859db4265SNate Lawson 
89959db4265SNate Lawson         ACPI_STRNCPY (TableHeader.Signature, "FADT", 4);
90059db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
90159db4265SNate Lawson         if (NewTable)
90259db4265SNate Lawson         {
90359db4265SNate Lawson             AcpiGbl_FADT = (void *) NewTable;
90459db4265SNate Lawson             AdWriteTable (NewTable, NewTable->Length,
90559db4265SNate Lawson                 "FADT", NewTable->OemTableId);
90659db4265SNate Lawson         }
90759db4265SNate Lawson         AcpiOsPrintf ("\n");
90859db4265SNate Lawson 
90959db4265SNate Lawson         /* Get the FACS */
91059db4265SNate Lawson 
91159db4265SNate Lawson         ACPI_STRNCPY (TableHeader.Signature, "FACS", 4);
91259db4265SNate Lawson         AcpiOsTableOverride (&TableHeader, &NewTable);
91359db4265SNate Lawson         if (NewTable)
91459db4265SNate Lawson         {
91559db4265SNate Lawson             AcpiGbl_FACS = (void *) NewTable;
91659db4265SNate Lawson             AdWriteTable (NewTable, AcpiGbl_FACS->Length,
91759db4265SNate Lawson                 "FACS", AcpiGbl_FADT->Header.OemTableId);
91859db4265SNate Lawson         }
91959db4265SNate Lawson         AcpiOsPrintf ("\n");
92059db4265SNate Lawson     }
92159db4265SNate Lawson 
92259db4265SNate Lawson     /* Always get the DSDT */
92359db4265SNate Lawson 
92459db4265SNate Lawson     ACPI_STRNCPY (TableHeader.Signature, DSDT_SIG, 4);
92559db4265SNate Lawson     AcpiOsTableOverride (&TableHeader, &NewTable);
92659db4265SNate Lawson     if (NewTable)
92759db4265SNate Lawson     {
92859db4265SNate Lawson         Status = AE_OK;
92959db4265SNate Lawson         AcpiGbl_DSDT = NewTable;
93059db4265SNate Lawson         AdWriteTable (AcpiGbl_DSDT, AcpiGbl_DSDT->Length,
93159db4265SNate Lawson             "DSDT", AcpiGbl_DSDT->OemTableId);
93259db4265SNate Lawson     }
93359db4265SNate Lawson     else
93459db4265SNate Lawson     {
93559db4265SNate Lawson         fprintf (stderr, "Could not obtain DSDT\n");
93659db4265SNate Lawson         Status = AE_NO_ACPI_TABLES;
93759db4265SNate Lawson     }
93859db4265SNate Lawson 
93959db4265SNate Lawson     AcpiOsPrintf ("\n");
94059db4265SNate Lawson 
94159db4265SNate Lawson     /* Get all SSDTs */
94259db4265SNate Lawson 
94359db4265SNate Lawson     ACPI_STRNCPY (TableHeader.Signature, SSDT_SIG, 4);
94459db4265SNate Lawson     Status = AcpiOsTableOverride (&TableHeader, &NewTable);
94559db4265SNate Lawson     if (NewTable)
94659db4265SNate Lawson     {
94759db4265SNate Lawson         while (NewTable)
94859db4265SNate Lawson         {
94959db4265SNate Lawson             Status = AcpiOsTableOverride (&TableHeader, &NewTable);
95059db4265SNate Lawson         }
95159db4265SNate Lawson     }
95259db4265SNate Lawson 
95359db4265SNate Lawson #ifdef _HPET
95459db4265SNate Lawson     AfGetHpet ();
95559db4265SNate Lawson #endif
95659db4265SNate Lawson 
95759db4265SNate Lawson     return AE_OK;
95859db4265SNate Lawson }
95959db4265SNate Lawson 
96059db4265SNate Lawson /******************************************************************************
96159db4265SNate Lawson  *
96259db4265SNate Lawson  * FUNCTION:    AdParseTable
96359db4265SNate Lawson  *
96459db4265SNate Lawson  * PARAMETERS:  None
96559db4265SNate Lawson  *
96659db4265SNate Lawson  * RETURN:      Status
96759db4265SNate Lawson  *
96859db4265SNate Lawson  * DESCRIPTION: Parse the DSDT.
96959db4265SNate Lawson  *
97059db4265SNate Lawson  *****************************************************************************/
97159db4265SNate Lawson 
97259db4265SNate Lawson ACPI_STATUS
97359db4265SNate Lawson AdParseTable (
97459db4265SNate Lawson     ACPI_TABLE_HEADER       *Table)
97559db4265SNate Lawson {
97659db4265SNate Lawson     ACPI_STATUS             Status = AE_OK;
97759db4265SNate Lawson     ACPI_WALK_STATE         *WalkState;
97859db4265SNate Lawson     ACPI_TABLE_DESC         TableDesc;
97959db4265SNate Lawson     UINT8                   *AmlStart;
98059db4265SNate Lawson     UINT32                  AmlLength;
98159db4265SNate Lawson 
98259db4265SNate Lawson 
98359db4265SNate Lawson     if (!Table)
98459db4265SNate Lawson     {
98559db4265SNate Lawson         return AE_NOT_EXIST;
98659db4265SNate Lawson     }
98759db4265SNate Lawson 
98859db4265SNate Lawson     /* Pass 1:  Parse everything except control method bodies */
98959db4265SNate Lawson 
99059db4265SNate Lawson     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
99159db4265SNate Lawson 
99259db4265SNate Lawson     AmlLength  = Table->Length  - sizeof (ACPI_TABLE_HEADER);
99359db4265SNate Lawson     AmlStart   = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
99459db4265SNate Lawson 
99559db4265SNate Lawson     /* Create the root object */
99659db4265SNate Lawson 
99759db4265SNate Lawson     AcpiGbl_ParsedNamespaceRoot = AcpiPsCreateScopeOp ();
99859db4265SNate Lawson     if (!AcpiGbl_ParsedNamespaceRoot)
99959db4265SNate Lawson     {
100059db4265SNate Lawson         return AE_NO_MEMORY;
100159db4265SNate Lawson     }
100259db4265SNate Lawson 
100359db4265SNate Lawson     /* Create and initialize a new walk state */
100459db4265SNate Lawson 
100559db4265SNate Lawson     WalkState = AcpiDsCreateWalkState (0,
100659db4265SNate Lawson                         AcpiGbl_ParsedNamespaceRoot, NULL, NULL);
100759db4265SNate Lawson     if (!WalkState)
100859db4265SNate Lawson     {
100959db4265SNate Lawson         return (AE_NO_MEMORY);
101059db4265SNate Lawson     }
101159db4265SNate Lawson 
101259db4265SNate Lawson     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParsedNamespaceRoot,
101359db4265SNate Lawson                 NULL, AmlStart, AmlLength, NULL, NULL, 1);
101459db4265SNate Lawson     if (ACPI_FAILURE (Status))
101559db4265SNate Lawson     {
101659db4265SNate Lawson         return (Status);
101759db4265SNate Lawson     }
101859db4265SNate Lawson 
101959db4265SNate Lawson     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
102059db4265SNate Lawson 
102159db4265SNate Lawson     Status = AcpiPsParseAml (WalkState);
102259db4265SNate Lawson     if (ACPI_FAILURE (Status))
102359db4265SNate Lawson     {
102459db4265SNate Lawson         return Status;
102559db4265SNate Lawson     }
102659db4265SNate Lawson 
102759db4265SNate Lawson     /* Pass 2 */
102859db4265SNate Lawson 
102959db4265SNate Lawson     TableDesc.AmlStart = AmlStart;
103059db4265SNate Lawson     TableDesc.AmlLength = AmlLength;
103159db4265SNate Lawson     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
103259db4265SNate Lawson 
103359db4265SNate Lawson     Status = AcpiNsOneCompleteParse (2, &TableDesc);
103459db4265SNate Lawson     if (ACPI_FAILURE (Status))
103559db4265SNate Lawson     {
103659db4265SNate Lawson         return (Status);
103759db4265SNate Lawson     }
103859db4265SNate Lawson 
103959db4265SNate Lawson     /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
104059db4265SNate Lawson 
104159db4265SNate Lawson     Status = AdParseDeferredOps (AcpiGbl_ParsedNamespaceRoot);
104259db4265SNate Lawson 
104359db4265SNate Lawson     fprintf (stderr, "Parsing completed\n");
104459db4265SNate Lawson     return AE_OK;
104559db4265SNate Lawson }
104659db4265SNate Lawson 
104759db4265SNate Lawson 
1048