Home | History | Annotate | Line # | Download | only in common
adisasm.c revision 1.1.1.14
      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.14  christos  * Copyright (C) 2000 - 2019, 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.7  christos #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.7  christos static ACPI_STATUS
     59   1.1.1.7  christos AdDoExternalFileList (
     60   1.1.1.7  christos     char                    *Filename);
     61   1.1.1.7  christos 
     62   1.1.1.7  christos static ACPI_STATUS
     63   1.1.1.7  christos AdDisassembleOneTable (
     64   1.1.1.7  christos     ACPI_TABLE_HEADER       *Table,
     65   1.1.1.7  christos     FILE                    *File,
     66       1.1    jruoho     char                    *Filename,
     67   1.1.1.7  christos     char                    *DisasmFilename);
     68       1.1    jruoho 
     69   1.1.1.5  christos static ACPI_STATUS
     70   1.1.1.7  christos AdReparseOneTable (
     71   1.1.1.5  christos     ACPI_TABLE_HEADER       *Table,
     72   1.1.1.7  christos     FILE                    *File,
     73   1.1.1.7  christos     ACPI_OWNER_ID           OwnerId);
     74   1.1.1.5  christos 
     75   1.1.1.7  christos 
     76   1.1.1.7  christos ACPI_TABLE_DESC             LocalTables[1];
     77   1.1.1.7  christos ACPI_PARSE_OBJECT           *AcpiGbl_ParseOpRoot;
     78   1.1.1.7  christos 
     79   1.1.1.7  christos 
     80   1.1.1.7  christos /* 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.7  christos     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.1.10  christos         fprintf (stderr, "Could not initialize ACPICA subsystem: %s\n",
    126  1.1.1.10  christos             AcpiFormatException (Status));
    127  1.1.1.10  christos 
    128       1.1    jruoho         return (Status);
    129       1.1    jruoho     }
    130       1.1    jruoho 
    131       1.1    jruoho     Status = AcpiUtInitGlobals ();
    132       1.1    jruoho     if (ACPI_FAILURE (Status))
    133       1.1    jruoho     {
    134  1.1.1.10  christos         fprintf (stderr, "Could not initialize ACPICA globals: %s\n",
    135  1.1.1.10  christos             AcpiFormatException (Status));
    136  1.1.1.10  christos 
    137       1.1    jruoho         return (Status);
    138       1.1    jruoho     }
    139       1.1    jruoho 
    140       1.1    jruoho     Status = AcpiUtMutexInitialize ();
    141       1.1    jruoho     if (ACPI_FAILURE (Status))
    142       1.1    jruoho     {
    143  1.1.1.10  christos         fprintf (stderr, "Could not initialize ACPICA mutex objects: %s\n",
    144  1.1.1.10  christos             AcpiFormatException (Status));
    145  1.1.1.10  christos 
    146       1.1    jruoho         return (Status);
    147       1.1    jruoho     }
    148       1.1    jruoho 
    149       1.1    jruoho     Status = AcpiNsRootInitialize ();
    150       1.1    jruoho     if (ACPI_FAILURE (Status))
    151       1.1    jruoho     {
    152  1.1.1.10  christos         fprintf (stderr, "Could not initialize ACPICA namespace: %s\n",
    153  1.1.1.10  christos             AcpiFormatException (Status));
    154  1.1.1.10  christos 
    155       1.1    jruoho         return (Status);
    156       1.1    jruoho     }
    157       1.1    jruoho 
    158       1.1    jruoho     /* Setup the Table Manager (cheat - there is no RSDT) */
    159       1.1    jruoho 
    160       1.1    jruoho     AcpiGbl_RootTableList.MaxTableCount = 1;
    161       1.1    jruoho     AcpiGbl_RootTableList.CurrentTableCount = 0;
    162       1.1    jruoho     AcpiGbl_RootTableList.Tables = LocalTables;
    163       1.1    jruoho 
    164  1.1.1.10  christos     return (AE_OK);
    165       1.1    jruoho }
    166       1.1    jruoho 
    167       1.1    jruoho 
    168       1.1    jruoho /******************************************************************************
    169       1.1    jruoho  *
    170       1.1    jruoho  * FUNCTION:    AdAmlDisassemble
    171       1.1    jruoho  *
    172       1.1    jruoho  * PARAMETERS:  Filename            - AML input filename
    173       1.1    jruoho  *              OutToFile           - TRUE if output should go to a file
    174       1.1    jruoho  *              Prefix              - Path prefix for output
    175       1.1    jruoho  *              OutFilename         - where the filename is returned
    176       1.1    jruoho  *
    177       1.1    jruoho  * RETURN:      Status
    178       1.1    jruoho  *
    179   1.1.1.7  christos  * DESCRIPTION: Disassembler entry point. Disassemble an entire ACPI table.
    180       1.1    jruoho  *
    181       1.1    jruoho  *****************************************************************************/
    182       1.1    jruoho 
    183       1.1    jruoho ACPI_STATUS
    184       1.1    jruoho AdAmlDisassemble (
    185       1.1    jruoho     BOOLEAN                 OutToFile,
    186       1.1    jruoho     char                    *Filename,
    187       1.1    jruoho     char                    *Prefix,
    188   1.1.1.4  christos     char                    **OutFilename)
    189       1.1    jruoho {
    190       1.1    jruoho     ACPI_STATUS             Status;
    191       1.1    jruoho     char                    *DisasmFilename = NULL;
    192       1.1    jruoho     FILE                    *File = NULL;
    193       1.1    jruoho     ACPI_TABLE_HEADER       *Table = NULL;
    194   1.1.1.7  christos     ACPI_NEW_TABLE_DESC     *ListHead = NULL;
    195       1.1    jruoho 
    196       1.1    jruoho 
    197       1.1    jruoho     /*
    198       1.1    jruoho      * Input: AML code from either a file or via GetTables (memory or
    199       1.1    jruoho      * registry)
    200       1.1    jruoho      */
    201       1.1    jruoho     if (Filename)
    202       1.1    jruoho     {
    203   1.1.1.7  christos         /* Get the list of all AML tables in the file */
    204   1.1.1.7  christos 
    205   1.1.1.7  christos         Status = AcGetAllTablesFromFile (Filename,
    206   1.1.1.7  christos             ACPI_GET_ALL_TABLES, &ListHead);
    207       1.1    jruoho         if (ACPI_FAILURE (Status))
    208       1.1    jruoho         {
    209   1.1.1.7  christos             AcpiOsPrintf ("Could not get ACPI tables from %s, %s\n",
    210   1.1.1.7  christos                 Filename, AcpiFormatException (Status));
    211   1.1.1.3  christos             return (Status);
    212       1.1    jruoho         }
    213       1.1    jruoho 
    214   1.1.1.7  christos         /* Process any user-specified files for external objects */
    215       1.1    jruoho 
    216   1.1.1.7  christos         Status = AdDoExternalFileList (Filename);
    217   1.1.1.7  christos         if (ACPI_FAILURE (Status))
    218   1.1.1.2    jruoho         {
    219   1.1.1.7  christos             return (Status);
    220       1.1    jruoho         }
    221       1.1    jruoho     }
    222       1.1    jruoho     else
    223       1.1    jruoho     {
    224   1.1.1.4  christos         Status = AdGetLocalTables ();
    225       1.1    jruoho         if (ACPI_FAILURE (Status))
    226       1.1    jruoho         {
    227       1.1    jruoho             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
    228       1.1    jruoho                 AcpiFormatException (Status));
    229   1.1.1.3  christos             return (Status);
    230       1.1    jruoho         }
    231       1.1    jruoho 
    232   1.1.1.7  christos         if (!AcpiGbl_DmOpt_Disasm)
    233       1.1    jruoho         {
    234   1.1.1.3  christos             return (AE_OK);
    235       1.1    jruoho         }
    236       1.1    jruoho 
    237       1.1    jruoho         /* Obtained the local tables, just disassemble the DSDT */
    238       1.1    jruoho 
    239       1.1    jruoho         Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
    240       1.1    jruoho         if (ACPI_FAILURE (Status))
    241       1.1    jruoho         {
    242       1.1    jruoho             AcpiOsPrintf ("Could not get DSDT, %s\n",
    243       1.1    jruoho                 AcpiFormatException (Status));
    244   1.1.1.3  christos             return (Status);
    245       1.1    jruoho         }
    246       1.1    jruoho 
    247       1.1    jruoho         AcpiOsPrintf ("\nDisassembly of DSDT\n");
    248       1.1    jruoho         Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
    249       1.1    jruoho     }
    250       1.1    jruoho 
    251       1.1    jruoho     /*
    252   1.1.1.3  christos      * Output: ASL code. Redirect to a file if requested
    253       1.1    jruoho      */
    254       1.1    jruoho     if (OutToFile)
    255       1.1    jruoho     {
    256       1.1    jruoho         /* Create/Open a disassembly output file */
    257       1.1    jruoho 
    258       1.1    jruoho         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
    259   1.1.1.4  christos         if (!DisasmFilename)
    260       1.1    jruoho         {
    261       1.1    jruoho             fprintf (stderr, "Could not generate output filename\n");
    262       1.1    jruoho             Status = AE_ERROR;
    263       1.1    jruoho             goto Cleanup;
    264       1.1    jruoho         }
    265       1.1    jruoho 
    266       1.1    jruoho         File = fopen (DisasmFilename, "w+");
    267       1.1    jruoho         if (!File)
    268       1.1    jruoho         {
    269   1.1.1.7  christos             fprintf (stderr, "Could not open output file %s\n",
    270   1.1.1.7  christos                 DisasmFilename);
    271       1.1    jruoho             Status = AE_ERROR;
    272       1.1    jruoho             goto Cleanup;
    273       1.1    jruoho         }
    274       1.1    jruoho 
    275       1.1    jruoho         AcpiOsRedirectOutput (File);
    276       1.1    jruoho     }
    277       1.1    jruoho 
    278       1.1    jruoho     *OutFilename = DisasmFilename;
    279       1.1    jruoho 
    280   1.1.1.7  christos     /* Disassemble all AML tables within the file */
    281   1.1.1.5  christos 
    282   1.1.1.7  christos     while (ListHead)
    283       1.1    jruoho     {
    284   1.1.1.7  christos         Status = AdDisassembleOneTable (ListHead->Table,
    285   1.1.1.7  christos             File, Filename, DisasmFilename);
    286       1.1    jruoho         if (ACPI_FAILURE (Status))
    287       1.1    jruoho         {
    288   1.1.1.7  christos             break;
    289       1.1    jruoho         }
    290       1.1    jruoho 
    291   1.1.1.7  christos         ListHead = ListHead->Next;
    292       1.1    jruoho     }
    293       1.1    jruoho 
    294       1.1    jruoho Cleanup:
    295       1.1    jruoho 
    296   1.1.1.7  christos     if (Table &&
    297   1.1.1.7  christos         !AcpiGbl_ForceAmlDisassembly &&
    298   1.1.1.7  christos         !AcpiUtIsAmlTable (Table))
    299       1.1    jruoho     {
    300       1.1    jruoho         ACPI_FREE (Table);
    301       1.1    jruoho     }
    302       1.1    jruoho 
    303  1.1.1.11  christos     AcDeleteTableList (ListHead);
    304  1.1.1.11  christos 
    305   1.1.1.5  christos     if (File)
    306       1.1    jruoho     {
    307       1.1    jruoho         fclose (File);
    308       1.1    jruoho         AcpiOsRedirectOutput (stdout);
    309       1.1    jruoho     }
    310       1.1    jruoho 
    311       1.1    jruoho     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    312       1.1    jruoho     AcpiGbl_ParseOpRoot = NULL;
    313       1.1    jruoho     return (Status);
    314       1.1    jruoho }
    315       1.1    jruoho 
    316       1.1    jruoho 
    317       1.1    jruoho /******************************************************************************
    318       1.1    jruoho  *
    319   1.1.1.7  christos  * FUNCTION:    AdDisassembleOneTable
    320       1.1    jruoho  *
    321   1.1.1.7  christos  * PARAMETERS:  Table               - Raw AML table
    322   1.1.1.7  christos  *              File                - Pointer for the input file
    323   1.1.1.7  christos  *              Filename            - AML input filename
    324   1.1.1.7  christos  *              DisasmFilename      - Output filename
    325       1.1    jruoho  *
    326   1.1.1.7  christos  * RETURN:      Status
    327       1.1    jruoho  *
    328   1.1.1.7  christos  * DESCRIPTION: Disassemble a single ACPI table. AML or data table.
    329       1.1    jruoho  *
    330       1.1    jruoho  *****************************************************************************/
    331       1.1    jruoho 
    332   1.1.1.7  christos static ACPI_STATUS
    333   1.1.1.7  christos AdDisassembleOneTable (
    334   1.1.1.7  christos     ACPI_TABLE_HEADER       *Table,
    335   1.1.1.7  christos     FILE                    *File,
    336   1.1.1.5  christos     char                    *Filename,
    337   1.1.1.7  christos     char                    *DisasmFilename)
    338       1.1    jruoho {
    339   1.1.1.7  christos     ACPI_STATUS             Status;
    340   1.1.1.7  christos     ACPI_OWNER_ID           OwnerId;
    341       1.1    jruoho 
    342       1.1    jruoho 
    343  1.1.1.10  christos #ifdef ACPI_ASL_COMPILER
    344  1.1.1.10  christos 
    345  1.1.1.10  christos     /*
    346  1.1.1.10  christos      * For ASL-/ASL+ converter: replace the temporary "XXXX"
    347  1.1.1.10  christos      * table signature with the original. This "XXXX" makes
    348  1.1.1.10  christos      * it harder for the AML interpreter to run the badaml
    349  1.1.1.10  christos      * (.xxx) file produced from the converter in case if
    350  1.1.1.10  christos      * it fails to get deleted.
    351  1.1.1.10  christos      */
    352  1.1.1.12  christos     if (AcpiGbl_CaptureComments)
    353  1.1.1.10  christos     {
    354  1.1.1.14  christos         strncpy (Table->Signature, AcpiGbl_TableSig, ACPI_NAMESEG_SIZE);
    355  1.1.1.10  christos     }
    356  1.1.1.10  christos #endif
    357  1.1.1.10  christos 
    358   1.1.1.7  christos     /* ForceAmlDisassembly means to assume the table contains valid AML */
    359   1.1.1.5  christos 
    360   1.1.1.7  christos     if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table))
    361   1.1.1.5  christos     {
    362   1.1.1.7  christos         AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE);
    363       1.1    jruoho 
    364   1.1.1.7  christos         /* This is a "Data Table" (non-AML table) */
    365       1.1    jruoho 
    366   1.1.1.7  christos         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
    367   1.1.1.7  christos             Table->Signature);
    368   1.1.1.7  christos         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  "
    369   1.1.1.7  christos             "FieldName : FieldValue\n */\n\n");
    370       1.1    jruoho 
    371   1.1.1.7  christos         AcpiDmDumpDataTable (Table);
    372   1.1.1.7  christos         fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
    373   1.1.1.7  christos             Table->Signature);
    374       1.1    jruoho 
    375   1.1.1.7  christos         if (File)
    376   1.1.1.7  christos         {
    377   1.1.1.7  christos             fprintf (stderr, "Formatted output:  %s - %u bytes\n",
    378   1.1.1.7  christos                 DisasmFilename, CmGetFileSize (File));
    379   1.1.1.7  christos         }
    380       1.1    jruoho 
    381   1.1.1.7  christos         return (AE_OK);
    382   1.1.1.7  christos     }
    383       1.1    jruoho 
    384       1.1    jruoho     /*
    385   1.1.1.7  christos      * This is an AML table (DSDT or SSDT).
    386   1.1.1.7  christos      * Always parse the tables, only option is what to display
    387       1.1    jruoho      */
    388   1.1.1.7  christos     Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
    389   1.1.1.7  christos     if (ACPI_FAILURE (Status))
    390   1.1.1.7  christos     {
    391   1.1.1.7  christos         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    392   1.1.1.7  christos             AcpiFormatException (Status));
    393   1.1.1.7  christos         return (Status);
    394   1.1.1.7  christos     }
    395       1.1    jruoho 
    396   1.1.1.7  christos     /* Debug output, namespace and parse tree */
    397       1.1    jruoho 
    398   1.1.1.7  christos     if (AslCompilerdebug && File)
    399       1.1    jruoho     {
    400   1.1.1.7  christos         AcpiOsPrintf ("/**** Before second load\n");
    401   1.1.1.3  christos 
    402   1.1.1.7  christos         NsSetupNamespaceListing (File);
    403   1.1.1.7  christos         NsDisplayNamespace ();
    404       1.1    jruoho 
    405   1.1.1.7  christos         AcpiOsPrintf ("*****/\n");
    406   1.1.1.7  christos     }
    407   1.1.1.3  christos 
    408   1.1.1.7  christos     /* Load namespace from names created within control methods */
    409       1.1    jruoho 
    410   1.1.1.7  christos     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    411   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    412       1.1    jruoho 
    413   1.1.1.7  christos     /*
    414   1.1.1.7  christos      * Cross reference the namespace here, in order to
    415   1.1.1.7  christos      * generate External() statements
    416   1.1.1.7  christos      */
    417   1.1.1.7  christos     AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    418   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    419   1.1.1.3  christos 
    420   1.1.1.7  christos     if (AslCompilerdebug)
    421   1.1.1.7  christos     {
    422   1.1.1.7  christos         AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    423       1.1    jruoho     }
    424       1.1    jruoho 
    425   1.1.1.7  christos     /* Find possible calls to external control methods */
    426       1.1    jruoho 
    427   1.1.1.7  christos     AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
    428       1.1    jruoho 
    429   1.1.1.7  christos     /*
    430   1.1.1.7  christos      * If we found any external control methods, we must reparse
    431   1.1.1.7  christos      * the entire tree with the new information (namely, the
    432   1.1.1.7  christos      * number of arguments per method)
    433   1.1.1.7  christos      */
    434  1.1.1.11  christos     if (AcpiDmGetUnresolvedExternalMethodCount ())
    435       1.1    jruoho     {
    436   1.1.1.7  christos         Status = AdReparseOneTable (Table, File, OwnerId);
    437   1.1.1.7  christos         if (ACPI_FAILURE (Status))
    438   1.1.1.7  christos         {
    439   1.1.1.7  christos             return (Status);
    440   1.1.1.7  christos         }
    441       1.1    jruoho     }
    442       1.1    jruoho 
    443   1.1.1.7  christos     /*
    444   1.1.1.7  christos      * Now that the namespace is finalized, we can perform namespace
    445   1.1.1.7  christos      * transforms.
    446   1.1.1.7  christos      *
    447   1.1.1.7  christos      * 1) Convert fixed-offset references to resource descriptors
    448   1.1.1.7  christos      *    to symbolic references (Note: modifies namespace)
    449   1.1.1.7  christos      */
    450  1.1.1.11  christos     AcpiDmConvertParseObjects (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
    451       1.1    jruoho 
    452   1.1.1.7  christos     /* Optional displays */
    453       1.1    jruoho 
    454   1.1.1.7  christos     if (AcpiGbl_DmOpt_Disasm)
    455       1.1    jruoho     {
    456   1.1.1.7  christos         /* This is the real disassembly */
    457   1.1.1.7  christos 
    458   1.1.1.7  christos         AdDisplayTables (Filename, Table);
    459   1.1.1.7  christos 
    460   1.1.1.7  christos         /* Dump hex table if requested (-vt) */
    461   1.1.1.7  christos 
    462   1.1.1.7  christos         AcpiDmDumpDataTable (Table);
    463   1.1.1.7  christos 
    464   1.1.1.7  christos         fprintf (stderr, "Disassembly completed\n");
    465   1.1.1.7  christos         if (File)
    466   1.1.1.4  christos         {
    467   1.1.1.7  christos             fprintf (stderr, "ASL Output:    %s - %u bytes\n",
    468   1.1.1.7  christos                 DisasmFilename, CmGetFileSize (File));
    469   1.1.1.4  christos         }
    470   1.1.1.4  christos 
    471  1.1.1.13  christos         if (AslGbl_MapfileFlag)
    472   1.1.1.7  christos         {
    473   1.1.1.7  christos             fprintf (stderr, "%14s %s - %u bytes\n",
    474  1.1.1.14  christos                 AslGbl_FileDescs[ASL_FILE_MAP_OUTPUT].ShortDescription,
    475  1.1.1.13  christos                 AslGbl_Files[ASL_FILE_MAP_OUTPUT].Filename,
    476   1.1.1.7  christos                 FlGetFileSize (ASL_FILE_MAP_OUTPUT));
    477   1.1.1.7  christos         }
    478       1.1    jruoho     }
    479       1.1    jruoho 
    480   1.1.1.7  christos     return (AE_OK);
    481       1.1    jruoho }
    482       1.1    jruoho 
    483       1.1    jruoho 
    484       1.1    jruoho /******************************************************************************
    485       1.1    jruoho  *
    486   1.1.1.7  christos  * FUNCTION:    AdReparseOneTable
    487       1.1    jruoho  *
    488   1.1.1.7  christos  * PARAMETERS:  Table               - Raw AML table
    489   1.1.1.7  christos  *              File                - Pointer for the input file
    490   1.1.1.7  christos  *              OwnerId             - ID for this table
    491       1.1    jruoho  *
    492       1.1    jruoho  * RETURN:      Status
    493       1.1    jruoho  *
    494   1.1.1.7  christos  * DESCRIPTION: Reparse a table that has already been loaded. Used to
    495   1.1.1.7  christos  *              integrate information about external control methods.
    496   1.1.1.7  christos  *              These methods may have been previously parsed incorrectly.
    497       1.1    jruoho  *
    498       1.1    jruoho  *****************************************************************************/
    499       1.1    jruoho 
    500   1.1.1.7  christos static ACPI_STATUS
    501   1.1.1.7  christos AdReparseOneTable (
    502   1.1.1.7  christos     ACPI_TABLE_HEADER       *Table,
    503   1.1.1.7  christos     FILE                    *File,
    504   1.1.1.7  christos     ACPI_OWNER_ID           OwnerId)
    505       1.1    jruoho {
    506   1.1.1.7  christos     ACPI_STATUS             Status;
    507  1.1.1.10  christos     ACPI_COMMENT_ADDR_NODE  *AddrListHead;
    508       1.1    jruoho 
    509       1.1    jruoho 
    510   1.1.1.7  christos     fprintf (stderr,
    511   1.1.1.7  christos         "\nFound %u external control methods, "
    512   1.1.1.7  christos         "reparsing with new information\n",
    513  1.1.1.11  christos         AcpiDmGetUnresolvedExternalMethodCount ());
    514       1.1    jruoho 
    515   1.1.1.7  christos     /* Reparse, rebuild namespace */
    516       1.1    jruoho 
    517   1.1.1.7  christos     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    518   1.1.1.7  christos     AcpiGbl_ParseOpRoot = NULL;
    519   1.1.1.7  christos     AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
    520       1.1    jruoho 
    521   1.1.1.7  christos     AcpiGbl_RootNode                    = NULL;
    522   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
    523   1.1.1.7  christos     AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
    524   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
    525   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Parent       = NULL;
    526   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Child        = NULL;
    527   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Peer         = NULL;
    528   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Object       = NULL;
    529   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Flags        = 0;
    530       1.1    jruoho 
    531   1.1.1.7  christos     Status = AcpiNsRootInitialize ();
    532   1.1.1.7  christos     if (ACPI_FAILURE (Status))
    533   1.1.1.7  christos     {
    534   1.1.1.7  christos         return (Status);
    535       1.1    jruoho     }
    536       1.1    jruoho 
    537   1.1.1.7  christos     /* New namespace, add the external definitions first */
    538   1.1.1.5  christos 
    539  1.1.1.11  christos     AcpiDmAddExternalListToNamespace ();
    540   1.1.1.5  christos 
    541  1.1.1.10  christos     /* For -ca option: clear the list of comment addresses. */
    542  1.1.1.10  christos 
    543  1.1.1.10  christos     while (AcpiGbl_CommentAddrListHead)
    544  1.1.1.10  christos     {
    545  1.1.1.10  christos         AddrListHead= AcpiGbl_CommentAddrListHead;
    546  1.1.1.10  christos         AcpiGbl_CommentAddrListHead = AcpiGbl_CommentAddrListHead->Next;
    547  1.1.1.10  christos         AcpiOsFree(AddrListHead);
    548  1.1.1.10  christos     }
    549  1.1.1.10  christos 
    550   1.1.1.7  christos     /* Parse the table again. No need to reload it, however */
    551   1.1.1.5  christos 
    552   1.1.1.7  christos     Status = AdParseTable (Table, NULL, FALSE, FALSE);
    553   1.1.1.5  christos     if (ACPI_FAILURE (Status))
    554   1.1.1.5  christos     {
    555   1.1.1.7  christos         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    556   1.1.1.7  christos             AcpiFormatException (Status));
    557   1.1.1.5  christos         return (Status);
    558   1.1.1.5  christos     }
    559   1.1.1.5  christos 
    560   1.1.1.7  christos     /* Cross reference the namespace again */
    561       1.1    jruoho 
    562   1.1.1.7  christos     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    563   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    564       1.1    jruoho 
    565   1.1.1.7  christos     AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    566   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    567       1.1    jruoho 
    568   1.1.1.7  christos     /* Debug output - namespace and parse tree */
    569       1.1    jruoho 
    570   1.1.1.7  christos     if (AslCompilerdebug)
    571       1.1    jruoho     {
    572   1.1.1.7  christos         AcpiOsPrintf ("/**** After second load and resource conversion\n");
    573   1.1.1.7  christos         if (File)
    574   1.1.1.7  christos         {
    575   1.1.1.7  christos             NsSetupNamespaceListing (File);
    576   1.1.1.7  christos             NsDisplayNamespace ();
    577   1.1.1.7  christos         }
    578       1.1    jruoho 
    579   1.1.1.7  christos         AcpiOsPrintf ("*****/\n");
    580   1.1.1.7  christos         AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    581   1.1.1.4  christos     }
    582       1.1    jruoho 
    583   1.1.1.3  christos     return (AE_OK);
    584       1.1    jruoho }
    585       1.1    jruoho 
    586       1.1    jruoho 
    587       1.1    jruoho /******************************************************************************
    588       1.1    jruoho  *
    589   1.1.1.7  christos  * FUNCTION:    AdDoExternalFileList
    590       1.1    jruoho  *
    591   1.1.1.7  christos  * PARAMETERS:  Filename            - Input file for the table
    592       1.1    jruoho  *
    593       1.1    jruoho  * RETURN:      Status
    594       1.1    jruoho  *
    595   1.1.1.7  christos  * DESCRIPTION: Process all tables found in the -e external files list
    596       1.1    jruoho  *
    597       1.1    jruoho  *****************************************************************************/
    598       1.1    jruoho 
    599   1.1.1.7  christos static ACPI_STATUS
    600   1.1.1.7  christos AdDoExternalFileList (
    601   1.1.1.7  christos     char                    *Filename)
    602       1.1    jruoho {
    603   1.1.1.7  christos     ACPI_EXTERNAL_FILE      *ExternalFileList;
    604   1.1.1.7  christos     char                    *ExternalFilename;
    605   1.1.1.7  christos     ACPI_NEW_TABLE_DESC     *ExternalListHead = NULL;
    606   1.1.1.7  christos     ACPI_STATUS             Status;
    607   1.1.1.7  christos     ACPI_STATUS             GlobalStatus = AE_OK;
    608   1.1.1.7  christos     ACPI_OWNER_ID           OwnerId;
    609       1.1    jruoho 
    610       1.1    jruoho 
    611   1.1.1.7  christos     /*
    612   1.1.1.7  christos      * External filenames are specified on the command line like this:
    613   1.1.1.7  christos      * Example: iasl -e file1,file2,file3 -d xxx.aml
    614   1.1.1.7  christos      */
    615   1.1.1.7  christos     ExternalFileList = AcpiGbl_ExternalFileList;
    616       1.1    jruoho 
    617   1.1.1.7  christos     /* Process each external file */
    618       1.1    jruoho 
    619   1.1.1.7  christos     while (ExternalFileList)
    620       1.1    jruoho     {
    621   1.1.1.7  christos         ExternalFilename = ExternalFileList->Path;
    622   1.1.1.7  christos         if (!strcmp (ExternalFilename, Filename))
    623   1.1.1.7  christos         {
    624   1.1.1.7  christos             /* Next external file */
    625       1.1    jruoho 
    626   1.1.1.7  christos             ExternalFileList = ExternalFileList->Next;
    627   1.1.1.7  christos             continue;
    628   1.1.1.7  christos         }
    629       1.1    jruoho 
    630   1.1.1.7  christos         AcpiOsPrintf ("External object resolution file %16s\n",
    631   1.1.1.7  christos             ExternalFilename);
    632       1.1    jruoho 
    633   1.1.1.7  christos         Status = AcGetAllTablesFromFile (
    634   1.1.1.7  christos             ExternalFilename, ACPI_GET_ONLY_AML_TABLES, &ExternalListHead);
    635       1.1    jruoho         if (ACPI_FAILURE (Status))
    636       1.1    jruoho         {
    637   1.1.1.7  christos             if (Status == AE_TYPE)
    638   1.1.1.7  christos             {
    639   1.1.1.7  christos                 ExternalFileList = ExternalFileList->Next;
    640   1.1.1.7  christos                 GlobalStatus = AE_TYPE;
    641   1.1.1.7  christos                 Status = AE_OK;
    642   1.1.1.7  christos                 continue;
    643   1.1.1.7  christos             }
    644   1.1.1.7  christos 
    645  1.1.1.11  christos             AcDeleteTableList (ExternalListHead);
    646   1.1.1.3  christos             return (Status);
    647       1.1    jruoho         }
    648   1.1.1.7  christos 
    649   1.1.1.7  christos         /* Load external tables for symbol resolution */
    650   1.1.1.7  christos 
    651   1.1.1.7  christos         while (ExternalListHead)
    652       1.1    jruoho         {
    653   1.1.1.7  christos             Status = AdParseTable (
    654   1.1.1.7  christos                 ExternalListHead->Table, &OwnerId, TRUE, TRUE);
    655       1.1    jruoho             if (ACPI_FAILURE (Status))
    656       1.1    jruoho             {
    657   1.1.1.7  christos                 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
    658   1.1.1.7  christos                     AcpiFormatException (Status));
    659  1.1.1.11  christos                 AcDeleteTableList (ExternalListHead);
    660   1.1.1.3  christos                 return (Status);
    661       1.1    jruoho             }
    662   1.1.1.7  christos 
    663   1.1.1.7  christos             /*
    664   1.1.1.7  christos              * Load namespace from names created within control methods
    665   1.1.1.7  christos              * Set owner id of nodes in external table
    666   1.1.1.7  christos              */
    667   1.1.1.7  christos             AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    668   1.1.1.7  christos                 AcpiGbl_RootNode, OwnerId);
    669   1.1.1.7  christos             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    670   1.1.1.7  christos 
    671   1.1.1.7  christos             ExternalListHead = ExternalListHead->Next;
    672       1.1    jruoho         }
    673       1.1    jruoho 
    674   1.1.1.7  christos         /* Next external file */
    675       1.1    jruoho 
    676   1.1.1.7  christos         ExternalFileList = ExternalFileList->Next;
    677       1.1    jruoho     }
    678       1.1    jruoho 
    679  1.1.1.11  christos     AcDeleteTableList (ExternalListHead);
    680  1.1.1.11  christos 
    681   1.1.1.7  christos     if (ACPI_FAILURE (GlobalStatus))
    682       1.1    jruoho     {
    683   1.1.1.7  christos         return (GlobalStatus);
    684       1.1    jruoho     }
    685       1.1    jruoho 
    686   1.1.1.7  christos     /* Clear external list generated by Scope in external tables */
    687       1.1    jruoho 
    688   1.1.1.7  christos     if (AcpiGbl_ExternalFileList)
    689   1.1.1.7  christos     {
    690   1.1.1.7  christos         AcpiDmClearExternalList ();
    691   1.1.1.7  christos     }
    692       1.1    jruoho 
    693   1.1.1.7  christos     /* Load any externals defined in the optional external ref file */
    694       1.1    jruoho 
    695   1.1.1.7  christos     AcpiDmGetExternalsFromFile ();
    696   1.1.1.3  christos     return (AE_OK);
    697       1.1    jruoho }
    698