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