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