Home | History | Annotate | Line # | Download | only in acpixtract
acpixtract.c revision 1.1
      1 
      2 /******************************************************************************
      3  *
      4  * Module Name: acpixtract - convert ascii ACPI tables to binary
      5  *
      6  *****************************************************************************/
      7 
      8 /******************************************************************************
      9  *
     10  * 1. Copyright Notice
     11  *
     12  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     13  * All rights reserved.
     14  *
     15  * 2. License
     16  *
     17  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  * rights.  You may have additional license terms from the party that provided
     19  * you this software, covering your right to use that party's intellectual
     20  * property rights.
     21  *
     22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  * copy of the source code appearing in this file ("Covered Code") an
     24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  * make derivatives, distribute, use and display any portion of the Covered
     27  * Code in any form, with the right to sublicense such rights; and
     28  *
     29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  * license (with the right to sublicense), under only those claims of Intel
     31  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  * offer to sell, and import the Covered Code and derivative works thereof
     33  * solely to the minimum extent necessary to exercise the above copyright
     34  * license, and in no event shall the patent license extend to any additions
     35  * to or modifications of the Original Intel Code.  No other license or right
     36  * is granted directly or by implication, estoppel or otherwise;
     37  *
     38  * The above copyright and patent license is granted only if the following
     39  * conditions are met:
     40  *
     41  * 3. Conditions
     42  *
     43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  * Redistribution of source code of any substantial portion of the Covered
     45  * Code or modification with rights to further distribute source must include
     46  * the above Copyright Notice, the above License, this list of Conditions,
     47  * and the following Disclaimer and Export Compliance provision.  In addition,
     48  * Licensee must cause all Covered Code to which Licensee contributes to
     49  * contain a file documenting the changes Licensee made to create that Covered
     50  * Code and the date of any change.  Licensee must include in that file the
     51  * documentation of any changes made by any predecessor Licensee.  Licensee
     52  * must include a prominent statement that the modification is derived,
     53  * directly or indirectly, from Original Intel Code.
     54  *
     55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  * Redistribution of source code of any substantial portion of the Covered
     57  * Code or modification without rights to further distribute source must
     58  * include the following Disclaimer and Export Compliance provision in the
     59  * documentation and/or other materials provided with distribution.  In
     60  * addition, Licensee may not authorize further sublicense of source of any
     61  * portion of the Covered Code, and must include terms to the effect that the
     62  * license from Licensee to its licensee is limited to the intellectual
     63  * property embodied in the software Licensee provides to its licensee, and
     64  * not to intellectual property embodied in modifications its licensee may
     65  * make.
     66  *
     67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  * substantial portion of the Covered Code or modification must reproduce the
     69  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  * provision in the documentation and/or other materials provided with the
     71  * distribution.
     72  *
     73  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  * Intel Code.
     75  *
     76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  * other dealings in products derived from or relating to the Covered Code
     79  * without prior written authorization from Intel.
     80  *
     81  * 4. Disclaimer and Export Compliance
     82  *
     83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  * PARTICULAR PURPOSE.
     90  *
     91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  * LIMITED REMEDY.
     99  *
    100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  * software or system incorporating such software without first obtaining any
    102  * required license or other approval from the U. S. Department of Commerce or
    103  * any other agency or department of the United States Government.  In the
    104  * event Licensee exports any such software from the United States or
    105  * re-exports any such software from a foreign destination, Licensee shall
    106  * ensure that the distribution and export/re-export of the software is in
    107  * compliance with all laws, regulations, orders, or other restrictions of the
    108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  * any of its subsidiaries will export/re-export any technical data, process,
    110  * software, or service, directly or indirectly, to any country for which the
    111  * United States government or any agency thereof requires an export license,
    112  * other governmental approval, or letter of assurance, without first obtaining
    113  * such license, approval or letter.
    114  *
    115  *****************************************************************************/
    116 
    117 #include <stdio.h>
    118 #include <stdlib.h>
    119 #include <string.h>
    120 #include <ctype.h>
    121 
    122 
    123 /* Note: This is a 32-bit program only */
    124 
    125 #define VERSION             0x20100107
    126 #define FIND_HEADER         0
    127 #define EXTRACT_DATA        1
    128 #define BUFFER_SIZE         256
    129 
    130 
    131 /* Local prototypes */
    132 
    133 void
    134 CheckAscii (
    135     char                    *Name,
    136     int                     Count);
    137 
    138 void
    139 NormalizeSignature (
    140     char                    *Signature);
    141 
    142 unsigned int
    143 GetNextInstance (
    144     char                    *InputPathname,
    145     char                    *Signature);
    146 
    147 int
    148 ExtractTables (
    149     char                    *InputPathname,
    150     char                    *Signature,
    151     unsigned int            MinimumInstances);
    152 
    153 size_t
    154 GetTableHeader (
    155     FILE                    *InputFile,
    156     unsigned char           *OutputData);
    157 
    158 unsigned int
    159 CountTableInstances (
    160     char                    *InputPathname,
    161     char                    *Signature);
    162 
    163 int
    164 ListTables (
    165     char                    *InputPathname);
    166 
    167 size_t
    168 ConvertLine (
    169     char                    *InputLine,
    170     unsigned char           *OutputData);
    171 
    172 void
    173 DisplayUsage (
    174     void);
    175 
    176 
    177 typedef struct acpi_table_header
    178 {
    179     char                    Signature[4];
    180     int                     Length;
    181     unsigned char           Revision;
    182     unsigned char           Checksum;
    183     char                    OemId[6];
    184     char                    OemTableId[8];
    185     int                     OemRevision;
    186     char                    AslCompilerId[4];
    187     int                     AslCompilerRevision;
    188 
    189 } ACPI_TABLE_HEADER;
    190 
    191 struct TableInfo
    192 {
    193     unsigned int            Signature;
    194     unsigned int            Instances;
    195     unsigned int            NextInstance;
    196     struct TableInfo        *Next;
    197 };
    198 
    199 struct TableInfo            *ListHead = NULL;
    200 char                        Filename[16];
    201 unsigned char               Data[16];
    202 
    203 
    204 /******************************************************************************
    205  *
    206  * FUNCTION:    DisplayUsage
    207  *
    208  * DESCRIPTION: Usage message
    209  *
    210  ******************************************************************************/
    211 
    212 void
    213 DisplayUsage (
    214     void)
    215 {
    216 
    217     printf ("Usage: acpixtract [option] <InputFile>\n");
    218     printf ("\nExtract binary ACPI tables from text acpidump output\n");
    219     printf ("Default invocation extracts all DSDTs and SSDTs\n");
    220     printf ("Version %8.8X\n\n", VERSION);
    221     printf ("Options:\n");
    222     printf (" -a                    Extract all tables, not just DSDT/SSDT\n");
    223     printf (" -l                    List table summaries, do not extract\n");
    224     printf (" -s<Signature>         Extract all tables named <Signature>\n");
    225     printf ("\n");
    226 }
    227 
    228 
    229 /*******************************************************************************
    230  *
    231  * FUNCTION:    CheckAscii
    232  *
    233  * PARAMETERS:  Name                - Ascii string, at least as long as Count
    234  *              Count               - Number of characters to check
    235  *
    236  * RETURN:      None
    237  *
    238  * DESCRIPTION: Ensure that the requested number of characters are printable
    239  *              Ascii characters. Sets non-printable and null chars to <space>.
    240  *
    241  ******************************************************************************/
    242 
    243 void
    244 CheckAscii (
    245     char                    *Name,
    246     int                     Count)
    247 {
    248     int                     i;
    249 
    250 
    251     for (i = 0; i < Count; i++)
    252     {
    253         if (!Name[i] || !isprint ((int) Name[i]))
    254         {
    255             Name[i] = ' ';
    256         }
    257     }
    258 }
    259 
    260 
    261 /*******************************************************************************
    262  *
    263  * FUNCTION:    NormalizeSignature
    264  *
    265  * PARAMETERS:  Name                - Ascii string containing an ACPI signature
    266  *
    267  * RETURN:      None
    268  *
    269  * DESCRIPTION: Change "RSD PTR" to "RSDP"
    270  *
    271  ******************************************************************************/
    272 
    273 void
    274 NormalizeSignature (
    275     char                    *Signature)
    276 {
    277 
    278     if (!strncmp (Signature, "RSD ", 4))
    279     {
    280         Signature[3] = 'P';
    281     }
    282 }
    283 
    284 
    285 /******************************************************************************
    286  *
    287  * FUNCTION:    ConvertLine
    288  *
    289  * PARAMETERS:  InputLine           - One line from the input acpidump file
    290  *              OutputData          - Where the converted data is returned
    291  *
    292  * RETURN:      The number of bytes actually converted
    293  *
    294  * DESCRIPTION: Convert one line of ascii text binary (up to 16 bytes)
    295  *
    296  ******************************************************************************/
    297 
    298 size_t
    299 ConvertLine (
    300     char                    *InputLine,
    301     unsigned char           *OutputData)
    302 {
    303     char                    *End;
    304     int                     BytesConverted;
    305     int                     Converted[16];
    306     int                     i;
    307 
    308 
    309     /* Terminate the input line at the end of the actual data (for sscanf) */
    310 
    311     End = strstr (InputLine + 2, "  ");
    312     if (!End)
    313     {
    314         return (0); /* Don't understand the format */
    315     }
    316     *End = 0;
    317 
    318     /*
    319      * Convert one line of table data, of the form:
    320      * <offset>: <up to 16 bytes of hex data> <ASCII representation> <newline>
    321      *
    322      * Example:
    323      * 02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08  _SB_LNKD........
    324      */
    325     BytesConverted = sscanf (InputLine,
    326         "%*s %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
    327         &Converted[0],  &Converted[1],  &Converted[2],  &Converted[3],
    328         &Converted[4],  &Converted[5],  &Converted[6],  &Converted[7],
    329         &Converted[8],  &Converted[9],  &Converted[10], &Converted[11],
    330         &Converted[12], &Converted[13], &Converted[14], &Converted[15]);
    331 
    332     /* Pack converted data into a byte array */
    333 
    334     for (i = 0; i < BytesConverted; i++)
    335     {
    336         OutputData[i] = (unsigned char) Converted[i];
    337     }
    338 
    339     return ((size_t) BytesConverted);
    340 }
    341 
    342 
    343 /******************************************************************************
    344  *
    345  * FUNCTION:    GetTableHeader
    346  *
    347  * PARAMETERS:  InputFile           - Handle for the input acpidump file
    348  *              OutputData          - Where the table header is returned
    349  *
    350  * RETURN:      The actual number of bytes converted
    351  *
    352  * DESCRIPTION: Extract and convert an ACPI table header
    353  *
    354  ******************************************************************************/
    355 
    356 size_t
    357 GetTableHeader (
    358     FILE                    *InputFile,
    359     unsigned char           *OutputData)
    360 {
    361     size_t                  BytesConverted;
    362     size_t                  TotalConverted = 0;
    363     char                    Buffer[BUFFER_SIZE];
    364     int                     i;
    365 
    366 
    367     /* Get the full 36 byte header, requires 3 lines */
    368 
    369     for (i = 0; i < 3; i++)
    370     {
    371         if (!fgets (Buffer, BUFFER_SIZE, InputFile))
    372         {
    373             return (TotalConverted);
    374         }
    375 
    376         BytesConverted = ConvertLine (Buffer, OutputData);
    377         TotalConverted += BytesConverted;
    378         OutputData += 16;
    379 
    380         if (BytesConverted != 16)
    381         {
    382             return (TotalConverted);
    383         }
    384     }
    385 
    386     return (TotalConverted);
    387 }
    388 
    389 
    390 /******************************************************************************
    391  *
    392  * FUNCTION:    CountTableInstances
    393  *
    394  * PARAMETERS:  InputPathname       - Filename for acpidump file
    395  *              Signature           - Requested signature to count
    396  *
    397  * RETURN:      The number of instances of the signature
    398  *
    399  * DESCRIPTION: Count the instances of tables with the given signature within
    400  *              the input acpidump file.
    401  *
    402  ******************************************************************************/
    403 
    404 unsigned int
    405 CountTableInstances (
    406     char                    *InputPathname,
    407     char                    *Signature)
    408 {
    409     char                    Buffer[BUFFER_SIZE];
    410     FILE                    *InputFile;
    411     unsigned int            Instances = 0;
    412 
    413 
    414     InputFile = fopen (InputPathname, "rt");
    415     if (!InputFile)
    416     {
    417         printf ("Could not open %s\n", InputPathname);
    418         return (0);
    419     }
    420 
    421     /* Count the number of instances of this signature */
    422 
    423     while (fgets (Buffer, BUFFER_SIZE, InputFile))
    424     {
    425         /* Ignore empty lines and lines that start with a space */
    426 
    427         if ((Buffer[0] == ' ') ||
    428             (Buffer[0] == '\n'))
    429         {
    430             continue;
    431         }
    432 
    433         NormalizeSignature (Buffer);
    434         if (!strncmp (Buffer, Signature, 4))
    435         {
    436             Instances++;
    437         }
    438     }
    439 
    440     fclose (InputFile);
    441     return (Instances);
    442 }
    443 
    444 
    445 /******************************************************************************
    446  *
    447  * FUNCTION:    GetNextInstance
    448  *
    449  * PARAMETERS:  InputPathname       - Filename for acpidump file
    450  *              Signature           - Requested ACPI signature
    451  *
    452  * RETURN:      The next instance number for this signature. Zero if this
    453  *              is the first instance of this signature.
    454  *
    455  * DESCRIPTION: Get the next instance number of the specified table. If this
    456  *              is the first instance of the table, create a new instance
    457  *              block. Note: only SSDT and PSDT tables can have multiple
    458  *              instances.
    459  *
    460  ******************************************************************************/
    461 
    462 unsigned int
    463 GetNextInstance (
    464     char                    *InputPathname,
    465     char                    *Signature)
    466 {
    467     struct TableInfo        *Info;
    468 
    469 
    470     Info = ListHead;
    471     while (Info)
    472     {
    473         if (*(unsigned int *) Signature == Info->Signature)
    474         {
    475             break;
    476         }
    477 
    478         Info = Info->Next;
    479     }
    480 
    481     if (!Info)
    482     {
    483         /* Signature not found, create new table info block */
    484 
    485         Info = malloc (sizeof (struct TableInfo));
    486         if (!Info)
    487         {
    488             printf ("Could not allocate memory\n");
    489             exit (0);
    490         }
    491 
    492         Info->Signature = *(unsigned int *) Signature;
    493         Info->Instances = CountTableInstances (InputPathname, Signature);
    494         Info->NextInstance = 1;
    495         Info->Next = ListHead;
    496         ListHead = Info;
    497     }
    498 
    499     if (Info->Instances > 1)
    500     {
    501         return (Info->NextInstance++);
    502     }
    503 
    504     return (0);
    505 }
    506 
    507 
    508 /******************************************************************************
    509  *
    510  * FUNCTION:    ExtractTables
    511  *
    512  * PARAMETERS:  InputPathname       - Filename for acpidump file
    513  *              Signature           - Requested ACPI signature to extract.
    514  *                                    NULL means extract ALL tables.
    515  *              MinimumInstances    - Min instances that are acceptable
    516  *
    517  * RETURN:      Status
    518  *
    519  * DESCRIPTION: Convert text ACPI tables to binary
    520  *
    521  ******************************************************************************/
    522 
    523 int
    524 ExtractTables (
    525     char                    *InputPathname,
    526     char                    *Signature,
    527     unsigned int            MinimumInstances)
    528 {
    529     char                    Buffer[BUFFER_SIZE];
    530     FILE                    *InputFile;
    531     FILE                    *OutputFile = NULL;
    532     size_t                  BytesWritten;
    533     size_t                  TotalBytesWritten = 0;
    534     size_t                  BytesConverted;
    535     unsigned int            State = FIND_HEADER;
    536     unsigned int            FoundTable = 0;
    537     unsigned int            Instances = 0;
    538     unsigned int            ThisInstance;
    539     char                    ThisSignature[4];
    540     int                     Status = 0;
    541 
    542 
    543     /* Open input in text mode, output is in binary mode */
    544 
    545     InputFile = fopen (InputPathname, "rt");
    546     if (!InputFile)
    547     {
    548         printf ("Could not open %s\n", InputPathname);
    549         return (-1);
    550     }
    551 
    552     if (Signature)
    553     {
    554         /* Are there enough instances of the table to continue? */
    555 
    556         NormalizeSignature (Signature);
    557 
    558         Instances = CountTableInstances (InputPathname, Signature);
    559         if (Instances < MinimumInstances)
    560         {
    561             printf ("Table %s was not found in %s\n", Signature, InputPathname);
    562             Status = -1;
    563             goto CleanupAndExit;
    564         }
    565 
    566         if (Instances == 0)
    567         {
    568             goto CleanupAndExit;
    569         }
    570     }
    571 
    572     /* Convert all instances of the table to binary */
    573 
    574     while (fgets (Buffer, BUFFER_SIZE, InputFile))
    575     {
    576         switch (State)
    577         {
    578         case FIND_HEADER:
    579 
    580             /* Ignore empty lines and lines that start with a space */
    581 
    582             if ((Buffer[0] == ' ') ||
    583                 (Buffer[0] == '\n'))
    584             {
    585                 continue;
    586             }
    587 
    588             NormalizeSignature (Buffer);
    589             strncpy (ThisSignature, Buffer, 4);
    590 
    591             if (Signature)
    592             {
    593                 /* Ignore signatures that don't match */
    594 
    595                 if (strncmp (ThisSignature, Signature, 4))
    596                 {
    597                     continue;
    598                 }
    599             }
    600 
    601             /*
    602              * Get the instance number for this signature. Only the
    603              * SSDT and PSDT tables can have multiple instances.
    604              */
    605             ThisInstance = GetNextInstance (InputPathname, ThisSignature);
    606 
    607             /* Build an output filename and create/open the output file */
    608 
    609             if (ThisInstance > 0)
    610             {
    611                 sprintf (Filename, "%4.4s%u.dat", ThisSignature, ThisInstance);
    612             }
    613             else
    614             {
    615                 sprintf (Filename, "%4.4s.dat", ThisSignature);
    616             }
    617 
    618             OutputFile = fopen (Filename, "w+b");
    619             if (!OutputFile)
    620             {
    621                 printf ("Could not open %s\n", Filename);
    622                 Status = -1;
    623                 goto CleanupAndExit;
    624             }
    625 
    626             State = EXTRACT_DATA;
    627             TotalBytesWritten = 0;
    628             FoundTable = 1;
    629             continue;
    630 
    631         case EXTRACT_DATA:
    632 
    633             /* Empty line or non-data line terminates the data */
    634 
    635             if ((Buffer[0] == '\n') ||
    636                 (Buffer[0] != ' '))
    637             {
    638                 fclose (OutputFile);
    639                 OutputFile = NULL;
    640                 State = FIND_HEADER;
    641 
    642                 printf ("Acpi table [%4.4s] - % 7d bytes written to %s\n",
    643                     ThisSignature, TotalBytesWritten, Filename);
    644                 continue;
    645             }
    646 
    647             /* Convert the ascii data (one line of text) to binary */
    648 
    649             BytesConverted = ConvertLine (Buffer, Data);
    650 
    651             /* Write the binary data */
    652 
    653             BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile);
    654             if (BytesWritten != BytesConverted)
    655             {
    656                 printf ("Write error on %s\n", Filename);
    657                 fclose (OutputFile);
    658                 OutputFile = NULL;
    659                 Status = -1;
    660                 goto CleanupAndExit;
    661             }
    662 
    663             TotalBytesWritten += BytesConverted;
    664             continue;
    665 
    666         default:
    667             Status = -1;
    668             goto CleanupAndExit;
    669         }
    670     }
    671 
    672     if (!FoundTable)
    673     {
    674         printf ("Table %s was not found in %s\n", Signature, InputPathname);
    675     }
    676 
    677 
    678 CleanupAndExit:
    679 
    680     if (OutputFile)
    681     {
    682         fclose (OutputFile);
    683         if (State == EXTRACT_DATA)
    684         {
    685             /* Received an EOF while extracting data */
    686 
    687             printf ("Acpi table [%4.4s] - % 7d bytes written to %s\n",
    688                 ThisSignature, TotalBytesWritten, Filename);
    689         }
    690     }
    691 
    692     fclose (InputFile);
    693     return (Status);
    694 }
    695 
    696 
    697 /******************************************************************************
    698  *
    699  * FUNCTION:    ListTables
    700  *
    701  * PARAMETERS:  InputPathname       - Filename for acpidump file
    702  *
    703  * RETURN:      Status
    704  *
    705  * DESCRIPTION: Display info for all ACPI tables found in input. Does not
    706  *              perform an actual extraction of the tables.
    707  *
    708  ******************************************************************************/
    709 
    710 int
    711 ListTables (
    712     char                    *InputPathname)
    713 {
    714     FILE                    *InputFile;
    715     char                    Buffer[BUFFER_SIZE];
    716     size_t                  HeaderSize;
    717     unsigned char           Header[48];
    718     int                     TableCount = 0;
    719     ACPI_TABLE_HEADER       *TableHeader = (ACPI_TABLE_HEADER *) (void *) Header;
    720 
    721 
    722     /* Open input in text mode, output is in binary mode */
    723 
    724     InputFile = fopen (InputPathname, "rt");
    725     if (!InputFile)
    726     {
    727         printf ("Could not open %s\n", InputPathname);
    728         return (-1);
    729     }
    730 
    731     /* Dump the headers for all tables found in the input file */
    732 
    733     printf ("\nSignature Length Revision  OemId     OemTableId"
    734             "   OemRevision CompilerId CompilerRevision\n\n");
    735 
    736     while (fgets (Buffer, BUFFER_SIZE, InputFile))
    737     {
    738         /* Ignore empty lines and lines that start with a space */
    739 
    740         if ((Buffer[0] == ' ') ||
    741             (Buffer[0] == '\n'))
    742         {
    743             continue;
    744         }
    745 
    746         /* Get the 36 byte header and display the fields */
    747 
    748         HeaderSize = GetTableHeader (InputFile, Header);
    749         if (HeaderSize < 16)
    750         {
    751             continue;
    752         }
    753 
    754         /* RSDP has an oddball signature and header */
    755 
    756         if (!strncmp (TableHeader->Signature, "RSD PTR ", 8))
    757         {
    758             CheckAscii ((char *) &Header[9], 6);
    759             printf ("%8.4s                   \"%6.6s\"\n", "RSDP", &Header[9]);
    760             TableCount++;
    761             continue;
    762         }
    763 
    764         /* Minimum size for table with standard header */
    765 
    766         if (HeaderSize < 36)
    767         {
    768             continue;
    769         }
    770 
    771         /* Signature and Table length */
    772 
    773         TableCount++;
    774         printf ("%8.4s % 7d", TableHeader->Signature, TableHeader->Length);
    775 
    776         /* FACS has only signature and length */
    777 
    778         if (!strncmp (TableHeader->Signature, "FACS", 4))
    779         {
    780             printf ("\n");
    781             continue;
    782         }
    783 
    784         /* OEM IDs and Compiler IDs */
    785 
    786         CheckAscii (TableHeader->OemId, 6);
    787         CheckAscii (TableHeader->OemTableId, 8);
    788         CheckAscii (TableHeader->AslCompilerId, 4);
    789 
    790         printf ("     %2.2X    \"%6.6s\"  \"%8.8s\"    %8.8X    \"%4.4s\"     %8.8X\n",
    791             TableHeader->Revision, TableHeader->OemId,
    792             TableHeader->OemTableId, TableHeader->OemRevision,
    793             TableHeader->AslCompilerId, TableHeader->AslCompilerRevision);
    794     }
    795 
    796     printf ("\nFound %u ACPI tables [%8.8X]\n", TableCount, VERSION);
    797     fclose (InputFile);
    798     return (0);
    799 }
    800 
    801 
    802 /******************************************************************************
    803  *
    804  * FUNCTION:    main
    805  *
    806  * DESCRIPTION: C main function
    807  *
    808  ******************************************************************************/
    809 
    810 int
    811 main (
    812     int                     argc,
    813     char                    *argv[])
    814 {
    815     int                     Status;
    816 
    817 
    818     if (argc < 2)
    819     {
    820         DisplayUsage ();
    821         return (0);
    822     }
    823 
    824     if (argv[1][0] == '-')
    825     {
    826         if (argc < 3)
    827         {
    828             DisplayUsage ();
    829             return (0);
    830         }
    831 
    832         switch (argv[1][1])
    833         {
    834         case 'a':
    835 
    836             /* Extract all tables found */
    837 
    838             return (ExtractTables (argv[2], NULL, 0));
    839 
    840         case 'l':
    841 
    842             /* List tables only, do not extract */
    843 
    844             return (ListTables (argv[2]));
    845 
    846         case 's':
    847 
    848             /* Extract only tables with this signature */
    849 
    850             return (ExtractTables (argv[2], &argv[1][2], 1));
    851 
    852         default:
    853             DisplayUsage ();
    854             return (0);
    855         }
    856     }
    857 
    858     /*
    859      * Default output is the DSDT and all SSDTs. One DSDT is required,
    860      * any SSDTs are optional.
    861      */
    862     Status = ExtractTables (argv[1], "DSDT", 1);
    863     if (Status)
    864     {
    865         return (Status);
    866     }
    867 
    868     Status = ExtractTables (argv[1], "SSDT", 0);
    869     return (Status);
    870 }
    871 
    872 
    873