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