Home | History | Annotate | Line # | Download | only in acpixtract
acpixtract.c revision 1.1.1.19
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3  1.1.1.11  christos  * Module Name: acpixtract - Top level functions to convert ascii/hex
      4  1.1.1.11  christos  *                           ACPI tables to the original binary tables
      5       1.1    jruoho  *
      6       1.1    jruoho  *****************************************************************************/
      7       1.1    jruoho 
      8   1.1.1.2    jruoho /*
      9  1.1.1.19  christos  * Copyright (C) 2000 - 2023, Intel Corp.
     10       1.1    jruoho  * All rights reserved.
     11       1.1    jruoho  *
     12   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     13   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     14   1.1.1.2    jruoho  * are met:
     15   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     16   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     17   1.1.1.2    jruoho  *    without modification.
     18   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     20   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     21   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     22   1.1.1.2    jruoho  *    binary redistribution.
     23   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     24   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     25   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     26   1.1.1.2    jruoho  *
     27   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     28   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     29   1.1.1.2    jruoho  * Software Foundation.
     30   1.1.1.2    jruoho  *
     31   1.1.1.2    jruoho  * NO WARRANTY
     32   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.16  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     35   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     43   1.1.1.2    jruoho  */
     44       1.1    jruoho 
     45   1.1.1.8  christos #include "acpixtract.h"
     46       1.1    jruoho 
     47       1.1    jruoho 
     48   1.1.1.4  christos /******************************************************************************
     49   1.1.1.4  christos  *
     50   1.1.1.8  christos  * FUNCTION:    AxExtractTables
     51   1.1.1.4  christos  *
     52   1.1.1.8  christos  * PARAMETERS:  InputPathname       - Filename for input acpidump file
     53   1.1.1.8  christos  *              Signature           - Requested ACPI signature to extract.
     54   1.1.1.8  christos  *                                    NULL means extract ALL tables.
     55   1.1.1.8  christos  *              MinimumInstances    - Min instances that are acceptable
     56   1.1.1.4  christos  *
     57   1.1.1.8  christos  * RETURN:      Status
     58   1.1.1.4  christos  *
     59   1.1.1.8  christos  * DESCRIPTION: Convert text ACPI tables to binary
     60   1.1.1.4  christos  *
     61   1.1.1.4  christos  ******************************************************************************/
     62   1.1.1.4  christos 
     63   1.1.1.8  christos int
     64   1.1.1.8  christos AxExtractTables (
     65   1.1.1.8  christos     char                    *InputPathname,
     66   1.1.1.8  christos     char                    *Signature,
     67   1.1.1.8  christos     unsigned int            MinimumInstances)
     68   1.1.1.4  christos {
     69   1.1.1.8  christos     FILE                    *InputFile;
     70   1.1.1.8  christos     FILE                    *OutputFile = NULL;
     71  1.1.1.13  christos     int                     BytesConverted;
     72  1.1.1.13  christos     int                     ThisTableBytesWritten = 0;
     73   1.1.1.8  christos     unsigned int            FoundTable = 0;
     74   1.1.1.8  christos     unsigned int            Instances = 0;
     75   1.1.1.8  christos     unsigned int            ThisInstance;
     76   1.1.1.9  christos     char                    ThisSignature[5];
     77   1.1.1.9  christos     char                    UpperSignature[5];
     78   1.1.1.8  christos     int                     Status = 0;
     79   1.1.1.8  christos     unsigned int            State = AX_STATE_FIND_HEADER;
     80   1.1.1.4  christos 
     81   1.1.1.4  christos 
     82   1.1.1.8  christos     /* Open input in text mode, output is in binary mode */
     83   1.1.1.4  christos 
     84  1.1.1.10  christos     InputFile = fopen (InputPathname, "r");
     85   1.1.1.8  christos     if (!InputFile)
     86   1.1.1.4  christos     {
     87   1.1.1.8  christos         printf ("Could not open input file %s\n", InputPathname);
     88   1.1.1.8  christos         return (-1);
     89   1.1.1.4  christos     }
     90   1.1.1.4  christos 
     91   1.1.1.9  christos     if (!AxIsFileAscii (InputFile))
     92   1.1.1.9  christos     {
     93   1.1.1.9  christos         fclose (InputFile);
     94   1.1.1.9  christos         return (-1);
     95   1.1.1.9  christos     }
     96   1.1.1.9  christos 
     97   1.1.1.8  christos     if (Signature)
     98       1.1    jruoho     {
     99  1.1.1.14  christos         strncpy (UpperSignature, Signature, ACPI_NAMESEG_SIZE);
    100   1.1.1.9  christos         AcpiUtStrupr (UpperSignature);
    101   1.1.1.9  christos 
    102   1.1.1.8  christos         /* Are there enough instances of the table to continue? */
    103       1.1    jruoho 
    104   1.1.1.9  christos         AxNormalizeSignature (UpperSignature);
    105   1.1.1.9  christos         Instances = AxCountTableInstances (InputPathname, UpperSignature);
    106  1.1.1.11  christos 
    107   1.1.1.8  christos         if (Instances < MinimumInstances)
    108   1.1.1.8  christos         {
    109   1.1.1.8  christos             printf ("Table [%s] was not found in %s\n",
    110   1.1.1.9  christos                 UpperSignature, InputPathname);
    111   1.1.1.8  christos             fclose (InputFile);
    112  1.1.1.11  christos             return (0);             /* Don't abort */
    113   1.1.1.8  christos         }
    114       1.1    jruoho 
    115   1.1.1.8  christos         if (Instances == 0)
    116   1.1.1.8  christos         {
    117   1.1.1.8  christos             fclose (InputFile);
    118   1.1.1.8  christos             return (-1);
    119   1.1.1.8  christos         }
    120       1.1    jruoho     }
    121       1.1    jruoho 
    122   1.1.1.8  christos     /* Convert all instances of the table to binary */
    123       1.1    jruoho 
    124   1.1.1.8  christos     while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
    125       1.1    jruoho     {
    126  1.1.1.11  christos         /*
    127  1.1.1.11  christos          * Check up front if we have a header line of the form:
    128  1.1.1.11  christos          * DSDT @ 0xdfffd0c0 (10999 bytes)
    129  1.1.1.11  christos          */
    130  1.1.1.11  christos         if (AX_IS_TABLE_BLOCK_HEADER &&
    131  1.1.1.11  christos             (State == AX_STATE_EXTRACT_DATA))
    132  1.1.1.11  christos         {
    133  1.1.1.11  christos             /* End of previous table, start of new table */
    134  1.1.1.11  christos 
    135  1.1.1.11  christos             if (ThisTableBytesWritten)
    136  1.1.1.11  christos             {
    137  1.1.1.11  christos                 printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    138  1.1.1.11  christos                     ThisTableBytesWritten, Gbl_OutputFilename);
    139  1.1.1.11  christos             }
    140  1.1.1.11  christos             else
    141  1.1.1.11  christos             {
    142  1.1.1.11  christos                 Gbl_TableCount--;
    143  1.1.1.11  christos             }
    144  1.1.1.11  christos 
    145  1.1.1.11  christos             State = AX_STATE_FIND_HEADER;
    146  1.1.1.11  christos         }
    147  1.1.1.11  christos 
    148   1.1.1.8  christos         switch (State)
    149   1.1.1.8  christos         {
    150   1.1.1.8  christos         case AX_STATE_FIND_HEADER:
    151       1.1    jruoho 
    152   1.1.1.8  christos             if (!AxIsDataBlockHeader ())
    153   1.1.1.8  christos             {
    154   1.1.1.8  christos                 continue;
    155   1.1.1.8  christos             }
    156       1.1    jruoho 
    157  1.1.1.14  christos             ACPI_COPY_NAMESEG (ThisSignature, Gbl_LineBuffer);
    158   1.1.1.8  christos             if (Signature)
    159   1.1.1.8  christos             {
    160   1.1.1.8  christos                 /* Ignore signatures that don't match */
    161       1.1    jruoho 
    162  1.1.1.14  christos                 if (!ACPI_COMPARE_NAMESEG (ThisSignature, UpperSignature))
    163   1.1.1.8  christos                 {
    164   1.1.1.8  christos                     continue;
    165   1.1.1.8  christos                 }
    166   1.1.1.8  christos             }
    167       1.1    jruoho 
    168   1.1.1.8  christos             /*
    169   1.1.1.8  christos              * Get the instance number for this signature. Only the
    170   1.1.1.8  christos              * SSDT and PSDT tables can have multiple instances.
    171   1.1.1.8  christos              */
    172   1.1.1.8  christos             ThisInstance = AxGetNextInstance (InputPathname, ThisSignature);
    173       1.1    jruoho 
    174   1.1.1.8  christos             /* Build an output filename and create/open the output file */
    175       1.1    jruoho 
    176   1.1.1.8  christos             if (ThisInstance > 0)
    177   1.1.1.8  christos             {
    178   1.1.1.8  christos                 /* Add instance number to the output filename */
    179       1.1    jruoho 
    180   1.1.1.8  christos                 sprintf (Gbl_OutputFilename, "%4.4s%u.dat",
    181   1.1.1.8  christos                     ThisSignature, ThisInstance);
    182   1.1.1.8  christos             }
    183   1.1.1.8  christos             else
    184   1.1.1.8  christos             {
    185   1.1.1.8  christos                 sprintf (Gbl_OutputFilename, "%4.4s.dat",
    186   1.1.1.8  christos                     ThisSignature);
    187   1.1.1.8  christos             }
    188       1.1    jruoho 
    189   1.1.1.8  christos             AcpiUtStrlwr (Gbl_OutputFilename);
    190   1.1.1.8  christos             OutputFile = fopen (Gbl_OutputFilename, "w+b");
    191   1.1.1.8  christos             if (!OutputFile)
    192   1.1.1.8  christos             {
    193   1.1.1.8  christos                 printf ("Could not open output file %s\n",
    194   1.1.1.8  christos                     Gbl_OutputFilename);
    195   1.1.1.8  christos                 fclose (InputFile);
    196   1.1.1.8  christos                 return (-1);
    197   1.1.1.8  christos             }
    198       1.1    jruoho 
    199   1.1.1.8  christos             /*
    200   1.1.1.8  christos              * Toss this block header of the form "<sig> @ <addr>" line
    201   1.1.1.8  christos              * and move on to the actual data block
    202   1.1.1.8  christos              */
    203   1.1.1.8  christos             Gbl_TableCount++;
    204   1.1.1.8  christos             FoundTable = 1;
    205   1.1.1.8  christos             ThisTableBytesWritten = 0;
    206   1.1.1.8  christos             State = AX_STATE_EXTRACT_DATA;
    207   1.1.1.8  christos             continue;
    208       1.1    jruoho 
    209   1.1.1.8  christos         case AX_STATE_EXTRACT_DATA:
    210       1.1    jruoho 
    211  1.1.1.11  christos             if (!AxIsHexDataLine ())
    212  1.1.1.11  christos             {
    213  1.1.1.11  christos                 continue;   /* Toss any lines that are not raw hex data */
    214  1.1.1.11  christos             }
    215  1.1.1.11  christos 
    216   1.1.1.8  christos             /* Empty line or non-data line terminates the data block */
    217       1.1    jruoho 
    218  1.1.1.13  christos             BytesConverted = AxConvertAndWrite (OutputFile, ThisSignature);
    219   1.1.1.8  christos             switch (BytesConverted)
    220   1.1.1.8  christos             {
    221   1.1.1.8  christos             case 0:
    222       1.1    jruoho 
    223   1.1.1.8  christos                 State = AX_STATE_FIND_HEADER; /* No more data block lines */
    224   1.1.1.8  christos                 continue;
    225       1.1    jruoho 
    226   1.1.1.8  christos             case -1:
    227       1.1    jruoho 
    228  1.1.1.13  christos                 Status = -1;
    229   1.1.1.8  christos                 goto CleanupAndExit; /* There was a write error */
    230       1.1    jruoho 
    231   1.1.1.8  christos             default: /* Normal case, get next line */
    232       1.1    jruoho 
    233   1.1.1.8  christos                 ThisTableBytesWritten += BytesConverted;
    234   1.1.1.8  christos                 continue;
    235   1.1.1.8  christos             }
    236       1.1    jruoho 
    237   1.1.1.8  christos         default:
    238       1.1    jruoho 
    239   1.1.1.8  christos             Status = -1;
    240   1.1.1.8  christos             goto CleanupAndExit;
    241       1.1    jruoho         }
    242       1.1    jruoho     }
    243       1.1    jruoho 
    244   1.1.1.8  christos     if (!FoundTable)
    245   1.1.1.8  christos     {
    246   1.1.1.9  christos         printf ("No ACPI tables were found in %s\n", InputPathname);
    247   1.1.1.8  christos     }
    248       1.1    jruoho 
    249       1.1    jruoho 
    250   1.1.1.8  christos CleanupAndExit:
    251       1.1    jruoho 
    252   1.1.1.8  christos     if (State == AX_STATE_EXTRACT_DATA)
    253       1.1    jruoho     {
    254   1.1.1.8  christos         /* Received an input file EOF while extracting data */
    255       1.1    jruoho 
    256  1.1.1.11  christos         printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    257  1.1.1.11  christos             ThisTableBytesWritten, Gbl_OutputFilename);
    258       1.1    jruoho     }
    259       1.1    jruoho 
    260   1.1.1.8  christos     if (OutputFile)
    261       1.1    jruoho     {
    262   1.1.1.8  christos         fclose (OutputFile);
    263       1.1    jruoho     }
    264       1.1    jruoho 
    265   1.1.1.8  christos     fclose (InputFile);
    266   1.1.1.8  christos     return (Status);
    267       1.1    jruoho }
    268       1.1    jruoho 
    269       1.1    jruoho 
    270       1.1    jruoho /******************************************************************************
    271       1.1    jruoho  *
    272   1.1.1.8  christos  * FUNCTION:    AxExtractToMultiAmlFile
    273       1.1    jruoho  *
    274   1.1.1.8  christos  * PARAMETERS:  InputPathname       - Filename for input acpidump file
    275       1.1    jruoho  *
    276       1.1    jruoho  * RETURN:      Status
    277       1.1    jruoho  *
    278   1.1.1.8  christos  * DESCRIPTION: Convert all DSDT/SSDT tables to binary and append them all
    279   1.1.1.8  christos  *              into a single output file. Used to simplify the loading of
    280   1.1.1.8  christos  *              multiple/many SSDTs into a utility like acpiexec -- instead
    281   1.1.1.8  christos  *              of creating many separate output files.
    282       1.1    jruoho  *
    283       1.1    jruoho  ******************************************************************************/
    284       1.1    jruoho 
    285   1.1.1.4  christos int
    286   1.1.1.8  christos AxExtractToMultiAmlFile (
    287   1.1.1.8  christos     char                    *InputPathname)
    288       1.1    jruoho {
    289       1.1    jruoho     FILE                    *InputFile;
    290   1.1.1.8  christos     FILE                    *OutputFile;
    291       1.1    jruoho     int                     Status = 0;
    292  1.1.1.13  christos     int                     TotalBytesWritten = 0;
    293  1.1.1.13  christos     int                     ThisTableBytesWritten = 0;
    294  1.1.1.11  christos     unsigned int            BytesConverted;
    295   1.1.1.8  christos     char                    ThisSignature[4];
    296   1.1.1.8  christos     unsigned int            State = AX_STATE_FIND_HEADER;
    297       1.1    jruoho 
    298       1.1    jruoho 
    299   1.1.1.8  christos     strcpy (Gbl_OutputFilename, AX_MULTI_TABLE_FILENAME);
    300   1.1.1.8  christos 
    301   1.1.1.8  christos     /* Open the input file in text mode */
    302       1.1    jruoho 
    303  1.1.1.10  christos     InputFile = fopen (InputPathname, "r");
    304       1.1    jruoho     if (!InputFile)
    305       1.1    jruoho     {
    306   1.1.1.8  christos         printf ("Could not open input file %s\n", InputPathname);
    307       1.1    jruoho         return (-1);
    308       1.1    jruoho     }
    309       1.1    jruoho 
    310   1.1.1.9  christos     if (!AxIsFileAscii (InputFile))
    311   1.1.1.9  christos     {
    312   1.1.1.9  christos         fclose (InputFile);
    313   1.1.1.9  christos         return (-1);
    314   1.1.1.9  christos     }
    315   1.1.1.9  christos 
    316   1.1.1.8  christos     /* Open the output file in binary mode */
    317       1.1    jruoho 
    318   1.1.1.8  christos     OutputFile = fopen (Gbl_OutputFilename, "w+b");
    319   1.1.1.8  christos     if (!OutputFile)
    320   1.1.1.8  christos     {
    321   1.1.1.8  christos         printf ("Could not open output file %s\n", Gbl_OutputFilename);
    322   1.1.1.8  christos         fclose (InputFile);
    323   1.1.1.8  christos         return (-1);
    324       1.1    jruoho     }
    325       1.1    jruoho 
    326   1.1.1.8  christos     /* Convert the DSDT and all SSDTs to binary */
    327       1.1    jruoho 
    328   1.1.1.8  christos     while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
    329       1.1    jruoho     {
    330  1.1.1.11  christos         /*
    331  1.1.1.11  christos          * Check up front if we have a header line of the form:
    332  1.1.1.11  christos          * DSDT @ 0xdfffd0c0 (10999 bytes)
    333  1.1.1.11  christos          */
    334  1.1.1.11  christos         if (AX_IS_TABLE_BLOCK_HEADER &&
    335  1.1.1.11  christos             (State == AX_STATE_EXTRACT_DATA))
    336  1.1.1.11  christos         {
    337  1.1.1.11  christos             /* End of previous table, start of new table */
    338  1.1.1.11  christos 
    339  1.1.1.11  christos             if (ThisTableBytesWritten)
    340  1.1.1.11  christos             {
    341  1.1.1.11  christos                 printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    342  1.1.1.11  christos                     ThisTableBytesWritten, Gbl_OutputFilename);
    343  1.1.1.11  christos             }
    344  1.1.1.11  christos             else
    345  1.1.1.11  christos             {
    346  1.1.1.11  christos                 Gbl_TableCount--;
    347  1.1.1.11  christos             }
    348  1.1.1.11  christos 
    349  1.1.1.11  christos             State = AX_STATE_FIND_HEADER;
    350  1.1.1.11  christos         }
    351  1.1.1.11  christos 
    352       1.1    jruoho         switch (State)
    353       1.1    jruoho         {
    354   1.1.1.4  christos         case AX_STATE_FIND_HEADER:
    355       1.1    jruoho 
    356   1.1.1.8  christos             if (!AxIsDataBlockHeader ())
    357   1.1.1.3    jruoho             {
    358   1.1.1.3    jruoho                 continue;
    359   1.1.1.3    jruoho             }
    360   1.1.1.3    jruoho 
    361  1.1.1.14  christos             ACPI_COPY_NAMESEG (ThisSignature, Gbl_LineBuffer);
    362       1.1    jruoho 
    363   1.1.1.8  christos             /* Only want DSDT and SSDTs */
    364       1.1    jruoho 
    365  1.1.1.14  christos             if (!ACPI_COMPARE_NAMESEG (ThisSignature, ACPI_SIG_DSDT) &&
    366  1.1.1.14  christos                 !ACPI_COMPARE_NAMESEG (ThisSignature, ACPI_SIG_SSDT))
    367   1.1.1.3    jruoho             {
    368   1.1.1.3    jruoho                 continue;
    369   1.1.1.3    jruoho             }
    370   1.1.1.3    jruoho 
    371       1.1    jruoho             /*
    372   1.1.1.8  christos              * Toss this block header of the form "<sig> @ <addr>" line
    373   1.1.1.8  christos              * and move on to the actual data block
    374       1.1    jruoho              */
    375   1.1.1.8  christos             Gbl_TableCount++;
    376   1.1.1.8  christos             ThisTableBytesWritten = 0;
    377   1.1.1.4  christos             State = AX_STATE_EXTRACT_DATA;
    378       1.1    jruoho             continue;
    379       1.1    jruoho 
    380   1.1.1.4  christos         case AX_STATE_EXTRACT_DATA:
    381       1.1    jruoho 
    382  1.1.1.11  christos             if (!AxIsHexDataLine ())
    383  1.1.1.11  christos             {
    384  1.1.1.11  christos                 continue;   /* Toss any lines that are not raw hex data */
    385  1.1.1.11  christos             }
    386  1.1.1.11  christos 
    387   1.1.1.8  christos             /* Empty line or non-data line terminates the data block */
    388       1.1    jruoho 
    389  1.1.1.13  christos             BytesConverted = AxConvertAndWrite (OutputFile, ThisSignature);
    390   1.1.1.8  christos             switch (BytesConverted)
    391       1.1    jruoho             {
    392   1.1.1.8  christos             case 0:
    393       1.1    jruoho 
    394   1.1.1.8  christos                 State = AX_STATE_FIND_HEADER; /* No more data block lines */
    395       1.1    jruoho                 continue;
    396       1.1    jruoho 
    397   1.1.1.8  christos             case -1:
    398       1.1    jruoho 
    399  1.1.1.13  christos                 Status = -1;
    400   1.1.1.8  christos                 goto CleanupAndExit; /* There was a write error */
    401       1.1    jruoho 
    402   1.1.1.8  christos             default: /* Normal case, get next line */
    403       1.1    jruoho 
    404   1.1.1.8  christos                 ThisTableBytesWritten += BytesConverted;
    405   1.1.1.8  christos                 TotalBytesWritten += BytesConverted;
    406   1.1.1.8  christos                 continue;
    407       1.1    jruoho             }
    408       1.1    jruoho 
    409       1.1    jruoho         default:
    410   1.1.1.4  christos 
    411       1.1    jruoho             Status = -1;
    412       1.1    jruoho             goto CleanupAndExit;
    413       1.1    jruoho         }
    414       1.1    jruoho     }
    415       1.1    jruoho 
    416       1.1    jruoho 
    417       1.1    jruoho CleanupAndExit:
    418       1.1    jruoho 
    419   1.1.1.8  christos     if (State == AX_STATE_EXTRACT_DATA)
    420       1.1    jruoho     {
    421   1.1.1.8  christos         /* Received an input file EOF or error while writing data */
    422       1.1    jruoho 
    423  1.1.1.11  christos         printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    424  1.1.1.11  christos             ThisTableBytesWritten, Gbl_OutputFilename);
    425       1.1    jruoho     }
    426       1.1    jruoho 
    427   1.1.1.9  christos     printf ("\n%u binary ACPI tables extracted and written to %s (%u bytes)\n",
    428   1.1.1.8  christos         Gbl_TableCount, Gbl_OutputFilename, TotalBytesWritten);
    429   1.1.1.8  christos 
    430       1.1    jruoho     fclose (InputFile);
    431   1.1.1.8  christos     fclose (OutputFile);
    432       1.1    jruoho     return (Status);
    433       1.1    jruoho }
    434       1.1    jruoho 
    435       1.1    jruoho 
    436       1.1    jruoho /******************************************************************************
    437       1.1    jruoho  *
    438  1.1.1.11  christos  * FUNCTION:    AxListAllTables
    439       1.1    jruoho  *
    440       1.1    jruoho  * PARAMETERS:  InputPathname       - Filename for acpidump file
    441       1.1    jruoho  *
    442       1.1    jruoho  * RETURN:      Status
    443       1.1    jruoho  *
    444       1.1    jruoho  * DESCRIPTION: Display info for all ACPI tables found in input. Does not
    445       1.1    jruoho  *              perform an actual extraction of the tables.
    446       1.1    jruoho  *
    447       1.1    jruoho  ******************************************************************************/
    448       1.1    jruoho 
    449   1.1.1.4  christos int
    450  1.1.1.11  christos AxListAllTables (
    451       1.1    jruoho     char                    *InputPathname)
    452       1.1    jruoho {
    453       1.1    jruoho     FILE                    *InputFile;
    454       1.1    jruoho     unsigned char           Header[48];
    455  1.1.1.11  christos     UINT32                  ByteCount = 0;
    456  1.1.1.18  christos     INT32                   ThisLineByteCount;
    457  1.1.1.11  christos     unsigned int            State = AX_STATE_FIND_HEADER;
    458       1.1    jruoho 
    459       1.1    jruoho 
    460       1.1    jruoho     /* Open input in text mode, output is in binary mode */
    461       1.1    jruoho 
    462  1.1.1.10  christos     InputFile = fopen (InputPathname, "r");
    463       1.1    jruoho     if (!InputFile)
    464       1.1    jruoho     {
    465   1.1.1.8  christos         printf ("Could not open input file %s\n", InputPathname);
    466       1.1    jruoho         return (-1);
    467       1.1    jruoho     }
    468       1.1    jruoho 
    469   1.1.1.9  christos     if (!AxIsFileAscii (InputFile))
    470   1.1.1.9  christos     {
    471   1.1.1.9  christos         fclose (InputFile);
    472   1.1.1.9  christos         return (-1);
    473   1.1.1.9  christos     }
    474   1.1.1.9  christos 
    475  1.1.1.11  christos     /* Info header */
    476  1.1.1.11  christos 
    477  1.1.1.11  christos     printf ("\n Signature  Length    Version Oem       Oem         "
    478  1.1.1.11  christos         "Oem         Compiler Compiler\n");
    479  1.1.1.11  christos     printf (  "                              Id        TableId     "
    480  1.1.1.11  christos         "RevisionId  Name     Revision\n");
    481  1.1.1.11  christos     printf (  " _________  __________  ____  ________  __________  "
    482  1.1.1.11  christos         "__________  _______  __________\n\n");
    483       1.1    jruoho 
    484  1.1.1.11  christos     /* Dump the headers for all tables found in the input file */
    485       1.1    jruoho 
    486   1.1.1.8  christos     while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
    487       1.1    jruoho     {
    488  1.1.1.11  christos         /* Ignore empty lines */
    489       1.1    jruoho 
    490  1.1.1.11  christos         if (AxIsEmptyLine (Gbl_LineBuffer))
    491       1.1    jruoho         {
    492       1.1    jruoho             continue;
    493       1.1    jruoho         }
    494       1.1    jruoho 
    495  1.1.1.11  christos         /*
    496  1.1.1.11  christos          * Check up front if we have a header line of the form:
    497  1.1.1.11  christos          * DSDT @ 0xdfffd0c0 (10999 bytes)
    498  1.1.1.11  christos          */
    499  1.1.1.11  christos         if (AX_IS_TABLE_BLOCK_HEADER &&
    500  1.1.1.11  christos             (State == AX_STATE_EXTRACT_DATA))
    501       1.1    jruoho         {
    502  1.1.1.11  christos             State = AX_STATE_FIND_HEADER;
    503       1.1    jruoho         }
    504       1.1    jruoho 
    505  1.1.1.11  christos         switch (State)
    506       1.1    jruoho         {
    507  1.1.1.11  christos         case AX_STATE_FIND_HEADER:
    508       1.1    jruoho 
    509  1.1.1.11  christos             ByteCount = 0;
    510  1.1.1.11  christos             if (!AxIsDataBlockHeader ())
    511  1.1.1.11  christos             {
    512  1.1.1.11  christos                 continue;
    513  1.1.1.11  christos             }
    514       1.1    jruoho 
    515  1.1.1.11  christos             State = AX_STATE_EXTRACT_DATA;
    516       1.1    jruoho             continue;
    517       1.1    jruoho 
    518  1.1.1.11  christos         case AX_STATE_EXTRACT_DATA:
    519   1.1.1.9  christos 
    520  1.1.1.11  christos             /* Ignore any lines that don't look like a data line */
    521       1.1    jruoho 
    522  1.1.1.11  christos             if (!AxIsHexDataLine ())
    523  1.1.1.11  christos             {
    524  1.1.1.11  christos                 continue;   /* Toss any lines that are not raw hex data */
    525  1.1.1.11  christos             }
    526       1.1    jruoho 
    527  1.1.1.11  christos             /* Convert header to hex and display it */
    528       1.1    jruoho 
    529  1.1.1.13  christos             ThisLineByteCount = AxConvertToBinary (Gbl_LineBuffer,
    530  1.1.1.13  christos                 &Header[ByteCount]);
    531  1.1.1.13  christos             if (ThisLineByteCount == EOF)
    532  1.1.1.13  christos             {
    533  1.1.1.13  christos                 fclose (InputFile);
    534  1.1.1.13  christos                 return (-1);
    535  1.1.1.13  christos             }
    536  1.1.1.13  christos 
    537  1.1.1.13  christos             ByteCount += ThisLineByteCount;
    538  1.1.1.11  christos             if (ByteCount >= sizeof (ACPI_TABLE_HEADER))
    539  1.1.1.11  christos             {
    540  1.1.1.11  christos                 AxDumpTableHeader (Header);
    541  1.1.1.11  christos                 State = AX_STATE_FIND_HEADER;
    542  1.1.1.11  christos             }
    543       1.1    jruoho             continue;
    544       1.1    jruoho 
    545  1.1.1.11  christos         default:
    546  1.1.1.11  christos             break;
    547  1.1.1.11  christos         }
    548       1.1    jruoho     }
    549       1.1    jruoho 
    550   1.1.1.9  christos     printf ("\nFound %u ACPI tables in %s\n", Gbl_TableCount, InputPathname);
    551       1.1    jruoho     fclose (InputFile);
    552       1.1    jruoho     return (0);
    553       1.1    jruoho }
    554