Home | History | Annotate | Line # | Download | only in common
adisasm.c revision 1.1.1.1
      1  1.1  jruoho /******************************************************************************
      2  1.1  jruoho  *
      3  1.1  jruoho  * Module Name: adisasm - Application-level disassembler routines
      4  1.1  jruoho  *
      5  1.1  jruoho  *****************************************************************************/
      6  1.1  jruoho 
      7  1.1  jruoho /******************************************************************************
      8  1.1  jruoho  *
      9  1.1  jruoho  * 1. Copyright Notice
     10  1.1  jruoho  *
     11  1.1  jruoho  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     12  1.1  jruoho  * All rights reserved.
     13  1.1  jruoho  *
     14  1.1  jruoho  * 2. License
     15  1.1  jruoho  *
     16  1.1  jruoho  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1  jruoho  * rights.  You may have additional license terms from the party that provided
     18  1.1  jruoho  * you this software, covering your right to use that party's intellectual
     19  1.1  jruoho  * property rights.
     20  1.1  jruoho  *
     21  1.1  jruoho  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1  jruoho  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1  jruoho  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1  jruoho  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1  jruoho  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1  jruoho  * Code in any form, with the right to sublicense such rights; and
     27  1.1  jruoho  *
     28  1.1  jruoho  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1  jruoho  * license (with the right to sublicense), under only those claims of Intel
     30  1.1  jruoho  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1  jruoho  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1  jruoho  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1  jruoho  * license, and in no event shall the patent license extend to any additions
     34  1.1  jruoho  * to or modifications of the Original Intel Code.  No other license or right
     35  1.1  jruoho  * is granted directly or by implication, estoppel or otherwise;
     36  1.1  jruoho  *
     37  1.1  jruoho  * The above copyright and patent license is granted only if the following
     38  1.1  jruoho  * conditions are met:
     39  1.1  jruoho  *
     40  1.1  jruoho  * 3. Conditions
     41  1.1  jruoho  *
     42  1.1  jruoho  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     44  1.1  jruoho  * Code or modification with rights to further distribute source must include
     45  1.1  jruoho  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1  jruoho  * and the following Disclaimer and Export Compliance provision.  In addition,
     47  1.1  jruoho  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1  jruoho  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1  jruoho  * Code and the date of any change.  Licensee must include in that file the
     50  1.1  jruoho  * documentation of any changes made by any predecessor Licensee.  Licensee
     51  1.1  jruoho  * must include a prominent statement that the modification is derived,
     52  1.1  jruoho  * directly or indirectly, from Original Intel Code.
     53  1.1  jruoho  *
     54  1.1  jruoho  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     56  1.1  jruoho  * Code or modification without rights to further distribute source must
     57  1.1  jruoho  * include the following Disclaimer and Export Compliance provision in the
     58  1.1  jruoho  * documentation and/or other materials provided with distribution.  In
     59  1.1  jruoho  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1  jruoho  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1  jruoho  * license from Licensee to its licensee is limited to the intellectual
     62  1.1  jruoho  * property embodied in the software Licensee provides to its licensee, and
     63  1.1  jruoho  * not to intellectual property embodied in modifications its licensee may
     64  1.1  jruoho  * make.
     65  1.1  jruoho  *
     66  1.1  jruoho  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1  jruoho  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1  jruoho  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1  jruoho  * provision in the documentation and/or other materials provided with the
     70  1.1  jruoho  * distribution.
     71  1.1  jruoho  *
     72  1.1  jruoho  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1  jruoho  * Intel Code.
     74  1.1  jruoho  *
     75  1.1  jruoho  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1  jruoho  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1  jruoho  * other dealings in products derived from or relating to the Covered Code
     78  1.1  jruoho  * without prior written authorization from Intel.
     79  1.1  jruoho  *
     80  1.1  jruoho  * 4. Disclaimer and Export Compliance
     81  1.1  jruoho  *
     82  1.1  jruoho  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1  jruoho  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1  jruoho  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     85  1.1  jruoho  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     86  1.1  jruoho  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1  jruoho  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1  jruoho  * PARTICULAR PURPOSE.
     89  1.1  jruoho  *
     90  1.1  jruoho  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1  jruoho  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1  jruoho  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1  jruoho  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1  jruoho  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1  jruoho  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     96  1.1  jruoho  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1  jruoho  * LIMITED REMEDY.
     98  1.1  jruoho  *
     99  1.1  jruoho  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1  jruoho  * software or system incorporating such software without first obtaining any
    101  1.1  jruoho  * required license or other approval from the U. S. Department of Commerce or
    102  1.1  jruoho  * any other agency or department of the United States Government.  In the
    103  1.1  jruoho  * event Licensee exports any such software from the United States or
    104  1.1  jruoho  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1  jruoho  * ensure that the distribution and export/re-export of the software is in
    106  1.1  jruoho  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1  jruoho  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1  jruoho  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1  jruoho  * software, or service, directly or indirectly, to any country for which the
    110  1.1  jruoho  * United States government or any agency thereof requires an export license,
    111  1.1  jruoho  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1  jruoho  * such license, approval or letter.
    113  1.1  jruoho  *
    114  1.1  jruoho  *****************************************************************************/
    115  1.1  jruoho 
    116  1.1  jruoho 
    117  1.1  jruoho #include "acpi.h"
    118  1.1  jruoho #include "accommon.h"
    119  1.1  jruoho #include "acparser.h"
    120  1.1  jruoho #include "amlcode.h"
    121  1.1  jruoho #include "acdebug.h"
    122  1.1  jruoho #include "acdisasm.h"
    123  1.1  jruoho #include "acdispat.h"
    124  1.1  jruoho #include "acnamesp.h"
    125  1.1  jruoho #include "actables.h"
    126  1.1  jruoho #include "acapps.h"
    127  1.1  jruoho 
    128  1.1  jruoho #include <stdio.h>
    129  1.1  jruoho #include <time.h>
    130  1.1  jruoho 
    131  1.1  jruoho 
    132  1.1  jruoho #define _COMPONENT          ACPI_TOOLS
    133  1.1  jruoho         ACPI_MODULE_NAME    ("adisasm")
    134  1.1  jruoho 
    135  1.1  jruoho 
    136  1.1  jruoho extern int                  AslCompilerdebug;
    137  1.1  jruoho extern char                 *Gbl_ExternalFilename;
    138  1.1  jruoho 
    139  1.1  jruoho 
    140  1.1  jruoho ACPI_STATUS
    141  1.1  jruoho LsDisplayNamespace (
    142  1.1  jruoho     void);
    143  1.1  jruoho 
    144  1.1  jruoho void
    145  1.1  jruoho LsSetupNsList (
    146  1.1  jruoho     void                    *Handle);
    147  1.1  jruoho 
    148  1.1  jruoho 
    149  1.1  jruoho /* Local prototypes */
    150  1.1  jruoho 
    151  1.1  jruoho void
    152  1.1  jruoho AdCreateTableHeader (
    153  1.1  jruoho     char                    *Filename,
    154  1.1  jruoho     ACPI_TABLE_HEADER       *Table);
    155  1.1  jruoho 
    156  1.1  jruoho void
    157  1.1  jruoho AdDisassemblerHeader (
    158  1.1  jruoho     char                    *Filename);
    159  1.1  jruoho 
    160  1.1  jruoho ACPI_STATUS
    161  1.1  jruoho AdDeferredParse (
    162  1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
    163  1.1  jruoho     UINT8                   *Aml,
    164  1.1  jruoho     UINT32                  AmlLength);
    165  1.1  jruoho 
    166  1.1  jruoho ACPI_STATUS
    167  1.1  jruoho AdParseDeferredOps (
    168  1.1  jruoho     ACPI_PARSE_OBJECT       *Root);
    169  1.1  jruoho 
    170  1.1  jruoho 
    171  1.1  jruoho /* Stubs for ASL compiler */
    172  1.1  jruoho 
    173  1.1  jruoho #ifndef ACPI_ASL_COMPILER
    174  1.1  jruoho BOOLEAN
    175  1.1  jruoho AcpiDsIsResultUsed (
    176  1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
    177  1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    178  1.1  jruoho {
    179  1.1  jruoho     return TRUE;
    180  1.1  jruoho }
    181  1.1  jruoho 
    182  1.1  jruoho ACPI_STATUS
    183  1.1  jruoho AcpiDsMethodError (
    184  1.1  jruoho     ACPI_STATUS             Status,
    185  1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    186  1.1  jruoho {
    187  1.1  jruoho     return (Status);
    188  1.1  jruoho }
    189  1.1  jruoho #endif
    190  1.1  jruoho 
    191  1.1  jruoho ACPI_STATUS
    192  1.1  jruoho AcpiNsLoadTable (
    193  1.1  jruoho     UINT32                  TableIndex,
    194  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node)
    195  1.1  jruoho {
    196  1.1  jruoho     return (AE_NOT_IMPLEMENTED);
    197  1.1  jruoho }
    198  1.1  jruoho 
    199  1.1  jruoho ACPI_STATUS
    200  1.1  jruoho AcpiDsRestartControlMethod (
    201  1.1  jruoho     ACPI_WALK_STATE         *WalkState,
    202  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc)
    203  1.1  jruoho {
    204  1.1  jruoho     return (AE_OK);
    205  1.1  jruoho }
    206  1.1  jruoho 
    207  1.1  jruoho void
    208  1.1  jruoho AcpiDsTerminateControlMethod (
    209  1.1  jruoho     ACPI_OPERAND_OBJECT     *MethodDesc,
    210  1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    211  1.1  jruoho {
    212  1.1  jruoho     return;
    213  1.1  jruoho }
    214  1.1  jruoho 
    215  1.1  jruoho ACPI_STATUS
    216  1.1  jruoho AcpiDsCallControlMethod (
    217  1.1  jruoho     ACPI_THREAD_STATE       *Thread,
    218  1.1  jruoho     ACPI_WALK_STATE         *WalkState,
    219  1.1  jruoho     ACPI_PARSE_OBJECT       *Op)
    220  1.1  jruoho {
    221  1.1  jruoho     return (AE_OK);
    222  1.1  jruoho }
    223  1.1  jruoho 
    224  1.1  jruoho ACPI_STATUS
    225  1.1  jruoho AcpiDsMethodDataInitArgs (
    226  1.1  jruoho     ACPI_OPERAND_OBJECT     **Params,
    227  1.1  jruoho     UINT32                  MaxParamCount,
    228  1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    229  1.1  jruoho {
    230  1.1  jruoho     return (AE_OK);
    231  1.1  jruoho }
    232  1.1  jruoho 
    233  1.1  jruoho 
    234  1.1  jruoho static ACPI_TABLE_DESC      LocalTables[1];
    235  1.1  jruoho static ACPI_PARSE_OBJECT    *AcpiGbl_ParseOpRoot;
    236  1.1  jruoho 
    237  1.1  jruoho 
    238  1.1  jruoho /*******************************************************************************
    239  1.1  jruoho  *
    240  1.1  jruoho  * FUNCTION:    AdInitialize
    241  1.1  jruoho  *
    242  1.1  jruoho  * PARAMETERS:  None
    243  1.1  jruoho  *
    244  1.1  jruoho  * RETURN:      Status
    245  1.1  jruoho  *
    246  1.1  jruoho  * DESCRIPTION: ACPICA and local initialization
    247  1.1  jruoho  *
    248  1.1  jruoho  ******************************************************************************/
    249  1.1  jruoho 
    250  1.1  jruoho ACPI_STATUS
    251  1.1  jruoho AdInitialize (
    252  1.1  jruoho     void)
    253  1.1  jruoho {
    254  1.1  jruoho     ACPI_STATUS             Status;
    255  1.1  jruoho 
    256  1.1  jruoho 
    257  1.1  jruoho     /* ACPI CA subsystem initialization */
    258  1.1  jruoho 
    259  1.1  jruoho     Status = AcpiOsInitialize ();
    260  1.1  jruoho     if (ACPI_FAILURE (Status))
    261  1.1  jruoho     {
    262  1.1  jruoho         return (Status);
    263  1.1  jruoho     }
    264  1.1  jruoho 
    265  1.1  jruoho     Status = AcpiUtInitGlobals ();
    266  1.1  jruoho     if (ACPI_FAILURE (Status))
    267  1.1  jruoho     {
    268  1.1  jruoho         return (Status);
    269  1.1  jruoho     }
    270  1.1  jruoho 
    271  1.1  jruoho     Status = AcpiUtMutexInitialize ();
    272  1.1  jruoho     if (ACPI_FAILURE (Status))
    273  1.1  jruoho     {
    274  1.1  jruoho         return (Status);
    275  1.1  jruoho     }
    276  1.1  jruoho 
    277  1.1  jruoho     Status = AcpiNsRootInitialize ();
    278  1.1  jruoho     if (ACPI_FAILURE (Status))
    279  1.1  jruoho     {
    280  1.1  jruoho         return (Status);
    281  1.1  jruoho     }
    282  1.1  jruoho 
    283  1.1  jruoho     /* Setup the Table Manager (cheat - there is no RSDT) */
    284  1.1  jruoho 
    285  1.1  jruoho     AcpiGbl_RootTableList.MaxTableCount = 1;
    286  1.1  jruoho     AcpiGbl_RootTableList.CurrentTableCount = 0;
    287  1.1  jruoho     AcpiGbl_RootTableList.Tables = LocalTables;
    288  1.1  jruoho 
    289  1.1  jruoho     return (Status);
    290  1.1  jruoho }
    291  1.1  jruoho 
    292  1.1  jruoho 
    293  1.1  jruoho /******************************************************************************
    294  1.1  jruoho  *
    295  1.1  jruoho  * FUNCTION:    AdAmlDisassemble
    296  1.1  jruoho  *
    297  1.1  jruoho  * PARAMETERS:  Filename            - AML input filename
    298  1.1  jruoho  *              OutToFile           - TRUE if output should go to a file
    299  1.1  jruoho  *              Prefix              - Path prefix for output
    300  1.1  jruoho  *              OutFilename         - where the filename is returned
    301  1.1  jruoho  *              GetAllTables        - TRUE if all tables are desired
    302  1.1  jruoho  *
    303  1.1  jruoho  * RETURN:      Status
    304  1.1  jruoho  *
    305  1.1  jruoho  * DESCRIPTION: Disassemble an entire ACPI table
    306  1.1  jruoho  *
    307  1.1  jruoho  *****************************************************************************/
    308  1.1  jruoho 
    309  1.1  jruoho ACPI_STATUS
    310  1.1  jruoho AdAmlDisassemble (
    311  1.1  jruoho     BOOLEAN                 OutToFile,
    312  1.1  jruoho     char                    *Filename,
    313  1.1  jruoho     char                    *Prefix,
    314  1.1  jruoho     char                    **OutFilename,
    315  1.1  jruoho     BOOLEAN                 GetAllTables)
    316  1.1  jruoho {
    317  1.1  jruoho     ACPI_STATUS             Status;
    318  1.1  jruoho     char                    *DisasmFilename = NULL;
    319  1.1  jruoho     char                    *ExternalFilename;
    320  1.1  jruoho     FILE                    *File = NULL;
    321  1.1  jruoho     ACPI_TABLE_HEADER       *Table = NULL;
    322  1.1  jruoho     ACPI_TABLE_HEADER       *ExternalTable;
    323  1.1  jruoho     ACPI_OWNER_ID           OwnerId;
    324  1.1  jruoho 
    325  1.1  jruoho 
    326  1.1  jruoho     /*
    327  1.1  jruoho      * Input: AML code from either a file or via GetTables (memory or
    328  1.1  jruoho      * registry)
    329  1.1  jruoho      */
    330  1.1  jruoho     if (Filename)
    331  1.1  jruoho     {
    332  1.1  jruoho         Status = AcpiDbGetTableFromFile (Filename, &Table);
    333  1.1  jruoho         if (ACPI_FAILURE (Status))
    334  1.1  jruoho         {
    335  1.1  jruoho             return Status;
    336  1.1  jruoho         }
    337  1.1  jruoho 
    338  1.1  jruoho         /*
    339  1.1  jruoho          * External filenames separated by commas
    340  1.1  jruoho          * Example: iasl -e file1,file2,file3 -d xxx.aml
    341  1.1  jruoho          */
    342  1.1  jruoho         if (Gbl_ExternalFilename)
    343  1.1  jruoho         {
    344  1.1  jruoho             ExternalFilename = strtok (Gbl_ExternalFilename, ",");
    345  1.1  jruoho 
    346  1.1  jruoho             while (ExternalFilename)
    347  1.1  jruoho             {
    348  1.1  jruoho                 Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
    349  1.1  jruoho                 if (ACPI_FAILURE (Status))
    350  1.1  jruoho                 {
    351  1.1  jruoho                     return Status;
    352  1.1  jruoho                 }
    353  1.1  jruoho 
    354  1.1  jruoho                 /* Load external table for symbol resolution */
    355  1.1  jruoho 
    356  1.1  jruoho                 if (ExternalTable)
    357  1.1  jruoho                 {
    358  1.1  jruoho                     Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
    359  1.1  jruoho                     if (ACPI_FAILURE (Status))
    360  1.1  jruoho                     {
    361  1.1  jruoho                         AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
    362  1.1  jruoho                             AcpiFormatException (Status));
    363  1.1  jruoho                         return Status;
    364  1.1  jruoho                     }
    365  1.1  jruoho 
    366  1.1  jruoho                     /*
    367  1.1  jruoho                      * Load namespace from names created within control methods
    368  1.1  jruoho                      * Set owner id of nodes in external table
    369  1.1  jruoho                      */
    370  1.1  jruoho                     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    371  1.1  jruoho                         AcpiGbl_RootNode, OwnerId);
    372  1.1  jruoho                     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    373  1.1  jruoho                 }
    374  1.1  jruoho 
    375  1.1  jruoho                 /* Next external file name */
    376  1.1  jruoho 
    377  1.1  jruoho                 ExternalFilename = strtok (NULL, ",");
    378  1.1  jruoho             }
    379  1.1  jruoho 
    380  1.1  jruoho             /* Clear external list generated by Scope in external tables */
    381  1.1  jruoho 
    382  1.1  jruoho             AcpiDmClearExternalList ();
    383  1.1  jruoho         }
    384  1.1  jruoho     }
    385  1.1  jruoho     else
    386  1.1  jruoho     {
    387  1.1  jruoho         Status = AdGetLocalTables (Filename, GetAllTables);
    388  1.1  jruoho         if (ACPI_FAILURE (Status))
    389  1.1  jruoho         {
    390  1.1  jruoho             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
    391  1.1  jruoho                 AcpiFormatException (Status));
    392  1.1  jruoho             return Status;
    393  1.1  jruoho         }
    394  1.1  jruoho 
    395  1.1  jruoho         if (!AcpiGbl_DbOpt_disasm)
    396  1.1  jruoho         {
    397  1.1  jruoho             return AE_OK;
    398  1.1  jruoho         }
    399  1.1  jruoho 
    400  1.1  jruoho         /* Obtained the local tables, just disassemble the DSDT */
    401  1.1  jruoho 
    402  1.1  jruoho         Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
    403  1.1  jruoho         if (ACPI_FAILURE (Status))
    404  1.1  jruoho         {
    405  1.1  jruoho             AcpiOsPrintf ("Could not get DSDT, %s\n",
    406  1.1  jruoho                 AcpiFormatException (Status));
    407  1.1  jruoho             return Status;
    408  1.1  jruoho         }
    409  1.1  jruoho 
    410  1.1  jruoho         AcpiOsPrintf ("\nDisassembly of DSDT\n");
    411  1.1  jruoho         Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
    412  1.1  jruoho     }
    413  1.1  jruoho 
    414  1.1  jruoho     /*
    415  1.1  jruoho      * Output:  ASL code. Redirect to a file if requested
    416  1.1  jruoho      */
    417  1.1  jruoho     if (OutToFile)
    418  1.1  jruoho     {
    419  1.1  jruoho         /* Create/Open a disassembly output file */
    420  1.1  jruoho 
    421  1.1  jruoho         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
    422  1.1  jruoho         if (!OutFilename)
    423  1.1  jruoho         {
    424  1.1  jruoho             fprintf (stderr, "Could not generate output filename\n");
    425  1.1  jruoho             Status = AE_ERROR;
    426  1.1  jruoho             goto Cleanup;
    427  1.1  jruoho         }
    428  1.1  jruoho 
    429  1.1  jruoho         File = fopen (DisasmFilename, "w+");
    430  1.1  jruoho         if (!File)
    431  1.1  jruoho         {
    432  1.1  jruoho             fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
    433  1.1  jruoho             Status = AE_ERROR;
    434  1.1  jruoho             goto Cleanup;
    435  1.1  jruoho         }
    436  1.1  jruoho 
    437  1.1  jruoho         AcpiOsRedirectOutput (File);
    438  1.1  jruoho     }
    439  1.1  jruoho 
    440  1.1  jruoho     *OutFilename = DisasmFilename;
    441  1.1  jruoho 
    442  1.1  jruoho     if (!AcpiUtIsAmlTable (Table))
    443  1.1  jruoho     {
    444  1.1  jruoho         AdDisassemblerHeader (Filename);
    445  1.1  jruoho         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
    446  1.1  jruoho             Table->Signature);
    447  1.1  jruoho         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  FieldName : FieldValue\n */\n\n");
    448  1.1  jruoho 
    449  1.1  jruoho         AcpiDmDumpDataTable (Table);
    450  1.1  jruoho         fprintf (stderr, "Acpi Data Table [%4.4s] decoded, written to \"%s\"\n",
    451  1.1  jruoho             Table->Signature, DisasmFilename);
    452  1.1  jruoho     }
    453  1.1  jruoho     else
    454  1.1  jruoho     {
    455  1.1  jruoho         /* Always parse the tables, only option is what to display */
    456  1.1  jruoho 
    457  1.1  jruoho         Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
    458  1.1  jruoho         if (ACPI_FAILURE (Status))
    459  1.1  jruoho         {
    460  1.1  jruoho             AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    461  1.1  jruoho                 AcpiFormatException (Status));
    462  1.1  jruoho             goto Cleanup;
    463  1.1  jruoho         }
    464  1.1  jruoho 
    465  1.1  jruoho         if (AslCompilerdebug)
    466  1.1  jruoho         {
    467  1.1  jruoho             AcpiOsPrintf ("/**** Before second load\n");
    468  1.1  jruoho 
    469  1.1  jruoho             LsSetupNsList (File);
    470  1.1  jruoho             LsDisplayNamespace ();
    471  1.1  jruoho             AcpiOsPrintf ("*****/\n");
    472  1.1  jruoho         }
    473  1.1  jruoho 
    474  1.1  jruoho         /*
    475  1.1  jruoho          * Load namespace from names created within control methods
    476  1.1  jruoho          */
    477  1.1  jruoho         AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
    478  1.1  jruoho 
    479  1.1  jruoho         /*
    480  1.1  jruoho          * Cross reference the namespace here, in order to generate External() statements
    481  1.1  jruoho          */
    482  1.1  jruoho         AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
    483  1.1  jruoho 
    484  1.1  jruoho         if (AslCompilerdebug)
    485  1.1  jruoho         {
    486  1.1  jruoho             AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    487  1.1  jruoho         }
    488  1.1  jruoho 
    489  1.1  jruoho         /* Find possible calls to external control methods */
    490  1.1  jruoho 
    491  1.1  jruoho         AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
    492  1.1  jruoho 
    493  1.1  jruoho         /* Convert fixed-offset references to resource descriptors to symbolic references */
    494  1.1  jruoho 
    495  1.1  jruoho         AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
    496  1.1  jruoho 
    497  1.1  jruoho         /*
    498  1.1  jruoho          * If we found any external control methods, we must reparse the entire
    499  1.1  jruoho          * tree with the new information (namely, the number of arguments per
    500  1.1  jruoho          * method)
    501  1.1  jruoho          */
    502  1.1  jruoho         if (AcpiDmGetExternalMethodCount ())
    503  1.1  jruoho         {
    504  1.1  jruoho             fprintf (stderr,
    505  1.1  jruoho                 "\nFound %u external control methods, reparsing with new information\n",
    506  1.1  jruoho                 AcpiDmGetExternalMethodCount ());
    507  1.1  jruoho 
    508  1.1  jruoho             /*
    509  1.1  jruoho              * Reparse, rebuild namespace. no need to xref namespace
    510  1.1  jruoho              */
    511  1.1  jruoho             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    512  1.1  jruoho             AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
    513  1.1  jruoho 
    514  1.1  jruoho             AcpiGbl_RootNode                    = NULL;
    515  1.1  jruoho             AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
    516  1.1  jruoho             AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
    517  1.1  jruoho             AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
    518  1.1  jruoho             AcpiGbl_RootNodeStruct.Parent       = NULL;
    519  1.1  jruoho             AcpiGbl_RootNodeStruct.Child        = NULL;
    520  1.1  jruoho             AcpiGbl_RootNodeStruct.Peer         = NULL;
    521  1.1  jruoho             AcpiGbl_RootNodeStruct.Object       = NULL;
    522  1.1  jruoho             AcpiGbl_RootNodeStruct.Flags        = 0;
    523  1.1  jruoho 
    524  1.1  jruoho             Status = AcpiNsRootInitialize ();
    525  1.1  jruoho             AcpiDmAddExternalsToNamespace ();
    526  1.1  jruoho 
    527  1.1  jruoho             /* Parse table. No need to reload it, however (FALSE) */
    528  1.1  jruoho 
    529  1.1  jruoho             Status = AdParseTable (Table, NULL, FALSE, FALSE);
    530  1.1  jruoho             if (ACPI_FAILURE (Status))
    531  1.1  jruoho             {
    532  1.1  jruoho                 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    533  1.1  jruoho                     AcpiFormatException (Status));
    534  1.1  jruoho                 goto Cleanup;
    535  1.1  jruoho             }
    536  1.1  jruoho 
    537  1.1  jruoho             if (AslCompilerdebug)
    538  1.1  jruoho             {
    539  1.1  jruoho                 AcpiOsPrintf ("/**** After second load and resource conversion\n");
    540  1.1  jruoho                 LsSetupNsList (File);
    541  1.1  jruoho                 LsDisplayNamespace ();
    542  1.1  jruoho                 AcpiOsPrintf ("*****/\n");
    543  1.1  jruoho 
    544  1.1  jruoho                 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    545  1.1  jruoho             }
    546  1.1  jruoho         }
    547  1.1  jruoho 
    548  1.1  jruoho         /* Optional displays */
    549  1.1  jruoho 
    550  1.1  jruoho         if (AcpiGbl_DbOpt_disasm)
    551  1.1  jruoho         {
    552  1.1  jruoho             AdDisplayTables (Filename, Table);
    553  1.1  jruoho             fprintf (stderr,
    554  1.1  jruoho                 "Disassembly completed, written to \"%s\"\n",
    555  1.1  jruoho                 DisasmFilename);
    556  1.1  jruoho         }
    557  1.1  jruoho     }
    558  1.1  jruoho 
    559  1.1  jruoho Cleanup:
    560  1.1  jruoho 
    561  1.1  jruoho     if (Table && !AcpiUtIsAmlTable (Table))
    562  1.1  jruoho     {
    563  1.1  jruoho         ACPI_FREE (Table);
    564  1.1  jruoho     }
    565  1.1  jruoho 
    566  1.1  jruoho     if (DisasmFilename)
    567  1.1  jruoho     {
    568  1.1  jruoho         ACPI_FREE (DisasmFilename);
    569  1.1  jruoho     }
    570  1.1  jruoho 
    571  1.1  jruoho     if (OutToFile && File)
    572  1.1  jruoho     {
    573  1.1  jruoho 
    574  1.1  jruoho #ifdef ASL_DISASM_DEBUG
    575  1.1  jruoho         LsSetupNsList (File);
    576  1.1  jruoho         LsDisplayNamespace ();
    577  1.1  jruoho #endif
    578  1.1  jruoho         fclose (File);
    579  1.1  jruoho         AcpiOsRedirectOutput (stdout);
    580  1.1  jruoho     }
    581  1.1  jruoho 
    582  1.1  jruoho     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    583  1.1  jruoho     AcpiGbl_ParseOpRoot = NULL;
    584  1.1  jruoho     return (Status);
    585  1.1  jruoho }
    586  1.1  jruoho 
    587  1.1  jruoho 
    588  1.1  jruoho /******************************************************************************
    589  1.1  jruoho  *
    590  1.1  jruoho  * FUNCTION:    AdDisassemblerHeader
    591  1.1  jruoho  *
    592  1.1  jruoho  * PARAMETERS:  Filename            - Input file for the table
    593  1.1  jruoho  *
    594  1.1  jruoho  * RETURN:      None
    595  1.1  jruoho  *
    596  1.1  jruoho  * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
    597  1.1  jruoho  *              current time and date.
    598  1.1  jruoho  *
    599  1.1  jruoho  *****************************************************************************/
    600  1.1  jruoho 
    601  1.1  jruoho void
    602  1.1  jruoho AdDisassemblerHeader (
    603  1.1  jruoho     char                    *Filename)
    604  1.1  jruoho {
    605  1.1  jruoho     time_t                  Timer;
    606  1.1  jruoho 
    607  1.1  jruoho     time (&Timer);
    608  1.1  jruoho 
    609  1.1  jruoho     /* Header and input table info */
    610  1.1  jruoho 
    611  1.1  jruoho     AcpiOsPrintf ("/*\n * Intel ACPI Component Architecture\n");
    612  1.1  jruoho     AcpiOsPrintf (" * AML Disassembler version %8.8X\n", ACPI_CA_VERSION);
    613  1.1  jruoho 
    614  1.1  jruoho     AcpiOsPrintf (" *\n * Disassembly of %s, %s", Filename, ctime (&Timer));
    615  1.1  jruoho     AcpiOsPrintf (" *\n");
    616  1.1  jruoho }
    617  1.1  jruoho 
    618  1.1  jruoho 
    619  1.1  jruoho /******************************************************************************
    620  1.1  jruoho  *
    621  1.1  jruoho  * FUNCTION:    AdCreateTableHeader
    622  1.1  jruoho  *
    623  1.1  jruoho  * PARAMETERS:  Filename            - Input file for the table
    624  1.1  jruoho  *              Table               - Pointer to the raw table
    625  1.1  jruoho  *
    626  1.1  jruoho  * RETURN:      None
    627  1.1  jruoho  *
    628  1.1  jruoho  * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
    629  1.1  jruoho  *              current time and date.
    630  1.1  jruoho  *
    631  1.1  jruoho  *****************************************************************************/
    632  1.1  jruoho 
    633  1.1  jruoho void
    634  1.1  jruoho AdCreateTableHeader (
    635  1.1  jruoho     char                    *Filename,
    636  1.1  jruoho     ACPI_TABLE_HEADER       *Table)
    637  1.1  jruoho {
    638  1.1  jruoho     char                    *NewFilename;
    639  1.1  jruoho     UINT8                   Checksum;
    640  1.1  jruoho 
    641  1.1  jruoho 
    642  1.1  jruoho     /*
    643  1.1  jruoho      * Print file header and dump original table header
    644  1.1  jruoho      */
    645  1.1  jruoho     AdDisassemblerHeader (Filename);
    646  1.1  jruoho 
    647  1.1  jruoho     AcpiOsPrintf (" *\n * Original Table Header:\n");
    648  1.1  jruoho     AcpiOsPrintf (" *     Signature        \"%4.4s\"\n",    Table->Signature);
    649  1.1  jruoho     AcpiOsPrintf (" *     Length           0x%8.8X (%u)\n", Table->Length, Table->Length);
    650  1.1  jruoho 
    651  1.1  jruoho     /* Print and validate the revision */
    652  1.1  jruoho 
    653  1.1  jruoho     AcpiOsPrintf (" *     Revision         0x%2.2X",      Table->Revision);
    654  1.1  jruoho 
    655  1.1  jruoho     switch (Table->Revision)
    656  1.1  jruoho     {
    657  1.1  jruoho     case 0:
    658  1.1  jruoho         AcpiOsPrintf (" **** Invalid Revision");
    659  1.1  jruoho         break;
    660  1.1  jruoho 
    661  1.1  jruoho     case 1:
    662  1.1  jruoho         /* Revision of DSDT controls the ACPI integer width */
    663  1.1  jruoho 
    664  1.1  jruoho         if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
    665  1.1  jruoho         {
    666  1.1  jruoho             AcpiOsPrintf (" **** ACPI 1.0, no 64-bit math support");
    667  1.1  jruoho         }
    668  1.1  jruoho         break;
    669  1.1  jruoho 
    670  1.1  jruoho     default:
    671  1.1  jruoho         break;
    672  1.1  jruoho     }
    673  1.1  jruoho     AcpiOsPrintf ("\n");
    674  1.1  jruoho 
    675  1.1  jruoho     /* Print and validate the table checksum */
    676  1.1  jruoho 
    677  1.1  jruoho     AcpiOsPrintf (" *     Checksum         0x%2.2X",        Table->Checksum);
    678  1.1  jruoho 
    679  1.1  jruoho     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
    680  1.1  jruoho     if (Checksum)
    681  1.1  jruoho     {
    682  1.1  jruoho         AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
    683  1.1  jruoho             (UINT8) (Table->Checksum - Checksum));
    684  1.1  jruoho     }
    685  1.1  jruoho     AcpiOsPrintf ("\n");
    686  1.1  jruoho 
    687  1.1  jruoho     AcpiOsPrintf (" *     OEM ID           \"%.6s\"\n",     Table->OemId);
    688  1.1  jruoho     AcpiOsPrintf (" *     OEM Table ID     \"%.8s\"\n",     Table->OemTableId);
    689  1.1  jruoho     AcpiOsPrintf (" *     OEM Revision     0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
    690  1.1  jruoho     AcpiOsPrintf (" *     Compiler ID      \"%.4s\"\n",     Table->AslCompilerId);
    691  1.1  jruoho     AcpiOsPrintf (" *     Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
    692  1.1  jruoho     AcpiOsPrintf (" */\n");
    693  1.1  jruoho 
    694  1.1  jruoho     /* Create AML output filename based on input filename */
    695  1.1  jruoho 
    696  1.1  jruoho     if (Filename)
    697  1.1  jruoho     {
    698  1.1  jruoho         NewFilename = FlGenerateFilename (Filename, "aml");
    699  1.1  jruoho     }
    700  1.1  jruoho     else
    701  1.1  jruoho     {
    702  1.1  jruoho         NewFilename = ACPI_ALLOCATE_ZEROED (9);
    703  1.1  jruoho         strncat (NewFilename, Table->Signature, 4);
    704  1.1  jruoho         strcat (NewFilename, ".aml");
    705  1.1  jruoho     }
    706  1.1  jruoho 
    707  1.1  jruoho     /* Open the ASL definition block */
    708  1.1  jruoho 
    709  1.1  jruoho     AcpiOsPrintf (
    710  1.1  jruoho         "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
    711  1.1  jruoho         NewFilename, Table->Signature, Table->Revision,
    712  1.1  jruoho         Table->OemId, Table->OemTableId, Table->OemRevision);
    713  1.1  jruoho 
    714  1.1  jruoho     ACPI_FREE (NewFilename);
    715  1.1  jruoho }
    716  1.1  jruoho 
    717  1.1  jruoho 
    718  1.1  jruoho /******************************************************************************
    719  1.1  jruoho  *
    720  1.1  jruoho  * FUNCTION:    AdDisplayTables
    721  1.1  jruoho  *
    722  1.1  jruoho  * PARAMETERS:  Filename            - Input file for the table
    723  1.1  jruoho  *              Table               - Pointer to the raw table
    724  1.1  jruoho  *
    725  1.1  jruoho  * RETURN:      Status
    726  1.1  jruoho  *
    727  1.1  jruoho  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
    728  1.1  jruoho  *
    729  1.1  jruoho  *****************************************************************************/
    730  1.1  jruoho 
    731  1.1  jruoho ACPI_STATUS
    732  1.1  jruoho AdDisplayTables (
    733  1.1  jruoho     char                    *Filename,
    734  1.1  jruoho     ACPI_TABLE_HEADER       *Table)
    735  1.1  jruoho {
    736  1.1  jruoho 
    737  1.1  jruoho 
    738  1.1  jruoho     if (!AcpiGbl_ParseOpRoot)
    739  1.1  jruoho     {
    740  1.1  jruoho         return AE_NOT_EXIST;
    741  1.1  jruoho     }
    742  1.1  jruoho 
    743  1.1  jruoho     if (!AcpiGbl_DbOpt_verbose)
    744  1.1  jruoho     {
    745  1.1  jruoho         AdCreateTableHeader (Filename, Table);
    746  1.1  jruoho     }
    747  1.1  jruoho 
    748  1.1  jruoho     AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
    749  1.1  jruoho 
    750  1.1  jruoho     if (AcpiGbl_DbOpt_verbose)
    751  1.1  jruoho     {
    752  1.1  jruoho         AcpiOsPrintf ("\n\nTable Header:\n");
    753  1.1  jruoho         AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
    754  1.1  jruoho             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
    755  1.1  jruoho 
    756  1.1  jruoho         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
    757  1.1  jruoho         AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
    758  1.1  jruoho             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
    759  1.1  jruoho     }
    760  1.1  jruoho 
    761  1.1  jruoho     return AE_OK;
    762  1.1  jruoho }
    763  1.1  jruoho 
    764  1.1  jruoho 
    765  1.1  jruoho /******************************************************************************
    766  1.1  jruoho  *
    767  1.1  jruoho  * FUNCTION:    AdDeferredParse
    768  1.1  jruoho  *
    769  1.1  jruoho  * PARAMETERS:  Op                  - Root Op of the deferred opcode
    770  1.1  jruoho  *              Aml                 - Pointer to the raw AML
    771  1.1  jruoho  *              AmlLength           - Length of the AML
    772  1.1  jruoho  *
    773  1.1  jruoho  * RETURN:      Status
    774  1.1  jruoho  *
    775  1.1  jruoho  * DESCRIPTION: Parse one deferred opcode
    776  1.1  jruoho  *              (Methods, operation regions, etc.)
    777  1.1  jruoho  *
    778  1.1  jruoho  *****************************************************************************/
    779  1.1  jruoho 
    780  1.1  jruoho ACPI_STATUS
    781  1.1  jruoho AdDeferredParse (
    782  1.1  jruoho     ACPI_PARSE_OBJECT       *Op,
    783  1.1  jruoho     UINT8                   *Aml,
    784  1.1  jruoho     UINT32                  AmlLength)
    785  1.1  jruoho {
    786  1.1  jruoho     ACPI_WALK_STATE         *WalkState;
    787  1.1  jruoho     ACPI_STATUS             Status;
    788  1.1  jruoho     ACPI_PARSE_OBJECT       *SearchOp;
    789  1.1  jruoho     ACPI_PARSE_OBJECT       *StartOp;
    790  1.1  jruoho     UINT32                  BaseAmlOffset;
    791  1.1  jruoho     ACPI_PARSE_OBJECT       *ExtraOp;
    792  1.1  jruoho 
    793  1.1  jruoho 
    794  1.1  jruoho     ACPI_FUNCTION_TRACE (AdDeferredParse);
    795  1.1  jruoho 
    796  1.1  jruoho 
    797  1.1  jruoho     fprintf (stderr, ".");
    798  1.1  jruoho 
    799  1.1  jruoho     if (!Aml || !AmlLength)
    800  1.1  jruoho     {
    801  1.1  jruoho         return_ACPI_STATUS (AE_OK);
    802  1.1  jruoho     }
    803  1.1  jruoho 
    804  1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
    805  1.1  jruoho         Op->Common.AmlOpName, (char *) &Op->Named.Name));
    806  1.1  jruoho 
    807  1.1  jruoho     WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
    808  1.1  jruoho     if (!WalkState)
    809  1.1  jruoho     {
    810  1.1  jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    811  1.1  jruoho     }
    812  1.1  jruoho 
    813  1.1  jruoho     Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
    814  1.1  jruoho                     AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
    815  1.1  jruoho     if (ACPI_FAILURE (Status))
    816  1.1  jruoho     {
    817  1.1  jruoho         return_ACPI_STATUS (Status);
    818  1.1  jruoho     }
    819  1.1  jruoho 
    820  1.1  jruoho     /* Parse the method */
    821  1.1  jruoho 
    822  1.1  jruoho     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
    823  1.1  jruoho     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
    824  1.1  jruoho     Status = AcpiPsParseAml (WalkState);
    825  1.1  jruoho 
    826  1.1  jruoho     /*
    827  1.1  jruoho      * We need to update all of the Aml offsets, since the parser thought
    828  1.1  jruoho      * that the method began at offset zero.  In reality, it began somewhere
    829  1.1  jruoho      * within the ACPI table, at the BaseAmlOffset.  Walk the entire tree that
    830  1.1  jruoho      * was just created and update the AmlOffset in each Op
    831  1.1  jruoho      */
    832  1.1  jruoho     BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
    833  1.1  jruoho     StartOp = (Op->Common.Value.Arg)->Common.Next;
    834  1.1  jruoho     SearchOp = StartOp;
    835  1.1  jruoho 
    836  1.1  jruoho     /* Walk the parse tree */
    837  1.1  jruoho 
    838  1.1  jruoho     while (SearchOp)
    839  1.1  jruoho     {
    840  1.1  jruoho         SearchOp->Common.AmlOffset += BaseAmlOffset;
    841  1.1  jruoho         SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
    842  1.1  jruoho     }
    843  1.1  jruoho 
    844  1.1  jruoho     /*
    845  1.1  jruoho      * Link the newly parsed subtree into the main parse tree
    846  1.1  jruoho      */
    847  1.1  jruoho     switch (Op->Common.AmlOpcode)
    848  1.1  jruoho     {
    849  1.1  jruoho     case AML_BUFFER_OP:
    850  1.1  jruoho     case AML_PACKAGE_OP:
    851  1.1  jruoho     case AML_VAR_PACKAGE_OP:
    852  1.1  jruoho 
    853  1.1  jruoho         switch (Op->Common.AmlOpcode)
    854  1.1  jruoho         {
    855  1.1  jruoho         case AML_PACKAGE_OP:
    856  1.1  jruoho             ExtraOp = Op->Common.Value.Arg;
    857  1.1  jruoho             ExtraOp = ExtraOp->Common.Next;
    858  1.1  jruoho             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
    859  1.1  jruoho             break;
    860  1.1  jruoho 
    861  1.1  jruoho         case AML_VAR_PACKAGE_OP:
    862  1.1  jruoho         case AML_BUFFER_OP:
    863  1.1  jruoho         default:
    864  1.1  jruoho             ExtraOp = Op->Common.Value.Arg;
    865  1.1  jruoho             Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
    866  1.1  jruoho             break;
    867  1.1  jruoho         }
    868  1.1  jruoho 
    869  1.1  jruoho         /* Must point all parents to the main tree */
    870  1.1  jruoho 
    871  1.1  jruoho         StartOp = Op;
    872  1.1  jruoho         SearchOp = StartOp;
    873  1.1  jruoho         while (SearchOp)
    874  1.1  jruoho         {
    875  1.1  jruoho             if (SearchOp->Common.Parent == ExtraOp)
    876  1.1  jruoho             {
    877  1.1  jruoho                 SearchOp->Common.Parent = Op;
    878  1.1  jruoho             }
    879  1.1  jruoho             SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
    880  1.1  jruoho         }
    881  1.1  jruoho         break;
    882  1.1  jruoho 
    883  1.1  jruoho     default:
    884  1.1  jruoho         break;
    885  1.1  jruoho     }
    886  1.1  jruoho 
    887  1.1  jruoho     return_ACPI_STATUS (AE_OK);
    888  1.1  jruoho }
    889  1.1  jruoho 
    890  1.1  jruoho 
    891  1.1  jruoho /******************************************************************************
    892  1.1  jruoho  *
    893  1.1  jruoho  * FUNCTION:    AdParseDeferredOps
    894  1.1  jruoho  *
    895  1.1  jruoho  * PARAMETERS:  Root                - Root of the parse tree
    896  1.1  jruoho  *
    897  1.1  jruoho  * RETURN:      Status
    898  1.1  jruoho  *
    899  1.1  jruoho  * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
    900  1.1  jruoho  *
    901  1.1  jruoho  *****************************************************************************/
    902  1.1  jruoho 
    903  1.1  jruoho ACPI_STATUS
    904  1.1  jruoho AdParseDeferredOps (
    905  1.1  jruoho     ACPI_PARSE_OBJECT       *Root)
    906  1.1  jruoho {
    907  1.1  jruoho     ACPI_PARSE_OBJECT       *Op = Root;
    908  1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    909  1.1  jruoho     const ACPI_OPCODE_INFO  *OpInfo;
    910  1.1  jruoho 
    911  1.1  jruoho 
    912  1.1  jruoho     ACPI_FUNCTION_NAME (AdParseDeferredOps);
    913  1.1  jruoho     fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
    914  1.1  jruoho 
    915  1.1  jruoho     while (Op)
    916  1.1  jruoho     {
    917  1.1  jruoho         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
    918  1.1  jruoho         if (!(OpInfo->Flags & AML_DEFER))
    919  1.1  jruoho         {
    920  1.1  jruoho             Op = AcpiPsGetDepthNext (Root, Op);
    921  1.1  jruoho             continue;
    922  1.1  jruoho         }
    923  1.1  jruoho 
    924  1.1  jruoho         switch (Op->Common.AmlOpcode)
    925  1.1  jruoho         {
    926  1.1  jruoho         case AML_METHOD_OP:
    927  1.1  jruoho         case AML_BUFFER_OP:
    928  1.1  jruoho         case AML_PACKAGE_OP:
    929  1.1  jruoho         case AML_VAR_PACKAGE_OP:
    930  1.1  jruoho 
    931  1.1  jruoho             Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
    932  1.1  jruoho             if (ACPI_FAILURE (Status))
    933  1.1  jruoho             {
    934  1.1  jruoho                 return_ACPI_STATUS (Status);
    935  1.1  jruoho             }
    936  1.1  jruoho             break;
    937  1.1  jruoho 
    938  1.1  jruoho         case AML_REGION_OP:
    939  1.1  jruoho         case AML_CREATE_QWORD_FIELD_OP:
    940  1.1  jruoho         case AML_CREATE_DWORD_FIELD_OP:
    941  1.1  jruoho         case AML_CREATE_WORD_FIELD_OP:
    942  1.1  jruoho         case AML_CREATE_BYTE_FIELD_OP:
    943  1.1  jruoho         case AML_CREATE_BIT_FIELD_OP:
    944  1.1  jruoho         case AML_CREATE_FIELD_OP:
    945  1.1  jruoho         case AML_BANK_FIELD_OP:
    946  1.1  jruoho 
    947  1.1  jruoho             /* Nothing to do in these cases */
    948  1.1  jruoho 
    949  1.1  jruoho             break;
    950  1.1  jruoho 
    951  1.1  jruoho         default:
    952  1.1  jruoho             ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
    953  1.1  jruoho                 Op->Common.AmlOpName));
    954  1.1  jruoho             break;
    955  1.1  jruoho         }
    956  1.1  jruoho 
    957  1.1  jruoho         Op = AcpiPsGetDepthNext (Root, Op);
    958  1.1  jruoho     }
    959  1.1  jruoho 
    960  1.1  jruoho     fprintf (stderr, "\n");
    961  1.1  jruoho     return Status;
    962  1.1  jruoho }
    963  1.1  jruoho 
    964  1.1  jruoho 
    965  1.1  jruoho /******************************************************************************
    966  1.1  jruoho  *
    967  1.1  jruoho  * FUNCTION:    AdGetLocalTables
    968  1.1  jruoho  *
    969  1.1  jruoho  * PARAMETERS:  Filename            - Not used
    970  1.1  jruoho  *              GetAllTables        - TRUE if all tables are desired
    971  1.1  jruoho  *
    972  1.1  jruoho  * RETURN:      Status
    973  1.1  jruoho  *
    974  1.1  jruoho  * DESCRIPTION: Get the ACPI tables from either memory or a file
    975  1.1  jruoho  *
    976  1.1  jruoho  *****************************************************************************/
    977  1.1  jruoho 
    978  1.1  jruoho ACPI_STATUS
    979  1.1  jruoho AdGetLocalTables (
    980  1.1  jruoho     char                    *Filename,
    981  1.1  jruoho     BOOLEAN                 GetAllTables)
    982  1.1  jruoho {
    983  1.1  jruoho     ACPI_STATUS             Status;
    984  1.1  jruoho     ACPI_TABLE_HEADER       TableHeader;
    985  1.1  jruoho     ACPI_TABLE_HEADER       *NewTable;
    986  1.1  jruoho     UINT32                  NumTables;
    987  1.1  jruoho     UINT32                  PointerSize;
    988  1.1  jruoho     UINT32                  TableIndex;
    989  1.1  jruoho 
    990  1.1  jruoho 
    991  1.1  jruoho     if (GetAllTables)
    992  1.1  jruoho     {
    993  1.1  jruoho         ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
    994  1.1  jruoho         AcpiOsTableOverride (&TableHeader, &NewTable);
    995  1.1  jruoho         if (!NewTable)
    996  1.1  jruoho         {
    997  1.1  jruoho             fprintf (stderr, "Could not obtain RSDT\n");
    998  1.1  jruoho             return AE_NO_ACPI_TABLES;
    999  1.1  jruoho         }
   1000  1.1  jruoho         else
   1001  1.1  jruoho         {
   1002  1.1  jruoho             AdWriteTable (NewTable, NewTable->Length,
   1003  1.1  jruoho                 ACPI_SIG_RSDT, NewTable->OemTableId);
   1004  1.1  jruoho         }
   1005  1.1  jruoho 
   1006  1.1  jruoho         if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
   1007  1.1  jruoho         {
   1008  1.1  jruoho             PointerSize = sizeof (UINT32);
   1009  1.1  jruoho         }
   1010  1.1  jruoho         else
   1011  1.1  jruoho         {
   1012  1.1  jruoho             PointerSize = sizeof (UINT64);
   1013  1.1  jruoho         }
   1014  1.1  jruoho 
   1015  1.1  jruoho         /*
   1016  1.1  jruoho          * Determine the number of tables pointed to by the RSDT/XSDT.
   1017  1.1  jruoho          * This is defined by the ACPI Specification to be the number of
   1018  1.1  jruoho          * pointers contained within the RSDT/XSDT.  The size of the pointers
   1019  1.1  jruoho          * is architecture-dependent.
   1020  1.1  jruoho          */
   1021  1.1  jruoho         NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
   1022  1.1  jruoho         AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n",
   1023  1.1  jruoho             NumTables, NewTable->Signature);
   1024  1.1  jruoho 
   1025  1.1  jruoho         /* Get the FADT */
   1026  1.1  jruoho 
   1027  1.1  jruoho         ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
   1028  1.1  jruoho         AcpiOsTableOverride (&TableHeader, &NewTable);
   1029  1.1  jruoho         if (NewTable)
   1030  1.1  jruoho         {
   1031  1.1  jruoho             AdWriteTable (NewTable, NewTable->Length,
   1032  1.1  jruoho                 ACPI_SIG_FADT, NewTable->OemTableId);
   1033  1.1  jruoho         }
   1034  1.1  jruoho         AcpiOsPrintf ("\n");
   1035  1.1  jruoho 
   1036  1.1  jruoho         /* Don't bother with FACS, it is usually all zeros */
   1037  1.1  jruoho     }
   1038  1.1  jruoho 
   1039  1.1  jruoho     /* Always get the DSDT */
   1040  1.1  jruoho 
   1041  1.1  jruoho     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
   1042  1.1  jruoho     AcpiOsTableOverride (&TableHeader, &NewTable);
   1043  1.1  jruoho     if (NewTable)
   1044  1.1  jruoho     {
   1045  1.1  jruoho         AdWriteTable (NewTable, NewTable->Length,
   1046  1.1  jruoho             ACPI_SIG_DSDT, NewTable->OemTableId);
   1047  1.1  jruoho 
   1048  1.1  jruoho         /* Store DSDT in the Table Manager */
   1049  1.1  jruoho 
   1050  1.1  jruoho         Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
   1051  1.1  jruoho                     0, &TableIndex);
   1052  1.1  jruoho         if (ACPI_FAILURE (Status))
   1053  1.1  jruoho         {
   1054  1.1  jruoho             fprintf (stderr, "Could not store DSDT\n");
   1055  1.1  jruoho             return AE_NO_ACPI_TABLES;
   1056  1.1  jruoho         }
   1057  1.1  jruoho     }
   1058  1.1  jruoho     else
   1059  1.1  jruoho     {
   1060  1.1  jruoho         fprintf (stderr, "Could not obtain DSDT\n");
   1061  1.1  jruoho         return AE_NO_ACPI_TABLES;
   1062  1.1  jruoho     }
   1063  1.1  jruoho 
   1064  1.1  jruoho #if 0
   1065  1.1  jruoho     /* TBD: Future implementation */
   1066  1.1  jruoho 
   1067  1.1  jruoho     AcpiOsPrintf ("\n");
   1068  1.1  jruoho 
   1069  1.1  jruoho     /* Get all SSDTs */
   1070  1.1  jruoho 
   1071  1.1  jruoho     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
   1072  1.1  jruoho     do
   1073  1.1  jruoho     {
   1074  1.1  jruoho         NewTable = NULL;
   1075  1.1  jruoho         Status = AcpiOsTableOverride (&TableHeader, &NewTable);
   1076  1.1  jruoho 
   1077  1.1  jruoho     } while (NewTable);
   1078  1.1  jruoho #endif
   1079  1.1  jruoho 
   1080  1.1  jruoho     return AE_OK;
   1081  1.1  jruoho }
   1082  1.1  jruoho 
   1083  1.1  jruoho 
   1084  1.1  jruoho /******************************************************************************
   1085  1.1  jruoho  *
   1086  1.1  jruoho  * FUNCTION:    AdParseTable
   1087  1.1  jruoho  *
   1088  1.1  jruoho  * PARAMETERS:  Table               - Pointer to the raw table
   1089  1.1  jruoho  *              OwnerId             - Returned OwnerId of the table
   1090  1.1  jruoho  *              LoadTable           - If add table to the global table list
   1091  1.1  jruoho  *              External            - If this is an external table
   1092  1.1  jruoho  *
   1093  1.1  jruoho  * RETURN:      Status
   1094  1.1  jruoho  *
   1095  1.1  jruoho  * DESCRIPTION: Parse the DSDT.
   1096  1.1  jruoho  *
   1097  1.1  jruoho  *****************************************************************************/
   1098  1.1  jruoho 
   1099  1.1  jruoho ACPI_STATUS
   1100  1.1  jruoho AdParseTable (
   1101  1.1  jruoho     ACPI_TABLE_HEADER       *Table,
   1102  1.1  jruoho     ACPI_OWNER_ID           *OwnerId,
   1103  1.1  jruoho     BOOLEAN                 LoadTable,
   1104  1.1  jruoho     BOOLEAN                 External)
   1105  1.1  jruoho {
   1106  1.1  jruoho     ACPI_STATUS             Status = AE_OK;
   1107  1.1  jruoho     ACPI_WALK_STATE         *WalkState;
   1108  1.1  jruoho     UINT8                   *AmlStart;
   1109  1.1  jruoho     UINT32                  AmlLength;
   1110  1.1  jruoho     UINT32                  TableIndex;
   1111  1.1  jruoho 
   1112  1.1  jruoho 
   1113  1.1  jruoho     if (!Table)
   1114  1.1  jruoho     {
   1115  1.1  jruoho         return AE_NOT_EXIST;
   1116  1.1  jruoho     }
   1117  1.1  jruoho 
   1118  1.1  jruoho     /* Pass 1:  Parse everything except control method bodies */
   1119  1.1  jruoho 
   1120  1.1  jruoho     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
   1121  1.1  jruoho 
   1122  1.1  jruoho     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
   1123  1.1  jruoho     AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
   1124  1.1  jruoho 
   1125  1.1  jruoho     /* Create the root object */
   1126  1.1  jruoho 
   1127  1.1  jruoho     AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
   1128  1.1  jruoho     if (!AcpiGbl_ParseOpRoot)
   1129  1.1  jruoho     {
   1130  1.1  jruoho         return AE_NO_MEMORY;
   1131  1.1  jruoho     }
   1132  1.1  jruoho 
   1133  1.1  jruoho     /* Create and initialize a new walk state */
   1134  1.1  jruoho 
   1135  1.1  jruoho     WalkState = AcpiDsCreateWalkState (0,
   1136  1.1  jruoho                         AcpiGbl_ParseOpRoot, NULL, NULL);
   1137  1.1  jruoho     if (!WalkState)
   1138  1.1  jruoho     {
   1139  1.1  jruoho         return (AE_NO_MEMORY);
   1140  1.1  jruoho     }
   1141  1.1  jruoho 
   1142  1.1  jruoho     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
   1143  1.1  jruoho                 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
   1144  1.1  jruoho     if (ACPI_FAILURE (Status))
   1145  1.1  jruoho     {
   1146  1.1  jruoho         return (Status);
   1147  1.1  jruoho     }
   1148  1.1  jruoho 
   1149  1.1  jruoho     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
   1150  1.1  jruoho     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
   1151  1.1  jruoho 
   1152  1.1  jruoho     Status = AcpiPsParseAml (WalkState);
   1153  1.1  jruoho     if (ACPI_FAILURE (Status))
   1154  1.1  jruoho     {
   1155  1.1  jruoho         return Status;
   1156  1.1  jruoho     }
   1157  1.1  jruoho 
   1158  1.1  jruoho     /* If LoadTable is FALSE, we are parsing the last loaded table */
   1159  1.1  jruoho 
   1160  1.1  jruoho     TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
   1161  1.1  jruoho 
   1162  1.1  jruoho     /* Pass 2 */
   1163  1.1  jruoho 
   1164  1.1  jruoho     if (LoadTable)
   1165  1.1  jruoho     {
   1166  1.1  jruoho         Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
   1167  1.1  jruoho                     Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
   1168  1.1  jruoho         if (ACPI_FAILURE (Status))
   1169  1.1  jruoho         {
   1170  1.1  jruoho             return Status;
   1171  1.1  jruoho         }
   1172  1.1  jruoho         Status = AcpiTbAllocateOwnerId (TableIndex);
   1173  1.1  jruoho         if (ACPI_FAILURE (Status))
   1174  1.1  jruoho         {
   1175  1.1  jruoho             return Status;
   1176  1.1  jruoho         }
   1177  1.1  jruoho         if (OwnerId)
   1178  1.1  jruoho         {
   1179  1.1  jruoho             Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
   1180  1.1  jruoho             if (ACPI_FAILURE (Status))
   1181  1.1  jruoho             {
   1182  1.1  jruoho                 return Status;
   1183  1.1  jruoho             }
   1184  1.1  jruoho         }
   1185  1.1  jruoho     }
   1186  1.1  jruoho 
   1187  1.1  jruoho     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
   1188  1.1  jruoho 
   1189  1.1  jruoho     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
   1190  1.1  jruoho     if (ACPI_FAILURE (Status))
   1191  1.1  jruoho     {
   1192  1.1  jruoho         return (Status);
   1193  1.1  jruoho     }
   1194  1.1  jruoho 
   1195  1.1  jruoho     /* No need to parse control methods of external table */
   1196  1.1  jruoho 
   1197  1.1  jruoho     if (External)
   1198  1.1  jruoho     {
   1199  1.1  jruoho         return AE_OK;
   1200  1.1  jruoho     }
   1201  1.1  jruoho 
   1202  1.1  jruoho     /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
   1203  1.1  jruoho 
   1204  1.1  jruoho     Status = AdParseDeferredOps (AcpiGbl_ParseOpRoot);
   1205  1.1  jruoho 
   1206  1.1  jruoho     /* Process Resource Templates */
   1207  1.1  jruoho 
   1208  1.1  jruoho     AcpiDmFindResources (AcpiGbl_ParseOpRoot);
   1209  1.1  jruoho 
   1210  1.1  jruoho     fprintf (stderr, "Parsing completed\n");
   1211  1.1  jruoho     return AE_OK;
   1212  1.1  jruoho }
   1213  1.1  jruoho 
   1214  1.1  jruoho 
   1215