Home | History | Annotate | Line # | Download | only in common
adisasm.c revision 1.1.1.4.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.4.2.1     skrll  * Copyright (C) 2000 - 2015, 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 "acparser.h"
     46          1.1    jruoho #include "amlcode.h"
     47          1.1    jruoho #include "acdisasm.h"
     48          1.1    jruoho #include "acdispat.h"
     49          1.1    jruoho #include "acnamesp.h"
     50          1.1    jruoho #include "actables.h"
     51          1.1    jruoho #include "acapps.h"
     52          1.1    jruoho 
     53          1.1    jruoho #include <stdio.h>
     54          1.1    jruoho #include <time.h>
     55          1.1    jruoho 
     56          1.1    jruoho 
     57          1.1    jruoho #define _COMPONENT          ACPI_TOOLS
     58          1.1    jruoho         ACPI_MODULE_NAME    ("adisasm")
     59          1.1    jruoho 
     60          1.1    jruoho /* Local prototypes */
     61          1.1    jruoho 
     62      1.1.1.2    jruoho static void
     63          1.1    jruoho AdCreateTableHeader (
     64          1.1    jruoho     char                    *Filename,
     65          1.1    jruoho     ACPI_TABLE_HEADER       *Table);
     66          1.1    jruoho 
     67  1.1.1.4.2.1     skrll static ACPI_STATUS
     68  1.1.1.4.2.1     skrll AdStoreTable (
     69  1.1.1.4.2.1     skrll     ACPI_TABLE_HEADER       *Table,
     70  1.1.1.4.2.1     skrll     UINT32                  *TableIndex);
     71  1.1.1.4.2.1     skrll 
     72          1.1    jruoho /* Stubs for ASL compiler */
     73          1.1    jruoho 
     74          1.1    jruoho #ifndef ACPI_ASL_COMPILER
     75          1.1    jruoho BOOLEAN
     76          1.1    jruoho AcpiDsIsResultUsed (
     77          1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
     78          1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     79          1.1    jruoho {
     80          1.1    jruoho     return TRUE;
     81          1.1    jruoho }
     82          1.1    jruoho 
     83          1.1    jruoho ACPI_STATUS
     84          1.1    jruoho AcpiDsMethodError (
     85          1.1    jruoho     ACPI_STATUS             Status,
     86          1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     87          1.1    jruoho {
     88          1.1    jruoho     return (Status);
     89          1.1    jruoho }
     90          1.1    jruoho #endif
     91          1.1    jruoho 
     92          1.1    jruoho ACPI_STATUS
     93          1.1    jruoho AcpiNsLoadTable (
     94          1.1    jruoho     UINT32                  TableIndex,
     95          1.1    jruoho     ACPI_NAMESPACE_NODE     *Node)
     96          1.1    jruoho {
     97          1.1    jruoho     return (AE_NOT_IMPLEMENTED);
     98          1.1    jruoho }
     99          1.1    jruoho 
    100          1.1    jruoho ACPI_STATUS
    101          1.1    jruoho AcpiDsRestartControlMethod (
    102          1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    103          1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc)
    104          1.1    jruoho {
    105          1.1    jruoho     return (AE_OK);
    106          1.1    jruoho }
    107          1.1    jruoho 
    108          1.1    jruoho void
    109          1.1    jruoho AcpiDsTerminateControlMethod (
    110          1.1    jruoho     ACPI_OPERAND_OBJECT     *MethodDesc,
    111          1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    112          1.1    jruoho {
    113          1.1    jruoho     return;
    114          1.1    jruoho }
    115          1.1    jruoho 
    116          1.1    jruoho ACPI_STATUS
    117          1.1    jruoho AcpiDsCallControlMethod (
    118          1.1    jruoho     ACPI_THREAD_STATE       *Thread,
    119          1.1    jruoho     ACPI_WALK_STATE         *WalkState,
    120          1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    121          1.1    jruoho {
    122          1.1    jruoho     return (AE_OK);
    123          1.1    jruoho }
    124          1.1    jruoho 
    125          1.1    jruoho ACPI_STATUS
    126          1.1    jruoho AcpiDsMethodDataInitArgs (
    127          1.1    jruoho     ACPI_OPERAND_OBJECT     **Params,
    128          1.1    jruoho     UINT32                  MaxParamCount,
    129          1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    130          1.1    jruoho {
    131          1.1    jruoho     return (AE_OK);
    132          1.1    jruoho }
    133          1.1    jruoho 
    134          1.1    jruoho 
    135          1.1    jruoho static ACPI_TABLE_DESC      LocalTables[1];
    136      1.1.1.4  christos ACPI_PARSE_OBJECT    *AcpiGbl_ParseOpRoot;
    137      1.1.1.3  christos 
    138      1.1.1.3  christos 
    139      1.1.1.3  christos /*******************************************************************************
    140      1.1.1.3  christos  *
    141          1.1    jruoho  * FUNCTION:    AdInitialize
    142          1.1    jruoho  *
    143          1.1    jruoho  * PARAMETERS:  None
    144          1.1    jruoho  *
    145          1.1    jruoho  * RETURN:      Status
    146          1.1    jruoho  *
    147          1.1    jruoho  * DESCRIPTION: ACPICA and local initialization
    148          1.1    jruoho  *
    149          1.1    jruoho  ******************************************************************************/
    150          1.1    jruoho 
    151          1.1    jruoho ACPI_STATUS
    152          1.1    jruoho AdInitialize (
    153          1.1    jruoho     void)
    154          1.1    jruoho {
    155          1.1    jruoho     ACPI_STATUS             Status;
    156          1.1    jruoho 
    157          1.1    jruoho 
    158      1.1.1.4  christos     /* ACPICA subsystem initialization */
    159          1.1    jruoho 
    160          1.1    jruoho     Status = AcpiOsInitialize ();
    161          1.1    jruoho     if (ACPI_FAILURE (Status))
    162          1.1    jruoho     {
    163          1.1    jruoho         return (Status);
    164          1.1    jruoho     }
    165          1.1    jruoho 
    166          1.1    jruoho     Status = AcpiUtInitGlobals ();
    167          1.1    jruoho     if (ACPI_FAILURE (Status))
    168          1.1    jruoho     {
    169          1.1    jruoho         return (Status);
    170          1.1    jruoho     }
    171          1.1    jruoho 
    172          1.1    jruoho     Status = AcpiUtMutexInitialize ();
    173          1.1    jruoho     if (ACPI_FAILURE (Status))
    174          1.1    jruoho     {
    175          1.1    jruoho         return (Status);
    176          1.1    jruoho     }
    177          1.1    jruoho 
    178          1.1    jruoho     Status = AcpiNsRootInitialize ();
    179          1.1    jruoho     if (ACPI_FAILURE (Status))
    180          1.1    jruoho     {
    181          1.1    jruoho         return (Status);
    182          1.1    jruoho     }
    183          1.1    jruoho 
    184          1.1    jruoho     /* Setup the Table Manager (cheat - there is no RSDT) */
    185          1.1    jruoho 
    186          1.1    jruoho     AcpiGbl_RootTableList.MaxTableCount = 1;
    187          1.1    jruoho     AcpiGbl_RootTableList.CurrentTableCount = 0;
    188          1.1    jruoho     AcpiGbl_RootTableList.Tables = LocalTables;
    189          1.1    jruoho 
    190  1.1.1.4.2.2     skrll     AcpiGbl_PreviousOp = NULL;
    191          1.1    jruoho     return (Status);
    192          1.1    jruoho }
    193          1.1    jruoho 
    194          1.1    jruoho 
    195          1.1    jruoho /******************************************************************************
    196          1.1    jruoho  *
    197          1.1    jruoho  * FUNCTION:    AdAmlDisassemble
    198          1.1    jruoho  *
    199          1.1    jruoho  * PARAMETERS:  Filename            - AML input filename
    200          1.1    jruoho  *              OutToFile           - TRUE if output should go to a file
    201          1.1    jruoho  *              Prefix              - Path prefix for output
    202          1.1    jruoho  *              OutFilename         - where the filename is returned
    203          1.1    jruoho  *
    204          1.1    jruoho  * RETURN:      Status
    205          1.1    jruoho  *
    206          1.1    jruoho  * DESCRIPTION: Disassemble an entire ACPI table
    207          1.1    jruoho  *
    208          1.1    jruoho  *****************************************************************************/
    209          1.1    jruoho 
    210          1.1    jruoho ACPI_STATUS
    211          1.1    jruoho AdAmlDisassemble (
    212          1.1    jruoho     BOOLEAN                 OutToFile,
    213          1.1    jruoho     char                    *Filename,
    214          1.1    jruoho     char                    *Prefix,
    215      1.1.1.4  christos     char                    **OutFilename)
    216          1.1    jruoho {
    217          1.1    jruoho     ACPI_STATUS             Status;
    218  1.1.1.4.2.2     skrll     ACPI_STATUS             GlobalStatus = AE_OK;
    219          1.1    jruoho     char                    *DisasmFilename = NULL;
    220          1.1    jruoho     char                    *ExternalFilename;
    221      1.1.1.2    jruoho     ACPI_EXTERNAL_FILE      *ExternalFileList = AcpiGbl_ExternalFileList;
    222          1.1    jruoho     FILE                    *File = NULL;
    223          1.1    jruoho     ACPI_TABLE_HEADER       *Table = NULL;
    224          1.1    jruoho     ACPI_TABLE_HEADER       *ExternalTable;
    225          1.1    jruoho     ACPI_OWNER_ID           OwnerId;
    226          1.1    jruoho 
    227          1.1    jruoho 
    228          1.1    jruoho     /*
    229          1.1    jruoho      * Input: AML code from either a file or via GetTables (memory or
    230          1.1    jruoho      * registry)
    231          1.1    jruoho      */
    232          1.1    jruoho     if (Filename)
    233          1.1    jruoho     {
    234  1.1.1.4.2.2     skrll         Status = AcpiDbGetTableFromFile (Filename, &Table, FALSE);
    235          1.1    jruoho         if (ACPI_FAILURE (Status))
    236          1.1    jruoho         {
    237      1.1.1.3  christos             return (Status);
    238          1.1    jruoho         }
    239          1.1    jruoho 
    240          1.1    jruoho         /*
    241          1.1    jruoho          * External filenames separated by commas
    242          1.1    jruoho          * Example: iasl -e file1,file2,file3 -d xxx.aml
    243          1.1    jruoho          */
    244      1.1.1.2    jruoho         while (ExternalFileList)
    245          1.1    jruoho         {
    246      1.1.1.2    jruoho             ExternalFilename = ExternalFileList->Path;
    247  1.1.1.4.2.2     skrll             if (!strcmp (ExternalFilename, Filename))
    248      1.1.1.2    jruoho             {
    249      1.1.1.2    jruoho                 /* Next external file */
    250      1.1.1.2    jruoho 
    251      1.1.1.2    jruoho                 ExternalFileList = ExternalFileList->Next;
    252      1.1.1.2    jruoho                 continue;
    253      1.1.1.2    jruoho             }
    254          1.1    jruoho 
    255  1.1.1.4.2.2     skrll             Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable, TRUE);
    256      1.1.1.2    jruoho             if (ACPI_FAILURE (Status))
    257      1.1.1.2    jruoho             {
    258  1.1.1.4.2.2     skrll                 if (Status == AE_TYPE)
    259  1.1.1.4.2.2     skrll                 {
    260  1.1.1.4.2.2     skrll                     ExternalFileList = ExternalFileList->Next;
    261  1.1.1.4.2.2     skrll                     GlobalStatus = AE_TYPE;
    262  1.1.1.4.2.2     skrll                     Status = AE_OK;
    263  1.1.1.4.2.2     skrll                     continue;
    264  1.1.1.4.2.2     skrll                 }
    265      1.1.1.3  christos                 return (Status);
    266      1.1.1.2    jruoho             }
    267      1.1.1.2    jruoho 
    268      1.1.1.2    jruoho             /* Load external table for symbol resolution */
    269      1.1.1.2    jruoho 
    270      1.1.1.2    jruoho             if (ExternalTable)
    271          1.1    jruoho             {
    272      1.1.1.2    jruoho                 Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
    273          1.1    jruoho                 if (ACPI_FAILURE (Status))
    274          1.1    jruoho                 {
    275      1.1.1.2    jruoho                     AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
    276      1.1.1.2    jruoho                         AcpiFormatException (Status));
    277      1.1.1.3  christos                     return (Status);
    278          1.1    jruoho                 }
    279          1.1    jruoho 
    280      1.1.1.2    jruoho                 /*
    281      1.1.1.2    jruoho                  * Load namespace from names created within control methods
    282      1.1.1.2    jruoho                  * Set owner id of nodes in external table
    283      1.1.1.2    jruoho                  */
    284      1.1.1.2    jruoho                 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    285      1.1.1.2    jruoho                     AcpiGbl_RootNode, OwnerId);
    286      1.1.1.2    jruoho                 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    287      1.1.1.2    jruoho             }
    288          1.1    jruoho 
    289      1.1.1.2    jruoho             /* Next external file */
    290          1.1    jruoho 
    291      1.1.1.2    jruoho             ExternalFileList = ExternalFileList->Next;
    292      1.1.1.2    jruoho         }
    293          1.1    jruoho 
    294  1.1.1.4.2.2     skrll         if (ACPI_FAILURE (GlobalStatus))
    295  1.1.1.4.2.2     skrll         {
    296  1.1.1.4.2.2     skrll             return (GlobalStatus);
    297  1.1.1.4.2.2     skrll         }
    298  1.1.1.4.2.2     skrll 
    299      1.1.1.2    jruoho         /* Clear external list generated by Scope in external tables */
    300          1.1    jruoho 
    301      1.1.1.2    jruoho         if (AcpiGbl_ExternalFileList)
    302      1.1.1.2    jruoho         {
    303          1.1    jruoho             AcpiDmClearExternalList ();
    304          1.1    jruoho         }
    305      1.1.1.3  christos 
    306      1.1.1.3  christos         /* Load any externals defined in the optional external ref file */
    307      1.1.1.3  christos 
    308      1.1.1.3  christos         AcpiDmGetExternalsFromFile ();
    309          1.1    jruoho     }
    310          1.1    jruoho     else
    311          1.1    jruoho     {
    312      1.1.1.4  christos         Status = AdGetLocalTables ();
    313          1.1    jruoho         if (ACPI_FAILURE (Status))
    314          1.1    jruoho         {
    315          1.1    jruoho             AcpiOsPrintf ("Could not get ACPI tables, %s\n",
    316          1.1    jruoho                 AcpiFormatException (Status));
    317      1.1.1.3  christos             return (Status);
    318          1.1    jruoho         }
    319          1.1    jruoho 
    320  1.1.1.4.2.1     skrll         if (!AcpiGbl_DbOpt_Disasm)
    321          1.1    jruoho         {
    322      1.1.1.3  christos             return (AE_OK);
    323          1.1    jruoho         }
    324          1.1    jruoho 
    325          1.1    jruoho         /* Obtained the local tables, just disassemble the DSDT */
    326          1.1    jruoho 
    327          1.1    jruoho         Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
    328          1.1    jruoho         if (ACPI_FAILURE (Status))
    329          1.1    jruoho         {
    330          1.1    jruoho             AcpiOsPrintf ("Could not get DSDT, %s\n",
    331          1.1    jruoho                 AcpiFormatException (Status));
    332      1.1.1.3  christos             return (Status);
    333          1.1    jruoho         }
    334          1.1    jruoho 
    335          1.1    jruoho         AcpiOsPrintf ("\nDisassembly of DSDT\n");
    336          1.1    jruoho         Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
    337          1.1    jruoho     }
    338          1.1    jruoho 
    339          1.1    jruoho     /*
    340      1.1.1.3  christos      * Output: ASL code. Redirect to a file if requested
    341          1.1    jruoho      */
    342          1.1    jruoho     if (OutToFile)
    343          1.1    jruoho     {
    344          1.1    jruoho         /* Create/Open a disassembly output file */
    345          1.1    jruoho 
    346          1.1    jruoho         DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
    347      1.1.1.4  christos         if (!DisasmFilename)
    348          1.1    jruoho         {
    349          1.1    jruoho             fprintf (stderr, "Could not generate output filename\n");
    350          1.1    jruoho             Status = AE_ERROR;
    351          1.1    jruoho             goto Cleanup;
    352          1.1    jruoho         }
    353          1.1    jruoho 
    354          1.1    jruoho         File = fopen (DisasmFilename, "w+");
    355          1.1    jruoho         if (!File)
    356          1.1    jruoho         {
    357          1.1    jruoho             fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
    358          1.1    jruoho             Status = AE_ERROR;
    359          1.1    jruoho             goto Cleanup;
    360          1.1    jruoho         }
    361          1.1    jruoho 
    362          1.1    jruoho         AcpiOsRedirectOutput (File);
    363          1.1    jruoho     }
    364          1.1    jruoho 
    365          1.1    jruoho     *OutFilename = DisasmFilename;
    366          1.1    jruoho 
    367  1.1.1.4.2.1     skrll     /* ForceAmlDisassembly means to assume the table contains valid AML */
    368  1.1.1.4.2.1     skrll 
    369  1.1.1.4.2.1     skrll     if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table))
    370          1.1    jruoho     {
    371  1.1.1.4.2.1     skrll         AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE);
    372          1.1    jruoho         AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
    373          1.1    jruoho             Table->Signature);
    374      1.1.1.3  christos         AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength]  "
    375      1.1.1.3  christos             "FieldName : FieldValue\n */\n\n");
    376          1.1    jruoho 
    377          1.1    jruoho         AcpiDmDumpDataTable (Table);
    378      1.1.1.3  christos         fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
    379      1.1.1.3  christos             Table->Signature);
    380  1.1.1.4.2.1     skrll 
    381  1.1.1.4.2.1     skrll         if (File)
    382  1.1.1.4.2.1     skrll         {
    383  1.1.1.4.2.1     skrll             fprintf (stderr, "Formatted output:  %s - %u bytes\n",
    384  1.1.1.4.2.1     skrll                 DisasmFilename, CmGetFileSize (File));
    385  1.1.1.4.2.1     skrll         }
    386          1.1    jruoho     }
    387          1.1    jruoho     else
    388          1.1    jruoho     {
    389          1.1    jruoho         /* Always parse the tables, only option is what to display */
    390          1.1    jruoho 
    391          1.1    jruoho         Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
    392          1.1    jruoho         if (ACPI_FAILURE (Status))
    393          1.1    jruoho         {
    394          1.1    jruoho             AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    395          1.1    jruoho                 AcpiFormatException (Status));
    396          1.1    jruoho             goto Cleanup;
    397          1.1    jruoho         }
    398          1.1    jruoho 
    399          1.1    jruoho         if (AslCompilerdebug)
    400          1.1    jruoho         {
    401          1.1    jruoho             AcpiOsPrintf ("/**** Before second load\n");
    402          1.1    jruoho 
    403  1.1.1.4.2.1     skrll             if (File)
    404  1.1.1.4.2.1     skrll             {
    405  1.1.1.4.2.1     skrll                 NsSetupNamespaceListing (File);
    406  1.1.1.4.2.1     skrll                 NsDisplayNamespace ();
    407  1.1.1.4.2.1     skrll             }
    408          1.1    jruoho             AcpiOsPrintf ("*****/\n");
    409          1.1    jruoho         }
    410          1.1    jruoho 
    411      1.1.1.3  christos         /* Load namespace from names created within control methods */
    412      1.1.1.3  christos 
    413      1.1.1.3  christos         AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    414      1.1.1.3  christos             AcpiGbl_RootNode, OwnerId);
    415          1.1    jruoho 
    416          1.1    jruoho         /*
    417      1.1.1.3  christos          * Cross reference the namespace here, in order to
    418      1.1.1.3  christos          * generate External() statements
    419          1.1    jruoho          */
    420      1.1.1.3  christos         AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    421      1.1.1.3  christos             AcpiGbl_RootNode, OwnerId);
    422          1.1    jruoho 
    423          1.1    jruoho         if (AslCompilerdebug)
    424          1.1    jruoho         {
    425          1.1    jruoho             AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    426          1.1    jruoho         }
    427          1.1    jruoho 
    428          1.1    jruoho         /* Find possible calls to external control methods */
    429          1.1    jruoho 
    430          1.1    jruoho         AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
    431          1.1    jruoho 
    432          1.1    jruoho         /*
    433      1.1.1.3  christos          * If we found any external control methods, we must reparse
    434      1.1.1.3  christos          * the entire tree with the new information (namely, the
    435      1.1.1.3  christos          * number of arguments per method)
    436          1.1    jruoho          */
    437          1.1    jruoho         if (AcpiDmGetExternalMethodCount ())
    438          1.1    jruoho         {
    439          1.1    jruoho             fprintf (stderr,
    440      1.1.1.3  christos                 "\nFound %u external control methods, "
    441      1.1.1.3  christos                 "reparsing with new information\n",
    442          1.1    jruoho                 AcpiDmGetExternalMethodCount ());
    443          1.1    jruoho 
    444      1.1.1.4  christos             /* Reparse, rebuild namespace */
    445      1.1.1.3  christos 
    446          1.1    jruoho             AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    447      1.1.1.4  christos             AcpiGbl_ParseOpRoot = NULL;
    448          1.1    jruoho             AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
    449          1.1    jruoho 
    450          1.1    jruoho             AcpiGbl_RootNode                    = NULL;
    451          1.1    jruoho             AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
    452          1.1    jruoho             AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
    453          1.1    jruoho             AcpiGbl_RootNodeStruct.Type         = ACPI_TYPE_DEVICE;
    454          1.1    jruoho             AcpiGbl_RootNodeStruct.Parent       = NULL;
    455          1.1    jruoho             AcpiGbl_RootNodeStruct.Child        = NULL;
    456          1.1    jruoho             AcpiGbl_RootNodeStruct.Peer         = NULL;
    457          1.1    jruoho             AcpiGbl_RootNodeStruct.Object       = NULL;
    458          1.1    jruoho             AcpiGbl_RootNodeStruct.Flags        = 0;
    459          1.1    jruoho 
    460          1.1    jruoho             Status = AcpiNsRootInitialize ();
    461      1.1.1.4  christos 
    462      1.1.1.4  christos             /* New namespace, add the external definitions first */
    463      1.1.1.4  christos 
    464          1.1    jruoho             AcpiDmAddExternalsToNamespace ();
    465          1.1    jruoho 
    466      1.1.1.3  christos             /* Parse the table again. No need to reload it, however */
    467          1.1    jruoho 
    468          1.1    jruoho             Status = AdParseTable (Table, NULL, FALSE, FALSE);
    469          1.1    jruoho             if (ACPI_FAILURE (Status))
    470          1.1    jruoho             {
    471          1.1    jruoho                 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
    472          1.1    jruoho                     AcpiFormatException (Status));
    473          1.1    jruoho                 goto Cleanup;
    474          1.1    jruoho             }
    475          1.1    jruoho 
    476      1.1.1.4  christos             /* Cross reference the namespace again */
    477      1.1.1.4  christos 
    478      1.1.1.4  christos             AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
    479      1.1.1.4  christos                 AcpiGbl_RootNode, OwnerId);
    480      1.1.1.4  christos 
    481      1.1.1.4  christos             AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
    482      1.1.1.4  christos                 AcpiGbl_RootNode, OwnerId);
    483      1.1.1.4  christos 
    484          1.1    jruoho             if (AslCompilerdebug)
    485          1.1    jruoho             {
    486          1.1    jruoho                 AcpiOsPrintf ("/**** After second load and resource conversion\n");
    487  1.1.1.4.2.1     skrll                 if (File)
    488  1.1.1.4.2.1     skrll                 {
    489  1.1.1.4.2.1     skrll                     NsSetupNamespaceListing (File);
    490  1.1.1.4.2.1     skrll                     NsDisplayNamespace ();
    491  1.1.1.4.2.1     skrll                 }
    492          1.1    jruoho                 AcpiOsPrintf ("*****/\n");
    493          1.1    jruoho 
    494          1.1    jruoho                 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
    495          1.1    jruoho             }
    496          1.1    jruoho         }
    497          1.1    jruoho 
    498      1.1.1.3  christos         /*
    499      1.1.1.3  christos          * Now that the namespace is finalized, we can perform namespace
    500      1.1.1.3  christos          * transforms.
    501      1.1.1.3  christos          *
    502      1.1.1.3  christos          * 1) Convert fixed-offset references to resource descriptors
    503      1.1.1.3  christos          *    to symbolic references (Note: modifies namespace)
    504      1.1.1.3  christos          */
    505      1.1.1.3  christos         AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
    506      1.1.1.3  christos 
    507          1.1    jruoho         /* Optional displays */
    508          1.1    jruoho 
    509  1.1.1.4.2.1     skrll         if (AcpiGbl_DbOpt_Disasm)
    510          1.1    jruoho         {
    511      1.1.1.3  christos             /* This is the real disassembly */
    512      1.1.1.3  christos 
    513          1.1    jruoho             AdDisplayTables (Filename, Table);
    514      1.1.1.3  christos 
    515      1.1.1.3  christos             /* Dump hex table if requested (-vt) */
    516      1.1.1.3  christos 
    517      1.1.1.3  christos             AcpiDmDumpDataTable (Table);
    518      1.1.1.3  christos 
    519      1.1.1.3  christos             fprintf (stderr, "Disassembly completed\n");
    520  1.1.1.4.2.1     skrll             if (File)
    521  1.1.1.4.2.1     skrll             {
    522  1.1.1.4.2.1     skrll                 fprintf (stderr, "ASL Output:    %s - %u bytes\n",
    523  1.1.1.4.2.1     skrll                     DisasmFilename, CmGetFileSize (File));
    524  1.1.1.4.2.1     skrll             }
    525      1.1.1.4  christos 
    526      1.1.1.4  christos             if (Gbl_MapfileFlag)
    527      1.1.1.4  christos             {
    528      1.1.1.4  christos                 fprintf (stderr, "%14s %s - %u bytes\n",
    529      1.1.1.4  christos                     Gbl_Files[ASL_FILE_MAP_OUTPUT].ShortDescription,
    530      1.1.1.4  christos                     Gbl_Files[ASL_FILE_MAP_OUTPUT].Filename,
    531      1.1.1.4  christos                     FlGetFileSize (ASL_FILE_MAP_OUTPUT));
    532      1.1.1.4  christos             }
    533          1.1    jruoho         }
    534          1.1    jruoho     }
    535          1.1    jruoho 
    536          1.1    jruoho Cleanup:
    537          1.1    jruoho 
    538  1.1.1.4.2.1     skrll     if (Table && !AcpiGbl_ForceAmlDisassembly &&!AcpiUtIsAmlTable (Table))
    539          1.1    jruoho     {
    540          1.1    jruoho         ACPI_FREE (Table);
    541          1.1    jruoho     }
    542          1.1    jruoho 
    543  1.1.1.4.2.1     skrll     if (File)
    544          1.1    jruoho     {
    545      1.1.1.3  christos         if (AslCompilerdebug) /* Display final namespace, with transforms */
    546      1.1.1.3  christos         {
    547      1.1.1.3  christos             NsSetupNamespaceListing (File);
    548      1.1.1.3  christos             NsDisplayNamespace ();
    549      1.1.1.3  christos         }
    550          1.1    jruoho 
    551          1.1    jruoho         fclose (File);
    552          1.1    jruoho         AcpiOsRedirectOutput (stdout);
    553          1.1    jruoho     }
    554          1.1    jruoho 
    555          1.1    jruoho     AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
    556          1.1    jruoho     AcpiGbl_ParseOpRoot = NULL;
    557          1.1    jruoho     return (Status);
    558          1.1    jruoho }
    559          1.1    jruoho 
    560          1.1    jruoho 
    561          1.1    jruoho /******************************************************************************
    562          1.1    jruoho  *
    563          1.1    jruoho  * FUNCTION:    AdDisassemblerHeader
    564          1.1    jruoho  *
    565          1.1    jruoho  * PARAMETERS:  Filename            - Input file for the table
    566  1.1.1.4.2.1     skrll  *              TableType           - Either AML or DataTable
    567          1.1    jruoho  *
    568          1.1    jruoho  * RETURN:      None
    569          1.1    jruoho  *
    570      1.1.1.4  christos  * DESCRIPTION: Create the disassembler header, including ACPICA signon with
    571          1.1    jruoho  *              current time and date.
    572          1.1    jruoho  *
    573          1.1    jruoho  *****************************************************************************/
    574          1.1    jruoho 
    575          1.1    jruoho void
    576          1.1    jruoho AdDisassemblerHeader (
    577  1.1.1.4.2.1     skrll     char                    *Filename,
    578  1.1.1.4.2.1     skrll     UINT8                   TableType)
    579          1.1    jruoho {
    580          1.1    jruoho     time_t                  Timer;
    581          1.1    jruoho 
    582  1.1.1.4.2.1     skrll 
    583          1.1    jruoho     time (&Timer);
    584          1.1    jruoho 
    585          1.1    jruoho     /* Header and input table info */
    586          1.1    jruoho 
    587      1.1.1.2    jruoho     AcpiOsPrintf ("/*\n");
    588  1.1.1.4.2.1     skrll     AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
    589  1.1.1.4.2.1     skrll 
    590  1.1.1.4.2.1     skrll     if (TableType == ACPI_IS_AML_TABLE)
    591  1.1.1.4.2.1     skrll     {
    592  1.1.1.4.2.1     skrll         if (AcpiGbl_CstyleDisassembly)
    593  1.1.1.4.2.1     skrll         {
    594  1.1.1.4.2.1     skrll             AcpiOsPrintf (
    595  1.1.1.4.2.1     skrll                 " * Disassembling to symbolic ASL+ operators\n"
    596  1.1.1.4.2.1     skrll                 " *\n");
    597  1.1.1.4.2.1     skrll         }
    598  1.1.1.4.2.1     skrll         else
    599  1.1.1.4.2.1     skrll         {
    600  1.1.1.4.2.1     skrll             AcpiOsPrintf (
    601  1.1.1.4.2.1     skrll                 " * Disassembling to non-symbolic legacy ASL operators\n"
    602  1.1.1.4.2.1     skrll                 " *\n");
    603  1.1.1.4.2.1     skrll         }
    604  1.1.1.4.2.1     skrll     }
    605          1.1    jruoho 
    606      1.1.1.2    jruoho     AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
    607          1.1    jruoho     AcpiOsPrintf (" *\n");
    608          1.1    jruoho }
    609          1.1    jruoho 
    610          1.1    jruoho 
    611          1.1    jruoho /******************************************************************************
    612          1.1    jruoho  *
    613          1.1    jruoho  * FUNCTION:    AdCreateTableHeader
    614          1.1    jruoho  *
    615          1.1    jruoho  * PARAMETERS:  Filename            - Input file for the table
    616          1.1    jruoho  *              Table               - Pointer to the raw table
    617          1.1    jruoho  *
    618          1.1    jruoho  * RETURN:      None
    619          1.1    jruoho  *
    620      1.1.1.4  christos  * DESCRIPTION: Create the ASL table header, including ACPICA signon with
    621          1.1    jruoho  *              current time and date.
    622          1.1    jruoho  *
    623          1.1    jruoho  *****************************************************************************/
    624          1.1    jruoho 
    625      1.1.1.2    jruoho static void
    626          1.1    jruoho AdCreateTableHeader (
    627          1.1    jruoho     char                    *Filename,
    628          1.1    jruoho     ACPI_TABLE_HEADER       *Table)
    629          1.1    jruoho {
    630          1.1    jruoho     char                    *NewFilename;
    631          1.1    jruoho     UINT8                   Checksum;
    632          1.1    jruoho 
    633          1.1    jruoho 
    634          1.1    jruoho     /*
    635          1.1    jruoho      * Print file header and dump original table header
    636          1.1    jruoho      */
    637  1.1.1.4.2.1     skrll     AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
    638          1.1    jruoho 
    639      1.1.1.2    jruoho     AcpiOsPrintf (" * Original Table Header:\n");
    640          1.1    jruoho     AcpiOsPrintf (" *     Signature        \"%4.4s\"\n",    Table->Signature);
    641          1.1    jruoho     AcpiOsPrintf (" *     Length           0x%8.8X (%u)\n", Table->Length, Table->Length);
    642          1.1    jruoho 
    643          1.1    jruoho     /* Print and validate the revision */
    644          1.1    jruoho 
    645          1.1    jruoho     AcpiOsPrintf (" *     Revision         0x%2.2X",      Table->Revision);
    646          1.1    jruoho 
    647          1.1    jruoho     switch (Table->Revision)
    648          1.1    jruoho     {
    649          1.1    jruoho     case 0:
    650      1.1.1.3  christos 
    651          1.1    jruoho         AcpiOsPrintf (" **** Invalid Revision");
    652          1.1    jruoho         break;
    653          1.1    jruoho 
    654          1.1    jruoho     case 1:
    655      1.1.1.3  christos 
    656          1.1    jruoho         /* Revision of DSDT controls the ACPI integer width */
    657          1.1    jruoho 
    658          1.1    jruoho         if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
    659          1.1    jruoho         {
    660      1.1.1.2    jruoho             AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
    661          1.1    jruoho         }
    662          1.1    jruoho         break;
    663          1.1    jruoho 
    664          1.1    jruoho     default:
    665      1.1.1.3  christos 
    666          1.1    jruoho         break;
    667          1.1    jruoho     }
    668          1.1    jruoho     AcpiOsPrintf ("\n");
    669          1.1    jruoho 
    670          1.1    jruoho     /* Print and validate the table checksum */
    671          1.1    jruoho 
    672          1.1    jruoho     AcpiOsPrintf (" *     Checksum         0x%2.2X",        Table->Checksum);
    673          1.1    jruoho 
    674          1.1    jruoho     Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
    675          1.1    jruoho     if (Checksum)
    676          1.1    jruoho     {
    677          1.1    jruoho         AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
    678          1.1    jruoho             (UINT8) (Table->Checksum - Checksum));
    679          1.1    jruoho     }
    680          1.1    jruoho     AcpiOsPrintf ("\n");
    681          1.1    jruoho 
    682          1.1    jruoho     AcpiOsPrintf (" *     OEM ID           \"%.6s\"\n",     Table->OemId);
    683          1.1    jruoho     AcpiOsPrintf (" *     OEM Table ID     \"%.8s\"\n",     Table->OemTableId);
    684          1.1    jruoho     AcpiOsPrintf (" *     OEM Revision     0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
    685          1.1    jruoho     AcpiOsPrintf (" *     Compiler ID      \"%.4s\"\n",     Table->AslCompilerId);
    686          1.1    jruoho     AcpiOsPrintf (" *     Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
    687      1.1.1.3  christos     AcpiOsPrintf (" */\n");
    688          1.1    jruoho 
    689          1.1    jruoho     /* Create AML output filename based on input filename */
    690          1.1    jruoho 
    691          1.1    jruoho     if (Filename)
    692          1.1    jruoho     {
    693          1.1    jruoho         NewFilename = FlGenerateFilename (Filename, "aml");
    694          1.1    jruoho     }
    695          1.1    jruoho     else
    696          1.1    jruoho     {
    697      1.1.1.4  christos         NewFilename = UtStringCacheCalloc (9);
    698      1.1.1.4  christos         if (NewFilename)
    699      1.1.1.4  christos         {
    700      1.1.1.4  christos             strncat (NewFilename, Table->Signature, 4);
    701      1.1.1.4  christos             strcat (NewFilename, ".aml");
    702      1.1.1.4  christos         }
    703      1.1.1.4  christos     }
    704      1.1.1.4  christos 
    705      1.1.1.4  christos     if (!NewFilename)
    706      1.1.1.4  christos     {
    707      1.1.1.4  christos         AcpiOsPrintf (" **** Could not generate AML output filename\n");
    708      1.1.1.4  christos         return;
    709          1.1    jruoho     }
    710          1.1    jruoho 
    711          1.1    jruoho     /* Open the ASL definition block */
    712          1.1    jruoho 
    713          1.1    jruoho     AcpiOsPrintf (
    714          1.1    jruoho         "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
    715          1.1    jruoho         NewFilename, Table->Signature, Table->Revision,
    716          1.1    jruoho         Table->OemId, Table->OemTableId, Table->OemRevision);
    717          1.1    jruoho }
    718          1.1    jruoho 
    719          1.1    jruoho 
    720          1.1    jruoho /******************************************************************************
    721          1.1    jruoho  *
    722          1.1    jruoho  * FUNCTION:    AdDisplayTables
    723          1.1    jruoho  *
    724          1.1    jruoho  * PARAMETERS:  Filename            - Input file for the table
    725          1.1    jruoho  *              Table               - Pointer to the raw table
    726          1.1    jruoho  *
    727          1.1    jruoho  * RETURN:      Status
    728          1.1    jruoho  *
    729          1.1    jruoho  * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
    730          1.1    jruoho  *
    731          1.1    jruoho  *****************************************************************************/
    732          1.1    jruoho 
    733          1.1    jruoho ACPI_STATUS
    734          1.1    jruoho AdDisplayTables (
    735          1.1    jruoho     char                    *Filename,
    736          1.1    jruoho     ACPI_TABLE_HEADER       *Table)
    737          1.1    jruoho {
    738          1.1    jruoho 
    739          1.1    jruoho 
    740          1.1    jruoho     if (!AcpiGbl_ParseOpRoot)
    741          1.1    jruoho     {
    742      1.1.1.3  christos         return (AE_NOT_EXIST);
    743          1.1    jruoho     }
    744          1.1    jruoho 
    745  1.1.1.4.2.1     skrll     if (!AcpiGbl_DbOpt_Verbose)
    746          1.1    jruoho     {
    747          1.1    jruoho         AdCreateTableHeader (Filename, Table);
    748          1.1    jruoho     }
    749          1.1    jruoho 
    750          1.1    jruoho     AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
    751      1.1.1.4  christos     MpEmitMappingInfo ();
    752          1.1    jruoho 
    753  1.1.1.4.2.1     skrll     if (AcpiGbl_DbOpt_Verbose)
    754          1.1    jruoho     {
    755          1.1    jruoho         AcpiOsPrintf ("\n\nTable Header:\n");
    756      1.1.1.3  christos         AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
    757          1.1    jruoho             DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
    758          1.1    jruoho 
    759          1.1    jruoho         AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
    760      1.1.1.3  christos         AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
    761      1.1.1.3  christos             Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
    762          1.1    jruoho     }
    763          1.1    jruoho 
    764      1.1.1.3  christos     return (AE_OK);
    765          1.1    jruoho }
    766          1.1    jruoho 
    767          1.1    jruoho 
    768  1.1.1.4.2.1     skrll /*******************************************************************************
    769  1.1.1.4.2.1     skrll  *
    770  1.1.1.4.2.1     skrll  * FUNCTION:    AdStoreTable
    771  1.1.1.4.2.1     skrll  *
    772  1.1.1.4.2.1     skrll  * PARAMETERS:  Table               - Table header
    773  1.1.1.4.2.1     skrll  *              TableIndex          - Where the table index is returned
    774  1.1.1.4.2.1     skrll  *
    775  1.1.1.4.2.1     skrll  * RETURN:      Status and table index.
    776  1.1.1.4.2.1     skrll  *
    777  1.1.1.4.2.1     skrll  * DESCRIPTION: Add an ACPI table to the global table list
    778  1.1.1.4.2.1     skrll  *
    779  1.1.1.4.2.1     skrll  ******************************************************************************/
    780  1.1.1.4.2.1     skrll 
    781  1.1.1.4.2.1     skrll static ACPI_STATUS
    782  1.1.1.4.2.1     skrll AdStoreTable (
    783  1.1.1.4.2.1     skrll     ACPI_TABLE_HEADER       *Table,
    784  1.1.1.4.2.1     skrll     UINT32                  *TableIndex)
    785  1.1.1.4.2.1     skrll {
    786  1.1.1.4.2.1     skrll     ACPI_STATUS             Status;
    787  1.1.1.4.2.1     skrll     ACPI_TABLE_DESC         *TableDesc;
    788  1.1.1.4.2.1     skrll 
    789  1.1.1.4.2.1     skrll 
    790  1.1.1.4.2.1     skrll     Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
    791  1.1.1.4.2.1     skrll     if (ACPI_FAILURE (Status))
    792  1.1.1.4.2.1     skrll     {
    793  1.1.1.4.2.1     skrll         return (Status);
    794  1.1.1.4.2.1     skrll     }
    795  1.1.1.4.2.1     skrll 
    796  1.1.1.4.2.1     skrll     /* Initialize added table */
    797  1.1.1.4.2.1     skrll 
    798  1.1.1.4.2.1     skrll     AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
    799  1.1.1.4.2.1     skrll         ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
    800  1.1.1.4.2.2     skrll     Status = AcpiTbValidateTable (TableDesc);
    801  1.1.1.4.2.2     skrll     return (Status);
    802  1.1.1.4.2.1     skrll }
    803  1.1.1.4.2.1     skrll 
    804  1.1.1.4.2.1     skrll 
    805          1.1    jruoho /******************************************************************************
    806          1.1    jruoho  *
    807          1.1    jruoho  * FUNCTION:    AdGetLocalTables
    808          1.1    jruoho  *
    809      1.1.1.4  christos  * PARAMETERS:  None
    810          1.1    jruoho  *
    811          1.1    jruoho  * RETURN:      Status
    812          1.1    jruoho  *
    813          1.1    jruoho  * DESCRIPTION: Get the ACPI tables from either memory or a file
    814          1.1    jruoho  *
    815          1.1    jruoho  *****************************************************************************/
    816          1.1    jruoho 
    817          1.1    jruoho ACPI_STATUS
    818          1.1    jruoho AdGetLocalTables (
    819      1.1.1.4  christos     void)
    820          1.1    jruoho {
    821          1.1    jruoho     ACPI_STATUS             Status;
    822          1.1    jruoho     ACPI_TABLE_HEADER       TableHeader;
    823          1.1    jruoho     ACPI_TABLE_HEADER       *NewTable;
    824          1.1    jruoho     UINT32                  TableIndex;
    825          1.1    jruoho 
    826          1.1    jruoho 
    827      1.1.1.4  christos     /* Get the DSDT via table override */
    828          1.1    jruoho 
    829          1.1    jruoho     ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
    830          1.1    jruoho     AcpiOsTableOverride (&TableHeader, &NewTable);
    831      1.1.1.4  christos     if (!NewTable)
    832          1.1    jruoho     {
    833          1.1    jruoho         fprintf (stderr, "Could not obtain DSDT\n");
    834      1.1.1.3  christos         return (AE_NO_ACPI_TABLES);
    835          1.1    jruoho     }
    836          1.1    jruoho 
    837      1.1.1.4  christos     AdWriteTable (NewTable, NewTable->Length,
    838      1.1.1.4  christos         ACPI_SIG_DSDT, NewTable->OemTableId);
    839          1.1    jruoho 
    840      1.1.1.4  christos     /* Store DSDT in the Table Manager */
    841          1.1    jruoho 
    842  1.1.1.4.2.1     skrll     Status = AdStoreTable (NewTable, &TableIndex);
    843      1.1.1.4  christos     if (ACPI_FAILURE (Status))
    844          1.1    jruoho     {
    845      1.1.1.4  christos         fprintf (stderr, "Could not store DSDT\n");
    846      1.1.1.4  christos         return (AE_NO_ACPI_TABLES);
    847      1.1.1.4  christos     }
    848          1.1    jruoho 
    849      1.1.1.3  christos     return (AE_OK);
    850          1.1    jruoho }
    851          1.1    jruoho 
    852          1.1    jruoho 
    853          1.1    jruoho /******************************************************************************
    854          1.1    jruoho  *
    855          1.1    jruoho  * FUNCTION:    AdParseTable
    856          1.1    jruoho  *
    857          1.1    jruoho  * PARAMETERS:  Table               - Pointer to the raw table
    858          1.1    jruoho  *              OwnerId             - Returned OwnerId of the table
    859          1.1    jruoho  *              LoadTable           - If add table to the global table list
    860          1.1    jruoho  *              External            - If this is an external table
    861          1.1    jruoho  *
    862          1.1    jruoho  * RETURN:      Status
    863          1.1    jruoho  *
    864          1.1    jruoho  * DESCRIPTION: Parse the DSDT.
    865          1.1    jruoho  *
    866          1.1    jruoho  *****************************************************************************/
    867          1.1    jruoho 
    868          1.1    jruoho ACPI_STATUS
    869          1.1    jruoho AdParseTable (
    870          1.1    jruoho     ACPI_TABLE_HEADER       *Table,
    871          1.1    jruoho     ACPI_OWNER_ID           *OwnerId,
    872          1.1    jruoho     BOOLEAN                 LoadTable,
    873          1.1    jruoho     BOOLEAN                 External)
    874          1.1    jruoho {
    875          1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    876          1.1    jruoho     ACPI_WALK_STATE         *WalkState;
    877          1.1    jruoho     UINT8                   *AmlStart;
    878          1.1    jruoho     UINT32                  AmlLength;
    879          1.1    jruoho     UINT32                  TableIndex;
    880          1.1    jruoho 
    881          1.1    jruoho 
    882          1.1    jruoho     if (!Table)
    883          1.1    jruoho     {
    884      1.1.1.3  christos         return (AE_NOT_EXIST);
    885          1.1    jruoho     }
    886          1.1    jruoho 
    887          1.1    jruoho     /* Pass 1:  Parse everything except control method bodies */
    888          1.1    jruoho 
    889          1.1    jruoho     fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
    890          1.1    jruoho 
    891          1.1    jruoho     AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
    892          1.1    jruoho     AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
    893          1.1    jruoho 
    894          1.1    jruoho     /* Create the root object */
    895          1.1    jruoho 
    896  1.1.1.4.2.2     skrll     AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
    897          1.1    jruoho     if (!AcpiGbl_ParseOpRoot)
    898          1.1    jruoho     {
    899      1.1.1.3  christos         return (AE_NO_MEMORY);
    900          1.1    jruoho     }
    901          1.1    jruoho 
    902          1.1    jruoho     /* Create and initialize a new walk state */
    903          1.1    jruoho 
    904          1.1    jruoho     WalkState = AcpiDsCreateWalkState (0,
    905          1.1    jruoho                         AcpiGbl_ParseOpRoot, NULL, NULL);
    906          1.1    jruoho     if (!WalkState)
    907          1.1    jruoho     {
    908          1.1    jruoho         return (AE_NO_MEMORY);
    909          1.1    jruoho     }
    910          1.1    jruoho 
    911          1.1    jruoho     Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
    912          1.1    jruoho                 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
    913          1.1    jruoho     if (ACPI_FAILURE (Status))
    914          1.1    jruoho     {
    915          1.1    jruoho         return (Status);
    916          1.1    jruoho     }
    917          1.1    jruoho 
    918          1.1    jruoho     WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
    919          1.1    jruoho     WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
    920          1.1    jruoho 
    921          1.1    jruoho     Status = AcpiPsParseAml (WalkState);
    922          1.1    jruoho     if (ACPI_FAILURE (Status))
    923          1.1    jruoho     {
    924      1.1.1.3  christos         return (Status);
    925          1.1    jruoho     }
    926          1.1    jruoho 
    927          1.1    jruoho     /* If LoadTable is FALSE, we are parsing the last loaded table */
    928          1.1    jruoho 
    929          1.1    jruoho     TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
    930          1.1    jruoho 
    931          1.1    jruoho     /* Pass 2 */
    932          1.1    jruoho 
    933          1.1    jruoho     if (LoadTable)
    934          1.1    jruoho     {
    935  1.1.1.4.2.1     skrll         Status = AdStoreTable (Table, &TableIndex);
    936          1.1    jruoho         if (ACPI_FAILURE (Status))
    937          1.1    jruoho         {
    938      1.1.1.3  christos             return (Status);
    939          1.1    jruoho         }
    940          1.1    jruoho         Status = AcpiTbAllocateOwnerId (TableIndex);
    941          1.1    jruoho         if (ACPI_FAILURE (Status))
    942          1.1    jruoho         {
    943      1.1.1.3  christos             return (Status);
    944          1.1    jruoho         }
    945          1.1    jruoho         if (OwnerId)
    946          1.1    jruoho         {
    947          1.1    jruoho             Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
    948          1.1    jruoho             if (ACPI_FAILURE (Status))
    949          1.1    jruoho             {
    950      1.1.1.3  christos                 return (Status);
    951          1.1    jruoho             }
    952          1.1    jruoho         }
    953          1.1    jruoho     }
    954          1.1    jruoho 
    955          1.1    jruoho     fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
    956          1.1    jruoho 
    957          1.1    jruoho     Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
    958          1.1    jruoho     if (ACPI_FAILURE (Status))
    959          1.1    jruoho     {
    960          1.1    jruoho         return (Status);
    961          1.1    jruoho     }
    962          1.1    jruoho 
    963          1.1    jruoho     /* No need to parse control methods of external table */
    964          1.1    jruoho 
    965          1.1    jruoho     if (External)
    966          1.1    jruoho     {
    967      1.1.1.3  christos         return (AE_OK);
    968          1.1    jruoho     }
    969          1.1    jruoho 
    970      1.1.1.4  christos     /*
    971      1.1.1.4  christos      * Pass 3: Parse control methods and link their parse trees
    972      1.1.1.4  christos      * into the main parse tree
    973      1.1.1.4  christos      */
    974      1.1.1.4  christos     fprintf (stderr,
    975      1.1.1.4  christos         "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
    976      1.1.1.3  christos     Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
    977      1.1.1.3  christos     fprintf (stderr, "\n");
    978          1.1    jruoho 
    979          1.1    jruoho     /* Process Resource Templates */
    980          1.1    jruoho 
    981          1.1    jruoho     AcpiDmFindResources (AcpiGbl_ParseOpRoot);
    982          1.1    jruoho 
    983          1.1    jruoho     fprintf (stderr, "Parsing completed\n");
    984      1.1.1.3  christos     return (AE_OK);
    985          1.1    jruoho }
    986