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