Home | History | Annotate | Line # | Download | only in common
adisasm.c revision 1.1.1.4.2.4
      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.1.2    jruoho /*
      8  1.1.1.4.2.3     skrll  * Copyright (C) 2000 - 2016, Intel Corp.
      9          1.1    jruoho  * All rights reserved.
     10          1.1    jruoho  *
     11      1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13      1.1.1.2    jruoho  * are met:
     14      1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1.1.2    jruoho  *    without modification.
     17      1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1.1.2    jruoho  *    binary redistribution.
     22      1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25      1.1.1.2    jruoho  *
     26      1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1.1.2    jruoho  * Software Foundation.
     29      1.1.1.2    jruoho  *
     30      1.1.1.2    jruoho  * NO WARRANTY
     31      1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1.1.2    jruoho  */
     43          1.1    jruoho 
     44      1.1.1.4  christos #include "aslcompiler.h"
     45          1.1    jruoho #include "amlcode.h"
     46          1.1    jruoho #include "acdisasm.h"
     47          1.1    jruoho #include "acdispat.h"
     48          1.1    jruoho #include "acnamesp.h"
     49  1.1.1.4.2.3     skrll #include "acparser.h"
     50          1.1    jruoho #include "acapps.h"
     51          1.1    jruoho 
     52          1.1    jruoho 
     53          1.1    jruoho #define _COMPONENT          ACPI_TOOLS
     54          1.1    jruoho         ACPI_MODULE_NAME    ("adisasm")
     55          1.1    jruoho 
     56          1.1    jruoho /* Local prototypes */
     57          1.1    jruoho 
     58  1.1.1.4.2.3     skrll static ACPI_STATUS
     59  1.1.1.4.2.3     skrll AdDoExternalFileList (
     60  1.1.1.4.2.3     skrll     char                    *Filename);
     61  1.1.1.4.2.3     skrll 
     62  1.1.1.4.2.3     skrll static ACPI_STATUS
     63  1.1.1.4.2.3     skrll AdDisassembleOneTable (
     64  1.1.1.4.2.3     skrll     ACPI_TABLE_HEADER       *Table,
     65  1.1.1.4.2.3     skrll     FILE                    *File,
     66          1.1    jruoho     char                    *Filename,
     67  1.1.1.4.2.3     skrll     char                    *DisasmFilename);
     68          1.1    jruoho 
     69  1.1.1.4.2.1     skrll static ACPI_STATUS
     70  1.1.1.4.2.3     skrll AdReparseOneTable (
     71  1.1.1.4.2.1     skrll     ACPI_TABLE_HEADER       *Table,
     72  1.1.1.4.2.3     skrll     FILE                    *File,
     73  1.1.1.4.2.3     skrll     ACPI_OWNER_ID           OwnerId);
     74  1.1.1.4.2.1     skrll 
     75  1.1.1.4.2.3     skrll 
     76  1.1.1.4.2.3     skrll ACPI_TABLE_DESC             LocalTables[1];
     77  1.1.1.4.2.3     skrll ACPI_PARSE_OBJECT           *AcpiGbl_ParseOpRoot;
     78  1.1.1.4.2.3     skrll 
     79  1.1.1.4.2.3     skrll 
     80  1.1.1.4.2.3     skrll /* Stubs for everything except ASL compiler */
     81          1.1    jruoho 
     82          1.1    jruoho #ifndef ACPI_ASL_COMPILER
     83          1.1    jruoho BOOLEAN
     84          1.1    jruoho AcpiDsIsResultUsed (
     85          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
     86          1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     87          1.1    jruoho {
     88  1.1.1.4.2.3     skrll     return (TRUE);
     89          1.1    jruoho }
     90          1.1    jruoho 
     91          1.1    jruoho ACPI_STATUS
     92          1.1    jruoho AcpiDsMethodError (
     93          1.1    jruoho     ACPI_STATUS             Status,
     94          1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     95          1.1    jruoho {
     96          1.1    jruoho     return (Status);
     97          1.1    jruoho }
     98          1.1    jruoho #endif
     99          1.1    jruoho 
    100      1.1.1.3  christos 
    101      1.1.1.3  christos /*******************************************************************************
    102      1.1.1.3  christos  *
    103          1.1    jruoho  * FUNCTION:    AdInitialize
    104          1.1    jruoho  *
    105          1.1    jruoho  * PARAMETERS:  None
    106          1.1    jruoho  *
    107          1.1    jruoho  * RETURN:      Status
    108          1.1    jruoho  *
    109          1.1    jruoho  * DESCRIPTION: ACPICA and local initialization
    110          1.1    jruoho  *
    111          1.1    jruoho  ******************************************************************************/
    112          1.1    jruoho 
    113          1.1    jruoho ACPI_STATUS
    114          1.1    jruoho AdInitialize (
    115          1.1    jruoho     void)
    116          1.1    jruoho {
    117          1.1    jruoho     ACPI_STATUS             Status;
    118          1.1    jruoho 
    119          1.1    jruoho 
    120      1.1.1.4  christos     /* ACPICA subsystem initialization */
    121          1.1    jruoho 
    122          1.1    jruoho     Status = AcpiOsInitialize ();
    123          1.1    jruoho     if (ACPI_FAILURE (Status))
    124          1.1    jruoho     {
    125          1.1    jruoho         return (Status);
    126          1.1    jruoho     }
    127          1.1    jruoho 
    128          1.1    jruoho     Status = AcpiUtInitGlobals ();
    129          1.1    jruoho     if (ACPI_FAILURE (Status))
    130          1.1    jruoho     {
    131          1.1    jruoho         return (Status);
    132          1.1    jruoho     }
    133          1.1    jruoho 
    134          1.1    jruoho     Status = AcpiUtMutexInitialize ();
    135          1.1    jruoho     if (ACPI_FAILURE (Status))
    136          1.1    jruoho     {
    137          1.1    jruoho         return (Status);
    138          1.1    jruoho     }
    139          1.1    jruoho 
    140          1.1    jruoho     Status = AcpiNsRootInitialize ();
    141          1.1    jruoho     if (ACPI_FAILURE (Status))
    142          1.1    jruoho     {
    143          1.1    jruoho         return (Status);
    144          1.1    jruoho     }
    145          1.1    jruoho 
    146          1.1    jruoho     /* Setup the Table Manager (cheat - there is no RSDT) */
    147          1.1    jruoho 
    148          1.1    jruoho     AcpiGbl_RootTableList.MaxTableCount = 1;
    149          1.1    jruoho     AcpiGbl_RootTableList.CurrentTableCount = 0;
    150          1.1    jruoho     AcpiGbl_RootTableList.Tables = LocalTables;
    151          1.1    jruoho 
    152          1.1    jruoho     return (Status);
    153          1.1    jruoho }
    154          1.1    jruoho 
    155          1.1    jruoho 
    156          1.1    jruoho /******************************************************************************
    157          1.1    jruoho  *
    158          1.1    jruoho  * FUNCTION:    AdAmlDisassemble
    159          1.1    jruoho  *
    160          1.1    jruoho  * PARAMETERS:  Filename            - AML input filename
    161          1.1    jruoho  *              OutToFile           - TRUE if output should go to a file
    162          1.1    jruoho  *              Prefix              - Path prefix for output
    163          1.1    jruoho  *              OutFilename         - where the filename is returned
    164          1.1    jruoho  *
    165          1.1    jruoho  * RETURN:      Status
    166          1.1    jruoho  *
    167  1.1.1.4.2.3     skrll  * DESCRIPTION: Disassembler entry point. Disassemble an entire ACPI table.
    168          1.1    jruoho  *
    169          1.1    jruoho  *****************************************************************************/
    170          1.1    jruoho 
    171          1.1    jruoho ACPI_STATUS
    172          1.1    jruoho AdAmlDisassemble (
    173          1.1    jruoho     BOOLEAN                 OutToFile,
    174          1.1    jruoho     char                    *Filename,
    175          1.1    jruoho     char                    *Prefix,
    176      1.1.1.4  christos     char                    **OutFilename)
    177          1.1    jruoho {
    178          1.1    jruoho     ACPI_STATUS             Status;
    179          1.1    jruoho     char                    *DisasmFilename = NULL;
    180          1.1    jruoho     FILE                    *File = NULL;
    181          1.1    jruoho     ACPI_TABLE_HEADER       *Table = NULL;
    182  1.1.1.4.2.3     skrll     ACPI_NEW_TABLE_DESC     *ListHead = NULL;
    183          1.1    jruoho 
    184          1.1    jruoho 
    185          1.1    jruoho     /*
    186          1.1    jruoho      * Input: AML code from either a file or via GetTables (memory or
    187          1.1    jruoho      * registry)
    188          1.1    jruoho      */
    189          1.1    jruoho     if (Filename)
    190          1.1    jruoho     {
    191  1.1.1.4.2.3     skrll         /* Get the list of all AML tables in the file */
    192  1.1.1.4.2.3     skrll 
    193  1.1.1.4.2.3     skrll         Status = AcGetAllTablesFromFile (Filename,
    194  1.1.1.4.2.3     skrll             ACPI_GET_ALL_TABLES, &ListHead);
    195          1.1    jruoho         if (ACPI_FAILURE (Status))
    196          1.1    jruoho         {
    197  1.1.1.4.2.3     skrll             AcpiOsPrintf ("Could not get ACPI tables from %s, %s\n",
    198  1.1.1.4.2.3     skrll                 Filename, AcpiFormatException (Status));
    199      1.1.1.3  christos             return (Status);
    200          1.1    jruoho         }
    201          1.1    jruoho 
    202  1.1.1.4.2.3     skrll         /* Process any user-specified files for external objects */
    203          1.1    jruoho 
    204  1.1.1.4.2.3     skrll         Status = AdDoExternalFileList (Filename);
    205  1.1.1.4.2.3     skrll         if (ACPI_FAILURE (Status))
    206      1.1.1.2    jruoho         {
    207  1.1.1.4.2.3     skrll             return (Status);
    208          1.1    jruoho         }
    209          1.1    jruoho     }
    210          1.1    jruoho     else
    211          1.1    jruoho     {
    212      1.1.1.4  christos         Status = AdGetLocalTables ();
    213          1.1    jruoho         if (ACPI_FAILURE (Status))
    214          1.1    jruoho         {
    215          1.1    jruoho             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
    216          1.1    jruoho                 AcpiFormatException (Status));
    217      1.1.1.3  christos             return (Status);
    218          1.1    jruoho         }
    219          1.1    jruoho 
    220  1.1.1.4.2.3     skrll         if (!AcpiGbl_DmOpt_Disasm)
    221          1.1    jruoho         {
    222      1.1.1.3  christos             return (AE_OK);
    223          1.1    jruoho         }
    224          1.1    jruoho 
    225          1.1    jruoho         /* Obtained the local tables, just disassemble the DSDT */
    226          1.1    jruoho 
    227          1.1    jruoho         Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
    228          1.1    jruoho         if (ACPI_FAILURE (Status))
    229          1.1    jruoho         {
    230          1.1    jruoho             AcpiOsPrintf ("Could not get DSDT, %s\n",
    231          1.1    jruoho                 AcpiFormatException (Status));
    232      1.1.1.3  christos             return (Status);
    233          1.1    jruoho         }
    234          1.1    jruoho 
    235          1.1    jruoho         AcpiOsPrintf ("\nDisassembly of DSDT\n");
    236          1.1    jruoho         Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
    237          1.1    jruoho     }
    238          1.1    jruoho 
    239          1.1    jruoho     /*
    240      1.1.1.3  christos      * Output: ASL code. Redirect to a file if requested
    241          1.1    jruoho      */
    242          1.1    jruoho     if (OutToFile)
    243          1.1    jruoho     {
    244          1.1    jruoho         /* Create/Open a disassembly output file */
    245          1.1    jruoho 
    246          1.1    jruoho         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
    247      1.1.1.4  christos         if (!DisasmFilename)
    248          1.1    jruoho         {
    249          1.1    jruoho             fprintf (stderr, "Could not generate output filename\n");
    250          1.1    jruoho             Status = AE_ERROR;
    251          1.1    jruoho             goto Cleanup;
    252          1.1    jruoho         }
    253          1.1    jruoho 
    254          1.1    jruoho         File = fopen (DisasmFilename, "w+");
    255          1.1    jruoho         if (!File)
    256          1.1    jruoho         {
    257  1.1.1.4.2.3     skrll             fprintf (stderr, "Could not open output file %s\n",
    258  1.1.1.4.2.3     skrll                 DisasmFilename);
    259          1.1    jruoho             Status = AE_ERROR;
    260          1.1    jruoho             goto Cleanup;
    261          1.1    jruoho         }
    262          1.1    jruoho 
    263          1.1    jruoho         AcpiOsRedirectOutput (File);
    264          1.1    jruoho     }
    265          1.1    jruoho 
    266          1.1    jruoho     *OutFilename = DisasmFilename;
    267          1.1    jruoho 
    268  1.1.1.4.2.3     skrll     /* Disassemble all AML tables within the file */
    269  1.1.1.4.2.1     skrll 
    270  1.1.1.4.2.3     skrll     while (ListHead)
    271          1.1    jruoho     {
    272  1.1.1.4.2.3     skrll         Status = AdDisassembleOneTable (ListHead->Table,
    273  1.1.1.4.2.3     skrll             File, Filename, DisasmFilename);
    274          1.1    jruoho         if (ACPI_FAILURE (Status))
    275          1.1    jruoho         {
    276  1.1.1.4.2.3     skrll             break;
    277          1.1    jruoho         }
    278          1.1    jruoho 
    279  1.1.1.4.2.3     skrll         ListHead = ListHead->Next;
    280          1.1    jruoho     }
    281          1.1    jruoho 
    282          1.1    jruoho Cleanup:
    283          1.1    jruoho 
    284  1.1.1.4.2.3     skrll     if (Table &&
    285  1.1.1.4.2.3     skrll         !AcpiGbl_ForceAmlDisassembly &&
    286  1.1.1.4.2.3     skrll         !AcpiUtIsAmlTable (Table))
    287          1.1    jruoho     {
    288          1.1    jruoho         ACPI_FREE (Table);
    289          1.1    jruoho     }
    290          1.1    jruoho 
    291  1.1.1.4.2.1     skrll     if (File)
    292          1.1    jruoho     {
    293          1.1    jruoho         fclose (File);
    294          1.1    jruoho         AcpiOsRedirectOutput (stdout);
    295          1.1    jruoho     }
    296          1.1    jruoho 
    297          1.1    jruoho     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    298          1.1    jruoho     AcpiGbl_ParseOpRoot = NULL;
    299          1.1    jruoho     return (Status);
    300          1.1    jruoho }
    301          1.1    jruoho 
    302          1.1    jruoho 
    303          1.1    jruoho /******************************************************************************
    304          1.1    jruoho  *
    305  1.1.1.4.2.3     skrll  * FUNCTION:    AdDisassembleOneTable
    306          1.1    jruoho  *
    307  1.1.1.4.2.3     skrll  * PARAMETERS:  Table               - Raw AML table
    308  1.1.1.4.2.3     skrll  *              File                - Pointer for the input file
    309  1.1.1.4.2.3     skrll  *              Filename            - AML input filename
    310  1.1.1.4.2.3     skrll  *              DisasmFilename      - Output filename
    311          1.1    jruoho  *
    312  1.1.1.4.2.3     skrll  * RETURN:      Status
    313          1.1    jruoho  *
    314  1.1.1.4.2.3     skrll  * DESCRIPTION: Disassemble a single ACPI table. AML or data table.
    315          1.1    jruoho  *
    316          1.1    jruoho  *****************************************************************************/
    317          1.1    jruoho 
    318  1.1.1.4.2.3     skrll static ACPI_STATUS
    319  1.1.1.4.2.3     skrll AdDisassembleOneTable (
    320  1.1.1.4.2.3     skrll     ACPI_TABLE_HEADER       *Table,
    321  1.1.1.4.2.3     skrll     FILE                    *File,
    322  1.1.1.4.2.1     skrll     char                    *Filename,
    323  1.1.1.4.2.3     skrll     char                    *DisasmFilename)
    324          1.1    jruoho {
    325  1.1.1.4.2.3     skrll     ACPI_STATUS             Status;
    326  1.1.1.4.2.3     skrll     ACPI_OWNER_ID           OwnerId;
    327          1.1    jruoho 
    328          1.1    jruoho 
    329  1.1.1.4.2.3     skrll     /* ForceAmlDisassembly means to assume the table contains valid AML */
    330  1.1.1.4.2.1     skrll 
    331  1.1.1.4.2.3     skrll     if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table))
    332  1.1.1.4.2.1     skrll     {
    333  1.1.1.4.2.3     skrll         AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE);
    334          1.1    jruoho 
    335  1.1.1.4.2.3     skrll         /* This is a "Data Table" (non-AML table) */
    336          1.1    jruoho 
    337  1.1.1.4.2.3     skrll         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
    338  1.1.1.4.2.3     skrll             Table->Signature);
    339  1.1.1.4.2.3     skrll         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  "
    340  1.1.1.4.2.3     skrll             "FieldName : FieldValue\n */\n\n");
    341          1.1    jruoho 
    342  1.1.1.4.2.3     skrll         AcpiDmDumpDataTable (Table);
    343  1.1.1.4.2.3     skrll         fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
    344  1.1.1.4.2.3     skrll             Table->Signature);
    345          1.1    jruoho 
    346  1.1.1.4.2.3     skrll         if (File)
    347  1.1.1.4.2.3     skrll         {
    348  1.1.1.4.2.3     skrll             fprintf (stderr, "Formatted output:  %s - %u bytes\n",
    349  1.1.1.4.2.3     skrll                 DisasmFilename, CmGetFileSize (File));
    350  1.1.1.4.2.3     skrll         }
    351          1.1    jruoho 
    352  1.1.1.4.2.3     skrll         return (AE_OK);
    353  1.1.1.4.2.3     skrll     }
    354          1.1    jruoho 
    355          1.1    jruoho     /*
    356  1.1.1.4.2.3     skrll      * This is an AML table (DSDT or SSDT).
    357  1.1.1.4.2.3     skrll      * Always parse the tables, only option is what to display
    358          1.1    jruoho      */
    359  1.1.1.4.2.3     skrll     Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
    360  1.1.1.4.2.3     skrll     if (ACPI_FAILURE (Status))
    361  1.1.1.4.2.3     skrll     {
    362  1.1.1.4.2.3     skrll         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    363  1.1.1.4.2.3     skrll             AcpiFormatException (Status));
    364  1.1.1.4.2.3     skrll         return (Status);
    365  1.1.1.4.2.3     skrll     }
    366          1.1    jruoho 
    367  1.1.1.4.2.3     skrll     /* Debug output, namespace and parse tree */
    368          1.1    jruoho 
    369  1.1.1.4.2.3     skrll     if (AslCompilerdebug && File)
    370          1.1    jruoho     {
    371  1.1.1.4.2.3     skrll         AcpiOsPrintf ("/**** Before second load\n");
    372      1.1.1.3  christos 
    373  1.1.1.4.2.3     skrll         NsSetupNamespaceListing (File);
    374  1.1.1.4.2.3     skrll         NsDisplayNamespace ();
    375          1.1    jruoho 
    376  1.1.1.4.2.3     skrll         AcpiOsPrintf ("*****/\n");
    377  1.1.1.4.2.3     skrll     }
    378      1.1.1.3  christos 
    379  1.1.1.4.2.3     skrll     /* Load namespace from names created within control methods */
    380          1.1    jruoho 
    381  1.1.1.4.2.3     skrll     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    382  1.1.1.4.2.3     skrll         AcpiGbl_RootNode, OwnerId);
    383          1.1    jruoho 
    384  1.1.1.4.2.3     skrll     /*
    385  1.1.1.4.2.3     skrll      * Cross reference the namespace here, in order to
    386  1.1.1.4.2.3     skrll      * generate External() statements
    387  1.1.1.4.2.3     skrll      */
    388  1.1.1.4.2.3     skrll     AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    389  1.1.1.4.2.3     skrll         AcpiGbl_RootNode, OwnerId);
    390      1.1.1.3  christos 
    391  1.1.1.4.2.3     skrll     if (AslCompilerdebug)
    392  1.1.1.4.2.3     skrll     {
    393  1.1.1.4.2.3     skrll         AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    394          1.1    jruoho     }
    395          1.1    jruoho 
    396  1.1.1.4.2.3     skrll     /* Find possible calls to external control methods */
    397          1.1    jruoho 
    398  1.1.1.4.2.3     skrll     AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
    399          1.1    jruoho 
    400  1.1.1.4.2.3     skrll     /*
    401  1.1.1.4.2.3     skrll      * If we found any external control methods, we must reparse
    402  1.1.1.4.2.3     skrll      * the entire tree with the new information (namely, the
    403  1.1.1.4.2.3     skrll      * number of arguments per method)
    404  1.1.1.4.2.3     skrll      */
    405  1.1.1.4.2.3     skrll     if (AcpiDmGetExternalMethodCount ())
    406          1.1    jruoho     {
    407  1.1.1.4.2.3     skrll         Status = AdReparseOneTable (Table, File, OwnerId);
    408  1.1.1.4.2.3     skrll         if (ACPI_FAILURE (Status))
    409  1.1.1.4.2.3     skrll         {
    410  1.1.1.4.2.3     skrll             return (Status);
    411  1.1.1.4.2.3     skrll         }
    412          1.1    jruoho     }
    413          1.1    jruoho 
    414  1.1.1.4.2.3     skrll     /*
    415  1.1.1.4.2.3     skrll      * Now that the namespace is finalized, we can perform namespace
    416  1.1.1.4.2.3     skrll      * transforms.
    417  1.1.1.4.2.3     skrll      *
    418  1.1.1.4.2.3     skrll      * 1) Convert fixed-offset references to resource descriptors
    419  1.1.1.4.2.3     skrll      *    to symbolic references (Note: modifies namespace)
    420  1.1.1.4.2.3     skrll      */
    421  1.1.1.4.2.3     skrll     AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
    422          1.1    jruoho 
    423  1.1.1.4.2.3     skrll     /* Optional displays */
    424          1.1    jruoho 
    425  1.1.1.4.2.3     skrll     if (AcpiGbl_DmOpt_Disasm)
    426          1.1    jruoho     {
    427  1.1.1.4.2.3     skrll         /* This is the real disassembly */
    428  1.1.1.4.2.3     skrll 
    429  1.1.1.4.2.3     skrll         AdDisplayTables (Filename, Table);
    430  1.1.1.4.2.3     skrll 
    431  1.1.1.4.2.3     skrll         /* Dump hex table if requested (-vt) */
    432  1.1.1.4.2.3     skrll 
    433  1.1.1.4.2.3     skrll         AcpiDmDumpDataTable (Table);
    434  1.1.1.4.2.3     skrll 
    435  1.1.1.4.2.3     skrll         fprintf (stderr, "Disassembly completed\n");
    436  1.1.1.4.2.3     skrll         if (File)
    437      1.1.1.4  christos         {
    438  1.1.1.4.2.3     skrll             fprintf (stderr, "ASL Output:    %s - %u bytes\n",
    439  1.1.1.4.2.3     skrll                 DisasmFilename, CmGetFileSize (File));
    440      1.1.1.4  christos         }
    441      1.1.1.4  christos 
    442  1.1.1.4.2.3     skrll         if (Gbl_MapfileFlag)
    443  1.1.1.4.2.3     skrll         {
    444  1.1.1.4.2.3     skrll             fprintf (stderr, "%14s %s - %u bytes\n",
    445  1.1.1.4.2.3     skrll                 Gbl_Files[ASL_FILE_MAP_OUTPUT].ShortDescription,
    446  1.1.1.4.2.3     skrll                 Gbl_Files[ASL_FILE_MAP_OUTPUT].Filename,
    447  1.1.1.4.2.3     skrll                 FlGetFileSize (ASL_FILE_MAP_OUTPUT));
    448  1.1.1.4.2.3     skrll         }
    449          1.1    jruoho     }
    450          1.1    jruoho 
    451  1.1.1.4.2.3     skrll     return (AE_OK);
    452          1.1    jruoho }
    453          1.1    jruoho 
    454          1.1    jruoho 
    455          1.1    jruoho /******************************************************************************
    456          1.1    jruoho  *
    457  1.1.1.4.2.3     skrll  * FUNCTION:    AdReparseOneTable
    458          1.1    jruoho  *
    459  1.1.1.4.2.3     skrll  * PARAMETERS:  Table               - Raw AML table
    460  1.1.1.4.2.3     skrll  *              File                - Pointer for the input file
    461  1.1.1.4.2.3     skrll  *              OwnerId             - ID for this table
    462          1.1    jruoho  *
    463          1.1    jruoho  * RETURN:      Status
    464          1.1    jruoho  *
    465  1.1.1.4.2.3     skrll  * DESCRIPTION: Reparse a table that has already been loaded. Used to
    466  1.1.1.4.2.3     skrll  *              integrate information about external control methods.
    467  1.1.1.4.2.3     skrll  *              These methods may have been previously parsed incorrectly.
    468          1.1    jruoho  *
    469          1.1    jruoho  *****************************************************************************/
    470          1.1    jruoho 
    471  1.1.1.4.2.3     skrll static ACPI_STATUS
    472  1.1.1.4.2.3     skrll AdReparseOneTable (
    473  1.1.1.4.2.3     skrll     ACPI_TABLE_HEADER       *Table,
    474  1.1.1.4.2.3     skrll     FILE                    *File,
    475  1.1.1.4.2.3     skrll     ACPI_OWNER_ID           OwnerId)
    476          1.1    jruoho {
    477  1.1.1.4.2.3     skrll     ACPI_STATUS             Status;
    478          1.1    jruoho 
    479          1.1    jruoho 
    480  1.1.1.4.2.3     skrll     fprintf (stderr,
    481  1.1.1.4.2.3     skrll         "\nFound %u external control methods, "
    482  1.1.1.4.2.3     skrll         "reparsing with new information\n",
    483  1.1.1.4.2.3     skrll         AcpiDmGetExternalMethodCount ());
    484          1.1    jruoho 
    485  1.1.1.4.2.3     skrll     /* Reparse, rebuild namespace */
    486          1.1    jruoho 
    487  1.1.1.4.2.3     skrll     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    488  1.1.1.4.2.3     skrll     AcpiGbl_ParseOpRoot = NULL;
    489  1.1.1.4.2.3     skrll     AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
    490          1.1    jruoho 
    491  1.1.1.4.2.3     skrll     AcpiGbl_RootNode                    = NULL;
    492  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
    493  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
    494  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
    495  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.Parent       = NULL;
    496  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.Child        = NULL;
    497  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.Peer         = NULL;
    498  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.Object       = NULL;
    499  1.1.1.4.2.3     skrll     AcpiGbl_RootNodeStruct.Flags        = 0;
    500          1.1    jruoho 
    501  1.1.1.4.2.3     skrll     Status = AcpiNsRootInitialize ();
    502  1.1.1.4.2.3     skrll     if (ACPI_FAILURE (Status))
    503  1.1.1.4.2.3     skrll     {
    504  1.1.1.4.2.3     skrll         return (Status);
    505          1.1    jruoho     }
    506          1.1    jruoho 
    507  1.1.1.4.2.3     skrll     /* New namespace, add the external definitions first */
    508  1.1.1.4.2.1     skrll 
    509  1.1.1.4.2.3     skrll     AcpiDmAddExternalsToNamespace ();
    510  1.1.1.4.2.1     skrll 
    511  1.1.1.4.2.3     skrll     /* Parse the table again. No need to reload it, however */
    512  1.1.1.4.2.1     skrll 
    513  1.1.1.4.2.3     skrll     Status = AdParseTable (Table, NULL, FALSE, FALSE);
    514  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    515  1.1.1.4.2.1     skrll     {
    516  1.1.1.4.2.3     skrll         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    517  1.1.1.4.2.3     skrll             AcpiFormatException (Status));
    518  1.1.1.4.2.1     skrll         return (Status);
    519  1.1.1.4.2.1     skrll     }
    520  1.1.1.4.2.1     skrll 
    521  1.1.1.4.2.3     skrll     /* Cross reference the namespace again */
    522          1.1    jruoho 
    523  1.1.1.4.2.3     skrll     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    524  1.1.1.4.2.3     skrll         AcpiGbl_RootNode, OwnerId);
    525          1.1    jruoho 
    526  1.1.1.4.2.3     skrll     AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    527  1.1.1.4.2.3     skrll         AcpiGbl_RootNode, OwnerId);
    528          1.1    jruoho 
    529  1.1.1.4.2.3     skrll     /* Debug output - namespace and parse tree */
    530          1.1    jruoho 
    531  1.1.1.4.2.3     skrll     if (AslCompilerdebug)
    532          1.1    jruoho     {
    533  1.1.1.4.2.3     skrll         AcpiOsPrintf ("/**** After second load and resource conversion\n");
    534  1.1.1.4.2.3     skrll         if (File)
    535  1.1.1.4.2.3     skrll         {
    536  1.1.1.4.2.3     skrll             NsSetupNamespaceListing (File);
    537  1.1.1.4.2.3     skrll             NsDisplayNamespace ();
    538  1.1.1.4.2.3     skrll         }
    539          1.1    jruoho 
    540  1.1.1.4.2.3     skrll         AcpiOsPrintf ("*****/\n");
    541  1.1.1.4.2.3     skrll         AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    542      1.1.1.4  christos     }
    543          1.1    jruoho 
    544      1.1.1.3  christos     return (AE_OK);
    545          1.1    jruoho }
    546          1.1    jruoho 
    547          1.1    jruoho 
    548          1.1    jruoho /******************************************************************************
    549          1.1    jruoho  *
    550  1.1.1.4.2.3     skrll  * FUNCTION:    AdDoExternalFileList
    551          1.1    jruoho  *
    552  1.1.1.4.2.3     skrll  * PARAMETERS:  Filename            - Input file for the table
    553          1.1    jruoho  *
    554          1.1    jruoho  * RETURN:      Status
    555          1.1    jruoho  *
    556  1.1.1.4.2.3     skrll  * DESCRIPTION: Process all tables found in the -e external files list
    557          1.1    jruoho  *
    558          1.1    jruoho  *****************************************************************************/
    559          1.1    jruoho 
    560  1.1.1.4.2.3     skrll static ACPI_STATUS
    561  1.1.1.4.2.3     skrll AdDoExternalFileList (
    562  1.1.1.4.2.3     skrll     char                    *Filename)
    563          1.1    jruoho {
    564  1.1.1.4.2.3     skrll     ACPI_EXTERNAL_FILE      *ExternalFileList;
    565  1.1.1.4.2.3     skrll     char                    *ExternalFilename;
    566  1.1.1.4.2.3     skrll     ACPI_NEW_TABLE_DESC     *ExternalListHead = NULL;
    567  1.1.1.4.2.3     skrll     ACPI_STATUS             Status;
    568  1.1.1.4.2.3     skrll     ACPI_STATUS             GlobalStatus = AE_OK;
    569  1.1.1.4.2.3     skrll     ACPI_OWNER_ID           OwnerId;
    570          1.1    jruoho 
    571          1.1    jruoho 
    572  1.1.1.4.2.3     skrll     /*
    573  1.1.1.4.2.3     skrll      * External filenames are specified on the command line like this:
    574  1.1.1.4.2.3     skrll      * Example: iasl -e file1,file2,file3 -d xxx.aml
    575  1.1.1.4.2.3     skrll      */
    576  1.1.1.4.2.3     skrll     ExternalFileList = AcpiGbl_ExternalFileList;
    577          1.1    jruoho 
    578  1.1.1.4.2.3     skrll     /* Process each external file */
    579          1.1    jruoho 
    580  1.1.1.4.2.3     skrll     while (ExternalFileList)
    581          1.1    jruoho     {
    582  1.1.1.4.2.3     skrll         ExternalFilename = ExternalFileList->Path;
    583  1.1.1.4.2.3     skrll         if (!strcmp (ExternalFilename, Filename))
    584  1.1.1.4.2.3     skrll         {
    585  1.1.1.4.2.3     skrll             /* Next external file */
    586          1.1    jruoho 
    587  1.1.1.4.2.3     skrll             ExternalFileList = ExternalFileList->Next;
    588  1.1.1.4.2.3     skrll             continue;
    589  1.1.1.4.2.3     skrll         }
    590          1.1    jruoho 
    591  1.1.1.4.2.3     skrll         AcpiOsPrintf ("External object resolution file %16s\n",
    592  1.1.1.4.2.3     skrll             ExternalFilename);
    593          1.1    jruoho 
    594  1.1.1.4.2.3     skrll         Status = AcGetAllTablesFromFile (
    595  1.1.1.4.2.3     skrll             ExternalFilename, ACPI_GET_ONLY_AML_TABLES, &ExternalListHead);
    596          1.1    jruoho         if (ACPI_FAILURE (Status))
    597          1.1    jruoho         {
    598  1.1.1.4.2.3     skrll             if (Status == AE_TYPE)
    599  1.1.1.4.2.3     skrll             {
    600  1.1.1.4.2.3     skrll                 ExternalFileList = ExternalFileList->Next;
    601  1.1.1.4.2.3     skrll                 GlobalStatus = AE_TYPE;
    602  1.1.1.4.2.3     skrll                 Status = AE_OK;
    603  1.1.1.4.2.3     skrll                 continue;
    604  1.1.1.4.2.3     skrll             }
    605  1.1.1.4.2.3     skrll 
    606      1.1.1.3  christos             return (Status);
    607          1.1    jruoho         }
    608  1.1.1.4.2.3     skrll 
    609  1.1.1.4.2.3     skrll         /* Load external tables for symbol resolution */
    610  1.1.1.4.2.3     skrll 
    611  1.1.1.4.2.3     skrll         while (ExternalListHead)
    612          1.1    jruoho         {
    613  1.1.1.4.2.3     skrll             Status = AdParseTable (
    614  1.1.1.4.2.3     skrll                 ExternalListHead->Table, &OwnerId, TRUE, TRUE);
    615          1.1    jruoho             if (ACPI_FAILURE (Status))
    616          1.1    jruoho             {
    617  1.1.1.4.2.3     skrll                 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
    618  1.1.1.4.2.3     skrll                     AcpiFormatException (Status));
    619      1.1.1.3  christos                 return (Status);
    620          1.1    jruoho             }
    621  1.1.1.4.2.3     skrll 
    622  1.1.1.4.2.3     skrll             /*
    623  1.1.1.4.2.3     skrll              * Load namespace from names created within control methods
    624  1.1.1.4.2.3     skrll              * Set owner id of nodes in external table
    625  1.1.1.4.2.3     skrll              */
    626  1.1.1.4.2.3     skrll             AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    627  1.1.1.4.2.3     skrll                 AcpiGbl_RootNode, OwnerId);
    628  1.1.1.4.2.3     skrll             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    629  1.1.1.4.2.3     skrll 
    630  1.1.1.4.2.3     skrll             ExternalListHead = ExternalListHead->Next;
    631          1.1    jruoho         }
    632          1.1    jruoho 
    633  1.1.1.4.2.3     skrll         /* Next external file */
    634          1.1    jruoho 
    635  1.1.1.4.2.3     skrll         ExternalFileList = ExternalFileList->Next;
    636          1.1    jruoho     }
    637          1.1    jruoho 
    638  1.1.1.4.2.3     skrll     if (ACPI_FAILURE (GlobalStatus))
    639          1.1    jruoho     {
    640  1.1.1.4.2.3     skrll         return (GlobalStatus);
    641          1.1    jruoho     }
    642          1.1    jruoho 
    643  1.1.1.4.2.3     skrll     /* Clear external list generated by Scope in external tables */
    644          1.1    jruoho 
    645  1.1.1.4.2.3     skrll     if (AcpiGbl_ExternalFileList)
    646  1.1.1.4.2.3     skrll     {
    647  1.1.1.4.2.3     skrll         AcpiDmClearExternalList ();
    648  1.1.1.4.2.3     skrll     }
    649          1.1    jruoho 
    650  1.1.1.4.2.3     skrll     /* Load any externals defined in the optional external ref file */
    651          1.1    jruoho 
    652  1.1.1.4.2.3     skrll     AcpiDmGetExternalsFromFile ();
    653      1.1.1.3  christos     return (AE_OK);
    654          1.1    jruoho }
    655