Home | History | Annotate | Line # | Download | only in common
adisasm.c revision 1.1.1.10
      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.9  christos  * Copyright (C) 2000 - 2017, 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.5  christos     if (File)
    304       1.1    jruoho     {
    305       1.1    jruoho         fclose (File);
    306       1.1    jruoho         AcpiOsRedirectOutput (stdout);
    307       1.1    jruoho     }
    308       1.1    jruoho 
    309       1.1    jruoho     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    310       1.1    jruoho     AcpiGbl_ParseOpRoot = NULL;
    311       1.1    jruoho     return (Status);
    312       1.1    jruoho }
    313       1.1    jruoho 
    314       1.1    jruoho 
    315       1.1    jruoho /******************************************************************************
    316       1.1    jruoho  *
    317   1.1.1.7  christos  * FUNCTION:    AdDisassembleOneTable
    318       1.1    jruoho  *
    319   1.1.1.7  christos  * PARAMETERS:  Table               - Raw AML table
    320   1.1.1.7  christos  *              File                - Pointer for the input file
    321   1.1.1.7  christos  *              Filename            - AML input filename
    322   1.1.1.7  christos  *              DisasmFilename      - Output filename
    323       1.1    jruoho  *
    324   1.1.1.7  christos  * RETURN:      Status
    325       1.1    jruoho  *
    326   1.1.1.7  christos  * DESCRIPTION: Disassemble a single ACPI table. AML or data table.
    327       1.1    jruoho  *
    328       1.1    jruoho  *****************************************************************************/
    329       1.1    jruoho 
    330   1.1.1.7  christos static ACPI_STATUS
    331   1.1.1.7  christos AdDisassembleOneTable (
    332   1.1.1.7  christos     ACPI_TABLE_HEADER       *Table,
    333   1.1.1.7  christos     FILE                    *File,
    334   1.1.1.5  christos     char                    *Filename,
    335   1.1.1.7  christos     char                    *DisasmFilename)
    336       1.1    jruoho {
    337   1.1.1.7  christos     ACPI_STATUS             Status;
    338   1.1.1.7  christos     ACPI_OWNER_ID           OwnerId;
    339       1.1    jruoho 
    340       1.1    jruoho 
    341  1.1.1.10  christos #ifdef ACPI_ASL_COMPILER
    342  1.1.1.10  christos 
    343  1.1.1.10  christos     /*
    344  1.1.1.10  christos      * For ASL-/ASL+ converter: replace the temporary "XXXX"
    345  1.1.1.10  christos      * table signature with the original. This "XXXX" makes
    346  1.1.1.10  christos      * it harder for the AML interpreter to run the badaml
    347  1.1.1.10  christos      * (.xxx) file produced from the converter in case if
    348  1.1.1.10  christos      * it fails to get deleted.
    349  1.1.1.10  christos      */
    350  1.1.1.10  christos     if (Gbl_CaptureComments)
    351  1.1.1.10  christos     {
    352  1.1.1.10  christos         strncpy (Table->Signature, AcpiGbl_TableSig, 4);
    353  1.1.1.10  christos     }
    354  1.1.1.10  christos #endif
    355  1.1.1.10  christos 
    356   1.1.1.7  christos     /* ForceAmlDisassembly means to assume the table contains valid AML */
    357   1.1.1.5  christos 
    358   1.1.1.7  christos     if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table))
    359   1.1.1.5  christos     {
    360   1.1.1.7  christos         AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE);
    361       1.1    jruoho 
    362   1.1.1.7  christos         /* This is a "Data Table" (non-AML table) */
    363       1.1    jruoho 
    364   1.1.1.7  christos         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
    365   1.1.1.7  christos             Table->Signature);
    366   1.1.1.7  christos         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  "
    367   1.1.1.7  christos             "FieldName : FieldValue\n */\n\n");
    368       1.1    jruoho 
    369   1.1.1.7  christos         AcpiDmDumpDataTable (Table);
    370   1.1.1.7  christos         fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
    371   1.1.1.7  christos             Table->Signature);
    372       1.1    jruoho 
    373   1.1.1.7  christos         if (File)
    374   1.1.1.7  christos         {
    375   1.1.1.7  christos             fprintf (stderr, "Formatted output:  %s - %u bytes\n",
    376   1.1.1.7  christos                 DisasmFilename, CmGetFileSize (File));
    377   1.1.1.7  christos         }
    378       1.1    jruoho 
    379   1.1.1.7  christos         return (AE_OK);
    380   1.1.1.7  christos     }
    381       1.1    jruoho 
    382       1.1    jruoho     /*
    383   1.1.1.7  christos      * This is an AML table (DSDT or SSDT).
    384   1.1.1.7  christos      * Always parse the tables, only option is what to display
    385       1.1    jruoho      */
    386   1.1.1.7  christos     Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
    387   1.1.1.7  christos     if (ACPI_FAILURE (Status))
    388   1.1.1.7  christos     {
    389   1.1.1.7  christos         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    390   1.1.1.7  christos             AcpiFormatException (Status));
    391   1.1.1.7  christos         return (Status);
    392   1.1.1.7  christos     }
    393       1.1    jruoho 
    394   1.1.1.7  christos     /* Debug output, namespace and parse tree */
    395       1.1    jruoho 
    396   1.1.1.7  christos     if (AslCompilerdebug && File)
    397       1.1    jruoho     {
    398   1.1.1.7  christos         AcpiOsPrintf ("/**** Before second load\n");
    399   1.1.1.3  christos 
    400   1.1.1.7  christos         NsSetupNamespaceListing (File);
    401   1.1.1.7  christos         NsDisplayNamespace ();
    402       1.1    jruoho 
    403   1.1.1.7  christos         AcpiOsPrintf ("*****/\n");
    404   1.1.1.7  christos     }
    405   1.1.1.3  christos 
    406   1.1.1.7  christos     /* Load namespace from names created within control methods */
    407       1.1    jruoho 
    408   1.1.1.7  christos     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    409   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    410       1.1    jruoho 
    411   1.1.1.7  christos     /*
    412   1.1.1.7  christos      * Cross reference the namespace here, in order to
    413   1.1.1.7  christos      * generate External() statements
    414   1.1.1.7  christos      */
    415   1.1.1.7  christos     AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    416   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    417   1.1.1.3  christos 
    418   1.1.1.7  christos     if (AslCompilerdebug)
    419   1.1.1.7  christos     {
    420   1.1.1.7  christos         AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    421       1.1    jruoho     }
    422       1.1    jruoho 
    423   1.1.1.7  christos     /* Find possible calls to external control methods */
    424       1.1    jruoho 
    425   1.1.1.7  christos     AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
    426       1.1    jruoho 
    427   1.1.1.7  christos     /*
    428   1.1.1.7  christos      * If we found any external control methods, we must reparse
    429   1.1.1.7  christos      * the entire tree with the new information (namely, the
    430   1.1.1.7  christos      * number of arguments per method)
    431   1.1.1.7  christos      */
    432   1.1.1.7  christos     if (AcpiDmGetExternalMethodCount ())
    433       1.1    jruoho     {
    434   1.1.1.7  christos         Status = AdReparseOneTable (Table, File, OwnerId);
    435   1.1.1.7  christos         if (ACPI_FAILURE (Status))
    436   1.1.1.7  christos         {
    437   1.1.1.7  christos             return (Status);
    438   1.1.1.7  christos         }
    439       1.1    jruoho     }
    440       1.1    jruoho 
    441   1.1.1.7  christos     /*
    442   1.1.1.7  christos      * Now that the namespace is finalized, we can perform namespace
    443   1.1.1.7  christos      * transforms.
    444   1.1.1.7  christos      *
    445   1.1.1.7  christos      * 1) Convert fixed-offset references to resource descriptors
    446   1.1.1.7  christos      *    to symbolic references (Note: modifies namespace)
    447   1.1.1.7  christos      */
    448   1.1.1.7  christos     AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
    449       1.1    jruoho 
    450   1.1.1.7  christos     /* Optional displays */
    451       1.1    jruoho 
    452   1.1.1.7  christos     if (AcpiGbl_DmOpt_Disasm)
    453       1.1    jruoho     {
    454   1.1.1.7  christos         /* This is the real disassembly */
    455   1.1.1.7  christos 
    456   1.1.1.7  christos         AdDisplayTables (Filename, Table);
    457   1.1.1.7  christos 
    458   1.1.1.7  christos         /* Dump hex table if requested (-vt) */
    459   1.1.1.7  christos 
    460   1.1.1.7  christos         AcpiDmDumpDataTable (Table);
    461   1.1.1.7  christos 
    462   1.1.1.7  christos         fprintf (stderr, "Disassembly completed\n");
    463   1.1.1.7  christos         if (File)
    464   1.1.1.4  christos         {
    465   1.1.1.7  christos             fprintf (stderr, "ASL Output:    %s - %u bytes\n",
    466   1.1.1.7  christos                 DisasmFilename, CmGetFileSize (File));
    467   1.1.1.4  christos         }
    468   1.1.1.4  christos 
    469   1.1.1.7  christos         if (Gbl_MapfileFlag)
    470   1.1.1.7  christos         {
    471   1.1.1.7  christos             fprintf (stderr, "%14s %s - %u bytes\n",
    472   1.1.1.7  christos                 Gbl_Files[ASL_FILE_MAP_OUTPUT].ShortDescription,
    473   1.1.1.7  christos                 Gbl_Files[ASL_FILE_MAP_OUTPUT].Filename,
    474   1.1.1.7  christos                 FlGetFileSize (ASL_FILE_MAP_OUTPUT));
    475   1.1.1.7  christos         }
    476       1.1    jruoho     }
    477       1.1    jruoho 
    478   1.1.1.7  christos     return (AE_OK);
    479       1.1    jruoho }
    480       1.1    jruoho 
    481       1.1    jruoho 
    482       1.1    jruoho /******************************************************************************
    483       1.1    jruoho  *
    484   1.1.1.7  christos  * FUNCTION:    AdReparseOneTable
    485       1.1    jruoho  *
    486   1.1.1.7  christos  * PARAMETERS:  Table               - Raw AML table
    487   1.1.1.7  christos  *              File                - Pointer for the input file
    488   1.1.1.7  christos  *              OwnerId             - ID for this table
    489       1.1    jruoho  *
    490       1.1    jruoho  * RETURN:      Status
    491       1.1    jruoho  *
    492   1.1.1.7  christos  * DESCRIPTION: Reparse a table that has already been loaded. Used to
    493   1.1.1.7  christos  *              integrate information about external control methods.
    494   1.1.1.7  christos  *              These methods may have been previously parsed incorrectly.
    495       1.1    jruoho  *
    496       1.1    jruoho  *****************************************************************************/
    497       1.1    jruoho 
    498   1.1.1.7  christos static ACPI_STATUS
    499   1.1.1.7  christos AdReparseOneTable (
    500   1.1.1.7  christos     ACPI_TABLE_HEADER       *Table,
    501   1.1.1.7  christos     FILE                    *File,
    502   1.1.1.7  christos     ACPI_OWNER_ID           OwnerId)
    503       1.1    jruoho {
    504   1.1.1.7  christos     ACPI_STATUS             Status;
    505  1.1.1.10  christos     ACPI_COMMENT_ADDR_NODE  *AddrListHead;
    506       1.1    jruoho 
    507       1.1    jruoho 
    508   1.1.1.7  christos     fprintf (stderr,
    509   1.1.1.7  christos         "\nFound %u external control methods, "
    510   1.1.1.7  christos         "reparsing with new information\n",
    511   1.1.1.7  christos         AcpiDmGetExternalMethodCount ());
    512       1.1    jruoho 
    513   1.1.1.7  christos     /* Reparse, rebuild namespace */
    514       1.1    jruoho 
    515   1.1.1.7  christos     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    516   1.1.1.7  christos     AcpiGbl_ParseOpRoot = NULL;
    517   1.1.1.7  christos     AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
    518       1.1    jruoho 
    519   1.1.1.7  christos     AcpiGbl_RootNode                    = NULL;
    520   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
    521   1.1.1.7  christos     AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
    522   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
    523   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Parent       = NULL;
    524   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Child        = NULL;
    525   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Peer         = NULL;
    526   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Object       = NULL;
    527   1.1.1.7  christos     AcpiGbl_RootNodeStruct.Flags        = 0;
    528       1.1    jruoho 
    529   1.1.1.7  christos     Status = AcpiNsRootInitialize ();
    530   1.1.1.7  christos     if (ACPI_FAILURE (Status))
    531   1.1.1.7  christos     {
    532   1.1.1.7  christos         return (Status);
    533       1.1    jruoho     }
    534       1.1    jruoho 
    535   1.1.1.7  christos     /* New namespace, add the external definitions first */
    536   1.1.1.5  christos 
    537   1.1.1.7  christos     AcpiDmAddExternalsToNamespace ();
    538   1.1.1.5  christos 
    539  1.1.1.10  christos     /* For -ca option: clear the list of comment addresses. */
    540  1.1.1.10  christos 
    541  1.1.1.10  christos     while (AcpiGbl_CommentAddrListHead)
    542  1.1.1.10  christos     {
    543  1.1.1.10  christos         AddrListHead= AcpiGbl_CommentAddrListHead;
    544  1.1.1.10  christos         AcpiGbl_CommentAddrListHead = AcpiGbl_CommentAddrListHead->Next;
    545  1.1.1.10  christos         AcpiOsFree(AddrListHead);
    546  1.1.1.10  christos     }
    547  1.1.1.10  christos 
    548   1.1.1.7  christos     /* Parse the table again. No need to reload it, however */
    549   1.1.1.5  christos 
    550   1.1.1.7  christos     Status = AdParseTable (Table, NULL, FALSE, FALSE);
    551   1.1.1.5  christos     if (ACPI_FAILURE (Status))
    552   1.1.1.5  christos     {
    553   1.1.1.7  christos         AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    554   1.1.1.7  christos             AcpiFormatException (Status));
    555   1.1.1.5  christos         return (Status);
    556   1.1.1.5  christos     }
    557   1.1.1.5  christos 
    558   1.1.1.7  christos     /* Cross reference the namespace again */
    559       1.1    jruoho 
    560   1.1.1.7  christos     AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    561   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    562       1.1    jruoho 
    563   1.1.1.7  christos     AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    564   1.1.1.7  christos         AcpiGbl_RootNode, OwnerId);
    565       1.1    jruoho 
    566   1.1.1.7  christos     /* Debug output - namespace and parse tree */
    567       1.1    jruoho 
    568   1.1.1.7  christos     if (AslCompilerdebug)
    569       1.1    jruoho     {
    570   1.1.1.7  christos         AcpiOsPrintf ("/**** After second load and resource conversion\n");
    571   1.1.1.7  christos         if (File)
    572   1.1.1.7  christos         {
    573   1.1.1.7  christos             NsSetupNamespaceListing (File);
    574   1.1.1.7  christos             NsDisplayNamespace ();
    575   1.1.1.7  christos         }
    576       1.1    jruoho 
    577   1.1.1.7  christos         AcpiOsPrintf ("*****/\n");
    578   1.1.1.7  christos         AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    579   1.1.1.4  christos     }
    580       1.1    jruoho 
    581   1.1.1.3  christos     return (AE_OK);
    582       1.1    jruoho }
    583       1.1    jruoho 
    584       1.1    jruoho 
    585       1.1    jruoho /******************************************************************************
    586       1.1    jruoho  *
    587   1.1.1.7  christos  * FUNCTION:    AdDoExternalFileList
    588       1.1    jruoho  *
    589   1.1.1.7  christos  * PARAMETERS:  Filename            - Input file for the table
    590       1.1    jruoho  *
    591       1.1    jruoho  * RETURN:      Status
    592       1.1    jruoho  *
    593   1.1.1.7  christos  * DESCRIPTION: Process all tables found in the -e external files list
    594       1.1    jruoho  *
    595       1.1    jruoho  *****************************************************************************/
    596       1.1    jruoho 
    597   1.1.1.7  christos static ACPI_STATUS
    598   1.1.1.7  christos AdDoExternalFileList (
    599   1.1.1.7  christos     char                    *Filename)
    600       1.1    jruoho {
    601   1.1.1.7  christos     ACPI_EXTERNAL_FILE      *ExternalFileList;
    602   1.1.1.7  christos     char                    *ExternalFilename;
    603   1.1.1.7  christos     ACPI_NEW_TABLE_DESC     *ExternalListHead = NULL;
    604   1.1.1.7  christos     ACPI_STATUS             Status;
    605   1.1.1.7  christos     ACPI_STATUS             GlobalStatus = AE_OK;
    606   1.1.1.7  christos     ACPI_OWNER_ID           OwnerId;
    607       1.1    jruoho 
    608       1.1    jruoho 
    609   1.1.1.7  christos     /*
    610   1.1.1.7  christos      * External filenames are specified on the command line like this:
    611   1.1.1.7  christos      * Example: iasl -e file1,file2,file3 -d xxx.aml
    612   1.1.1.7  christos      */
    613   1.1.1.7  christos     ExternalFileList = AcpiGbl_ExternalFileList;
    614       1.1    jruoho 
    615   1.1.1.7  christos     /* Process each external file */
    616       1.1    jruoho 
    617   1.1.1.7  christos     while (ExternalFileList)
    618       1.1    jruoho     {
    619   1.1.1.7  christos         ExternalFilename = ExternalFileList->Path;
    620   1.1.1.7  christos         if (!strcmp (ExternalFilename, Filename))
    621   1.1.1.7  christos         {
    622   1.1.1.7  christos             /* Next external file */
    623       1.1    jruoho 
    624   1.1.1.7  christos             ExternalFileList = ExternalFileList->Next;
    625   1.1.1.7  christos             continue;
    626   1.1.1.7  christos         }
    627       1.1    jruoho 
    628   1.1.1.7  christos         AcpiOsPrintf ("External object resolution file %16s\n",
    629   1.1.1.7  christos             ExternalFilename);
    630       1.1    jruoho 
    631   1.1.1.7  christos         Status = AcGetAllTablesFromFile (
    632   1.1.1.7  christos             ExternalFilename, ACPI_GET_ONLY_AML_TABLES, &ExternalListHead);
    633       1.1    jruoho         if (ACPI_FAILURE (Status))
    634       1.1    jruoho         {
    635   1.1.1.7  christos             if (Status == AE_TYPE)
    636   1.1.1.7  christos             {
    637   1.1.1.7  christos                 ExternalFileList = ExternalFileList->Next;
    638   1.1.1.7  christos                 GlobalStatus = AE_TYPE;
    639   1.1.1.7  christos                 Status = AE_OK;
    640   1.1.1.7  christos                 continue;
    641   1.1.1.7  christos             }
    642   1.1.1.7  christos 
    643   1.1.1.3  christos             return (Status);
    644       1.1    jruoho         }
    645   1.1.1.7  christos 
    646   1.1.1.7  christos         /* Load external tables for symbol resolution */
    647   1.1.1.7  christos 
    648   1.1.1.7  christos         while (ExternalListHead)
    649       1.1    jruoho         {
    650   1.1.1.7  christos             Status = AdParseTable (
    651   1.1.1.7  christos                 ExternalListHead->Table, &OwnerId, TRUE, TRUE);
    652       1.1    jruoho             if (ACPI_FAILURE (Status))
    653       1.1    jruoho             {
    654   1.1.1.7  christos                 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
    655   1.1.1.7  christos                     AcpiFormatException (Status));
    656   1.1.1.3  christos                 return (Status);
    657       1.1    jruoho             }
    658   1.1.1.7  christos 
    659   1.1.1.7  christos             /*
    660   1.1.1.7  christos              * Load namespace from names created within control methods
    661   1.1.1.7  christos              * Set owner id of nodes in external table
    662   1.1.1.7  christos              */
    663   1.1.1.7  christos             AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    664   1.1.1.7  christos                 AcpiGbl_RootNode, OwnerId);
    665   1.1.1.7  christos             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    666   1.1.1.7  christos 
    667   1.1.1.7  christos             ExternalListHead = ExternalListHead->Next;
    668       1.1    jruoho         }
    669       1.1    jruoho 
    670   1.1.1.7  christos         /* Next external file */
    671       1.1    jruoho 
    672   1.1.1.7  christos         ExternalFileList = ExternalFileList->Next;
    673       1.1    jruoho     }
    674       1.1    jruoho 
    675   1.1.1.7  christos     if (ACPI_FAILURE (GlobalStatus))
    676       1.1    jruoho     {
    677   1.1.1.7  christos         return (GlobalStatus);
    678       1.1    jruoho     }
    679       1.1    jruoho 
    680   1.1.1.7  christos     /* Clear external list generated by Scope in external tables */
    681       1.1    jruoho 
    682   1.1.1.7  christos     if (AcpiGbl_ExternalFileList)
    683   1.1.1.7  christos     {
    684   1.1.1.7  christos         AcpiDmClearExternalList ();
    685   1.1.1.7  christos     }
    686       1.1    jruoho 
    687   1.1.1.7  christos     /* Load any externals defined in the optional external ref file */
    688       1.1    jruoho 
    689   1.1.1.7  christos     AcpiDmGetExternalsFromFile ();
    690   1.1.1.3  christos     return (AE_OK);
    691       1.1    jruoho }
    692