Home | History | Annotate | Line # | Download | only in acpixtract
acpixtract.c revision 1.1.1.11
      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.10  christos  * Copyright (C) 2000 - 2017, 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.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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.8  christos     unsigned int            BytesConverted;
     72   1.1.1.8  christos     unsigned 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.9  christos         strncpy (UpperSignature, Signature, 4);
    100   1.1.1.9  christos         UpperSignature[4] = 0;
    101   1.1.1.9  christos         AcpiUtStrupr (UpperSignature);
    102   1.1.1.9  christos 
    103   1.1.1.8  christos         /* Are there enough instances of the table to continue? */
    104       1.1    jruoho 
    105   1.1.1.9  christos         AxNormalizeSignature (UpperSignature);
    106   1.1.1.9  christos         Instances = AxCountTableInstances (InputPathname, UpperSignature);
    107  1.1.1.11  christos 
    108   1.1.1.8  christos         if (Instances < MinimumInstances)
    109   1.1.1.8  christos         {
    110   1.1.1.8  christos             printf ("Table [%s] was not found in %s\n",
    111   1.1.1.9  christos                 UpperSignature, InputPathname);
    112   1.1.1.8  christos             fclose (InputFile);
    113  1.1.1.11  christos             return (0);             /* Don't abort */
    114   1.1.1.8  christos         }
    115       1.1    jruoho 
    116   1.1.1.8  christos         if (Instances == 0)
    117   1.1.1.8  christos         {
    118   1.1.1.8  christos             fclose (InputFile);
    119   1.1.1.8  christos             return (-1);
    120   1.1.1.8  christos         }
    121       1.1    jruoho     }
    122       1.1    jruoho 
    123   1.1.1.8  christos     /* Convert all instances of the table to binary */
    124       1.1    jruoho 
    125   1.1.1.8  christos     while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
    126       1.1    jruoho     {
    127  1.1.1.11  christos         /*
    128  1.1.1.11  christos          * Check up front if we have a header line of the form:
    129  1.1.1.11  christos          * DSDT @ 0xdfffd0c0 (10999 bytes)
    130  1.1.1.11  christos          */
    131  1.1.1.11  christos         if (AX_IS_TABLE_BLOCK_HEADER &&
    132  1.1.1.11  christos             (State == AX_STATE_EXTRACT_DATA))
    133  1.1.1.11  christos         {
    134  1.1.1.11  christos             /* End of previous table, start of new table */
    135  1.1.1.11  christos 
    136  1.1.1.11  christos             if (ThisTableBytesWritten)
    137  1.1.1.11  christos             {
    138  1.1.1.11  christos                 printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    139  1.1.1.11  christos                     ThisTableBytesWritten, Gbl_OutputFilename);
    140  1.1.1.11  christos             }
    141  1.1.1.11  christos             else
    142  1.1.1.11  christos             {
    143  1.1.1.11  christos                 Gbl_TableCount--;
    144  1.1.1.11  christos             }
    145  1.1.1.11  christos 
    146  1.1.1.11  christos             State = AX_STATE_FIND_HEADER;
    147  1.1.1.11  christos         }
    148  1.1.1.11  christos 
    149   1.1.1.8  christos         switch (State)
    150   1.1.1.8  christos         {
    151   1.1.1.8  christos         case AX_STATE_FIND_HEADER:
    152       1.1    jruoho 
    153   1.1.1.8  christos             if (!AxIsDataBlockHeader ())
    154   1.1.1.8  christos             {
    155   1.1.1.8  christos                 continue;
    156   1.1.1.8  christos             }
    157       1.1    jruoho 
    158   1.1.1.8  christos             ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer);
    159   1.1.1.8  christos             if (Signature)
    160   1.1.1.8  christos             {
    161   1.1.1.8  christos                 /* Ignore signatures that don't match */
    162       1.1    jruoho 
    163   1.1.1.9  christos                 if (!ACPI_COMPARE_NAME (ThisSignature, UpperSignature))
    164   1.1.1.8  christos                 {
    165   1.1.1.8  christos                     continue;
    166   1.1.1.8  christos                 }
    167   1.1.1.8  christos             }
    168       1.1    jruoho 
    169   1.1.1.8  christos             /*
    170   1.1.1.8  christos              * Get the instance number for this signature. Only the
    171   1.1.1.8  christos              * SSDT and PSDT tables can have multiple instances.
    172   1.1.1.8  christos              */
    173   1.1.1.8  christos             ThisInstance = AxGetNextInstance (InputPathname, ThisSignature);
    174       1.1    jruoho 
    175   1.1.1.8  christos             /* Build an output filename and create/open the output file */
    176       1.1    jruoho 
    177   1.1.1.8  christos             if (ThisInstance > 0)
    178   1.1.1.8  christos             {
    179   1.1.1.8  christos                 /* Add instance number to the output filename */
    180       1.1    jruoho 
    181   1.1.1.8  christos                 sprintf (Gbl_OutputFilename, "%4.4s%u.dat",
    182   1.1.1.8  christos                     ThisSignature, ThisInstance);
    183   1.1.1.8  christos             }
    184   1.1.1.8  christos             else
    185   1.1.1.8  christos             {
    186   1.1.1.8  christos                 sprintf (Gbl_OutputFilename, "%4.4s.dat",
    187   1.1.1.8  christos                     ThisSignature);
    188   1.1.1.8  christos             }
    189       1.1    jruoho 
    190   1.1.1.8  christos             AcpiUtStrlwr (Gbl_OutputFilename);
    191   1.1.1.8  christos             OutputFile = fopen (Gbl_OutputFilename, "w+b");
    192   1.1.1.8  christos             if (!OutputFile)
    193   1.1.1.8  christos             {
    194   1.1.1.8  christos                 printf ("Could not open output file %s\n",
    195   1.1.1.8  christos                     Gbl_OutputFilename);
    196   1.1.1.8  christos                 fclose (InputFile);
    197   1.1.1.8  christos                 return (-1);
    198   1.1.1.8  christos             }
    199       1.1    jruoho 
    200   1.1.1.8  christos             /*
    201   1.1.1.8  christos              * Toss this block header of the form "<sig> @ <addr>" line
    202   1.1.1.8  christos              * and move on to the actual data block
    203   1.1.1.8  christos              */
    204   1.1.1.8  christos             Gbl_TableCount++;
    205   1.1.1.8  christos             FoundTable = 1;
    206   1.1.1.8  christos             ThisTableBytesWritten = 0;
    207   1.1.1.8  christos             State = AX_STATE_EXTRACT_DATA;
    208   1.1.1.8  christos             continue;
    209       1.1    jruoho 
    210   1.1.1.8  christos         case AX_STATE_EXTRACT_DATA:
    211       1.1    jruoho 
    212  1.1.1.11  christos             if (!AxIsHexDataLine ())
    213  1.1.1.11  christos             {
    214  1.1.1.11  christos                 continue;   /* Toss any lines that are not raw hex data */
    215  1.1.1.11  christos             }
    216  1.1.1.11  christos 
    217   1.1.1.8  christos             /* Empty line or non-data line terminates the data block */
    218       1.1    jruoho 
    219  1.1.1.11  christos             BytesConverted = AxConvertAndWrite (OutputFile, ThisSignature,
    220  1.1.1.11  christos                 ThisTableBytesWritten);
    221   1.1.1.8  christos             switch (BytesConverted)
    222   1.1.1.8  christos             {
    223   1.1.1.8  christos             case 0:
    224       1.1    jruoho 
    225   1.1.1.8  christos                 State = AX_STATE_FIND_HEADER; /* No more data block lines */
    226   1.1.1.8  christos                 continue;
    227       1.1    jruoho 
    228   1.1.1.8  christos             case -1:
    229       1.1    jruoho 
    230   1.1.1.8  christos                 goto CleanupAndExit; /* There was a write error */
    231       1.1    jruoho 
    232   1.1.1.8  christos             default: /* Normal case, get next line */
    233       1.1    jruoho 
    234   1.1.1.8  christos                 ThisTableBytesWritten += BytesConverted;
    235   1.1.1.8  christos                 continue;
    236   1.1.1.8  christos             }
    237       1.1    jruoho 
    238   1.1.1.8  christos         default:
    239       1.1    jruoho 
    240   1.1.1.8  christos             Status = -1;
    241   1.1.1.8  christos             goto CleanupAndExit;
    242       1.1    jruoho         }
    243       1.1    jruoho     }
    244       1.1    jruoho 
    245   1.1.1.8  christos     if (!FoundTable)
    246   1.1.1.8  christos     {
    247   1.1.1.9  christos         printf ("No ACPI tables were found in %s\n", InputPathname);
    248   1.1.1.8  christos     }
    249       1.1    jruoho 
    250       1.1    jruoho 
    251   1.1.1.8  christos CleanupAndExit:
    252       1.1    jruoho 
    253   1.1.1.8  christos     if (State == AX_STATE_EXTRACT_DATA)
    254       1.1    jruoho     {
    255   1.1.1.8  christos         /* Received an input file EOF while extracting data */
    256       1.1    jruoho 
    257  1.1.1.11  christos         printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    258  1.1.1.11  christos             ThisTableBytesWritten, Gbl_OutputFilename);
    259       1.1    jruoho     }
    260       1.1    jruoho 
    261   1.1.1.8  christos     if (OutputFile)
    262       1.1    jruoho     {
    263   1.1.1.8  christos         fclose (OutputFile);
    264       1.1    jruoho     }
    265       1.1    jruoho 
    266   1.1.1.8  christos     fclose (InputFile);
    267   1.1.1.8  christos     return (Status);
    268       1.1    jruoho }
    269       1.1    jruoho 
    270       1.1    jruoho 
    271       1.1    jruoho /******************************************************************************
    272       1.1    jruoho  *
    273   1.1.1.8  christos  * FUNCTION:    AxExtractToMultiAmlFile
    274       1.1    jruoho  *
    275   1.1.1.8  christos  * PARAMETERS:  InputPathname       - Filename for input acpidump file
    276       1.1    jruoho  *
    277       1.1    jruoho  * RETURN:      Status
    278       1.1    jruoho  *
    279   1.1.1.8  christos  * DESCRIPTION: Convert all DSDT/SSDT tables to binary and append them all
    280   1.1.1.8  christos  *              into a single output file. Used to simplify the loading of
    281   1.1.1.8  christos  *              multiple/many SSDTs into a utility like acpiexec -- instead
    282   1.1.1.8  christos  *              of creating many separate output files.
    283       1.1    jruoho  *
    284       1.1    jruoho  ******************************************************************************/
    285       1.1    jruoho 
    286   1.1.1.4  christos int
    287   1.1.1.8  christos AxExtractToMultiAmlFile (
    288   1.1.1.8  christos     char                    *InputPathname)
    289       1.1    jruoho {
    290       1.1    jruoho     FILE                    *InputFile;
    291   1.1.1.8  christos     FILE                    *OutputFile;
    292       1.1    jruoho     int                     Status = 0;
    293   1.1.1.8  christos     unsigned int            TotalBytesWritten = 0;
    294   1.1.1.8  christos     unsigned int            ThisTableBytesWritten = 0;
    295  1.1.1.11  christos     unsigned int            BytesConverted;
    296   1.1.1.8  christos     char                    ThisSignature[4];
    297   1.1.1.8  christos     unsigned int            State = AX_STATE_FIND_HEADER;
    298       1.1    jruoho 
    299       1.1    jruoho 
    300   1.1.1.8  christos     strcpy (Gbl_OutputFilename, AX_MULTI_TABLE_FILENAME);
    301   1.1.1.8  christos 
    302   1.1.1.8  christos     /* Open the input file in text mode */
    303       1.1    jruoho 
    304  1.1.1.10  christos     InputFile = fopen (InputPathname, "r");
    305       1.1    jruoho     if (!InputFile)
    306       1.1    jruoho     {
    307   1.1.1.8  christos         printf ("Could not open input file %s\n", InputPathname);
    308       1.1    jruoho         return (-1);
    309       1.1    jruoho     }
    310       1.1    jruoho 
    311   1.1.1.9  christos     if (!AxIsFileAscii (InputFile))
    312   1.1.1.9  christos     {
    313   1.1.1.9  christos         fclose (InputFile);
    314   1.1.1.9  christos         return (-1);
    315   1.1.1.9  christos     }
    316   1.1.1.9  christos 
    317   1.1.1.8  christos     /* Open the output file in binary mode */
    318       1.1    jruoho 
    319   1.1.1.8  christos     OutputFile = fopen (Gbl_OutputFilename, "w+b");
    320   1.1.1.8  christos     if (!OutputFile)
    321   1.1.1.8  christos     {
    322   1.1.1.8  christos         printf ("Could not open output file %s\n", Gbl_OutputFilename);
    323   1.1.1.8  christos         fclose (InputFile);
    324   1.1.1.8  christos         return (-1);
    325       1.1    jruoho     }
    326       1.1    jruoho 
    327   1.1.1.8  christos     /* Convert the DSDT and all SSDTs to binary */
    328       1.1    jruoho 
    329   1.1.1.8  christos     while (fgets (Gbl_LineBuffer, AX_LINE_BUFFER_SIZE, InputFile))
    330       1.1    jruoho     {
    331  1.1.1.11  christos         /*
    332  1.1.1.11  christos          * Check up front if we have a header line of the form:
    333  1.1.1.11  christos          * DSDT @ 0xdfffd0c0 (10999 bytes)
    334  1.1.1.11  christos          */
    335  1.1.1.11  christos         if (AX_IS_TABLE_BLOCK_HEADER &&
    336  1.1.1.11  christos             (State == AX_STATE_EXTRACT_DATA))
    337  1.1.1.11  christos         {
    338  1.1.1.11  christos             /* End of previous table, start of new table */
    339  1.1.1.11  christos 
    340  1.1.1.11  christos             if (ThisTableBytesWritten)
    341  1.1.1.11  christos             {
    342  1.1.1.11  christos                 printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    343  1.1.1.11  christos                     ThisTableBytesWritten, Gbl_OutputFilename);
    344  1.1.1.11  christos             }
    345  1.1.1.11  christos             else
    346  1.1.1.11  christos             {
    347  1.1.1.11  christos                 Gbl_TableCount--;
    348  1.1.1.11  christos             }
    349  1.1.1.11  christos 
    350  1.1.1.11  christos             State = AX_STATE_FIND_HEADER;
    351  1.1.1.11  christos         }
    352  1.1.1.11  christos 
    353       1.1    jruoho         switch (State)
    354       1.1    jruoho         {
    355   1.1.1.4  christos         case AX_STATE_FIND_HEADER:
    356       1.1    jruoho 
    357   1.1.1.8  christos             if (!AxIsDataBlockHeader ())
    358   1.1.1.3    jruoho             {
    359   1.1.1.3    jruoho                 continue;
    360   1.1.1.3    jruoho             }
    361   1.1.1.3    jruoho 
    362   1.1.1.8  christos             ACPI_MOVE_NAME (ThisSignature, Gbl_LineBuffer);
    363       1.1    jruoho 
    364   1.1.1.8  christos             /* Only want DSDT and SSDTs */
    365       1.1    jruoho 
    366   1.1.1.8  christos             if (!ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_DSDT) &&
    367   1.1.1.8  christos                 !ACPI_COMPARE_NAME (ThisSignature, ACPI_SIG_SSDT))
    368   1.1.1.3    jruoho             {
    369   1.1.1.3    jruoho                 continue;
    370   1.1.1.3    jruoho             }
    371   1.1.1.3    jruoho 
    372       1.1    jruoho             /*
    373   1.1.1.8  christos              * Toss this block header of the form "<sig> @ <addr>" line
    374   1.1.1.8  christos              * and move on to the actual data block
    375       1.1    jruoho              */
    376   1.1.1.8  christos             Gbl_TableCount++;
    377   1.1.1.8  christos             ThisTableBytesWritten = 0;
    378   1.1.1.4  christos             State = AX_STATE_EXTRACT_DATA;
    379       1.1    jruoho             continue;
    380       1.1    jruoho 
    381   1.1.1.4  christos         case AX_STATE_EXTRACT_DATA:
    382       1.1    jruoho 
    383  1.1.1.11  christos             if (!AxIsHexDataLine ())
    384  1.1.1.11  christos             {
    385  1.1.1.11  christos                 continue;   /* Toss any lines that are not raw hex data */
    386  1.1.1.11  christos             }
    387  1.1.1.11  christos 
    388   1.1.1.8  christos             /* Empty line or non-data line terminates the data block */
    389       1.1    jruoho 
    390  1.1.1.11  christos             BytesConverted = AxConvertAndWrite (
    391   1.1.1.8  christos                 OutputFile, ThisSignature, ThisTableBytesWritten);
    392   1.1.1.8  christos             switch (BytesConverted)
    393       1.1    jruoho             {
    394   1.1.1.8  christos             case 0:
    395       1.1    jruoho 
    396   1.1.1.8  christos                 State = AX_STATE_FIND_HEADER; /* No more data block lines */
    397       1.1    jruoho                 continue;
    398       1.1    jruoho 
    399   1.1.1.8  christos             case -1:
    400       1.1    jruoho 
    401   1.1.1.8  christos                 goto CleanupAndExit; /* There was a write error */
    402       1.1    jruoho 
    403   1.1.1.8  christos             default: /* Normal case, get next line */
    404       1.1    jruoho 
    405   1.1.1.8  christos                 ThisTableBytesWritten += BytesConverted;
    406   1.1.1.8  christos                 TotalBytesWritten += BytesConverted;
    407   1.1.1.8  christos                 continue;
    408       1.1    jruoho             }
    409       1.1    jruoho 
    410       1.1    jruoho         default:
    411   1.1.1.4  christos 
    412       1.1    jruoho             Status = -1;
    413       1.1    jruoho             goto CleanupAndExit;
    414       1.1    jruoho         }
    415       1.1    jruoho     }
    416       1.1    jruoho 
    417       1.1    jruoho 
    418       1.1    jruoho CleanupAndExit:
    419       1.1    jruoho 
    420   1.1.1.8  christos     if (State == AX_STATE_EXTRACT_DATA)
    421       1.1    jruoho     {
    422   1.1.1.8  christos         /* Received an input file EOF or error while writing data */
    423       1.1    jruoho 
    424  1.1.1.11  christos         printf (AX_TABLE_INFO_FORMAT, ThisSignature, ThisTableBytesWritten,
    425  1.1.1.11  christos             ThisTableBytesWritten, Gbl_OutputFilename);
    426       1.1    jruoho     }
    427       1.1    jruoho 
    428   1.1.1.9  christos     printf ("\n%u binary ACPI tables extracted and written to %s (%u bytes)\n",
    429   1.1.1.8  christos         Gbl_TableCount, Gbl_OutputFilename, TotalBytesWritten);
    430   1.1.1.8  christos 
    431       1.1    jruoho     fclose (InputFile);
    432   1.1.1.8  christos     fclose (OutputFile);
    433       1.1    jruoho     return (Status);
    434       1.1    jruoho }
    435       1.1    jruoho 
    436       1.1    jruoho 
    437       1.1    jruoho /******************************************************************************
    438       1.1    jruoho  *
    439  1.1.1.11  christos  * FUNCTION:    AxListAllTables
    440       1.1    jruoho  *
    441       1.1    jruoho  * PARAMETERS:  InputPathname       - Filename for acpidump file
    442       1.1    jruoho  *
    443       1.1    jruoho  * RETURN:      Status
    444       1.1    jruoho  *
    445       1.1    jruoho  * DESCRIPTION: Display info for all ACPI tables found in input. Does not
    446       1.1    jruoho  *              perform an actual extraction of the tables.
    447       1.1    jruoho  *
    448       1.1    jruoho  ******************************************************************************/
    449       1.1    jruoho 
    450   1.1.1.4  christos int
    451  1.1.1.11  christos AxListAllTables (
    452       1.1    jruoho     char                    *InputPathname)
    453       1.1    jruoho {
    454       1.1    jruoho     FILE                    *InputFile;
    455       1.1    jruoho     unsigned char           Header[48];
    456  1.1.1.11  christos     UINT32                  ByteCount = 0;
    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.11  christos             ByteCount += AxConvertToBinary (Gbl_LineBuffer, &Header[ByteCount]);
    530  1.1.1.11  christos             if (ByteCount >= sizeof (ACPI_TABLE_HEADER))
    531  1.1.1.11  christos             {
    532  1.1.1.11  christos                 AxDumpTableHeader (Header);
    533  1.1.1.11  christos                 State = AX_STATE_FIND_HEADER;
    534  1.1.1.11  christos             }
    535       1.1    jruoho             continue;
    536       1.1    jruoho 
    537  1.1.1.11  christos         default:
    538  1.1.1.11  christos             break;
    539  1.1.1.11  christos         }
    540       1.1    jruoho     }
    541       1.1    jruoho 
    542   1.1.1.9  christos     printf ("\nFound %u ACPI tables in %s\n", Gbl_TableCount, InputPathname);
    543       1.1    jruoho     fclose (InputFile);
    544       1.1    jruoho     return (0);
    545       1.1    jruoho }
    546