Home | History | Annotate | Line # | Download | only in acpibin
abcompare.c revision 1.1.1.9
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: abcompare - compare AML files
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7      1.1    jruoho /*
      8  1.1.1.9  christos  * Copyright (C) 2000 - 2018, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11      1.1    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1    jruoho  * modification, are permitted provided that the following conditions
     13      1.1    jruoho  * are met:
     14      1.1    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1    jruoho  *    without modification.
     17      1.1    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1    jruoho  *    binary redistribution.
     22      1.1    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1    jruoho  *    from this software without specific prior written permission.
     25      1.1    jruoho  *
     26      1.1    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1    jruoho  * Software Foundation.
     29      1.1    jruoho  *
     30      1.1    jruoho  * NO WARRANTY
     31      1.1    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #include "acpibin.h"
     45      1.1    jruoho 
     46      1.1    jruoho 
     47      1.1    jruoho ACPI_TABLE_HEADER           Header1;
     48      1.1    jruoho ACPI_TABLE_HEADER           Header2;
     49      1.1    jruoho 
     50      1.1    jruoho #define BUFFER_SIZE         256
     51      1.1    jruoho char                        Buffer[BUFFER_SIZE];
     52      1.1    jruoho 
     53      1.1    jruoho 
     54      1.1    jruoho /* Local prototypes */
     55      1.1    jruoho 
     56      1.1    jruoho static BOOLEAN
     57      1.1    jruoho AbValidateHeader (
     58      1.1    jruoho     ACPI_TABLE_HEADER       *Header);
     59      1.1    jruoho 
     60      1.1    jruoho static UINT8
     61      1.1    jruoho AcpiTbSumTable (
     62      1.1    jruoho     void                    *Buffer,
     63      1.1    jruoho     UINT32                  Length);
     64      1.1    jruoho 
     65      1.1    jruoho static char *
     66      1.1    jruoho AbGetFile (
     67      1.1    jruoho     char                    *Filename,
     68      1.1    jruoho     UINT32                  *FileSize);
     69      1.1    jruoho 
     70      1.1    jruoho static void
     71      1.1    jruoho AbPrintHeaderInfo (
     72      1.1    jruoho     ACPI_TABLE_HEADER       *Header);
     73      1.1    jruoho 
     74  1.1.1.2  christos static void
     75  1.1.1.2  christos AbPrintHeadersInfo (
     76  1.1.1.2  christos     ACPI_TABLE_HEADER       *Header,
     77  1.1.1.2  christos     ACPI_TABLE_HEADER       *Header2);
     78  1.1.1.2  christos 
     79      1.1    jruoho 
     80      1.1    jruoho /******************************************************************************
     81      1.1    jruoho  *
     82      1.1    jruoho  * FUNCTION:    AbValidateHeader
     83      1.1    jruoho  *
     84      1.1    jruoho  * DESCRIPTION: Check for valid ACPI table header
     85      1.1    jruoho  *
     86      1.1    jruoho  ******************************************************************************/
     87      1.1    jruoho 
     88      1.1    jruoho static BOOLEAN
     89      1.1    jruoho AbValidateHeader (
     90      1.1    jruoho     ACPI_TABLE_HEADER       *Header)
     91      1.1    jruoho {
     92      1.1    jruoho 
     93  1.1.1.6  christos     if (!AcpiUtValidNameseg (Header->Signature))
     94      1.1    jruoho     {
     95      1.1    jruoho         printf ("Header signature is invalid\n");
     96  1.1.1.2  christos         return (FALSE);
     97      1.1    jruoho     }
     98      1.1    jruoho 
     99  1.1.1.2  christos     return (TRUE);
    100      1.1    jruoho }
    101      1.1    jruoho 
    102      1.1    jruoho 
    103      1.1    jruoho /*******************************************************************************
    104      1.1    jruoho  *
    105      1.1    jruoho  * FUNCTION:    AcpiTbSumTable
    106      1.1    jruoho  *
    107      1.1    jruoho  * PARAMETERS:  Buffer              - Buffer to checksum
    108      1.1    jruoho  *              Length              - Size of the buffer
    109      1.1    jruoho  *
    110      1.1    jruoho  * RETURNS      8 bit checksum of buffer
    111      1.1    jruoho  *
    112      1.1    jruoho  * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
    113      1.1    jruoho  *
    114      1.1    jruoho  ******************************************************************************/
    115      1.1    jruoho 
    116      1.1    jruoho static UINT8
    117      1.1    jruoho AcpiTbSumTable (
    118      1.1    jruoho     void                    *Buffer,
    119      1.1    jruoho     UINT32                  Length)
    120      1.1    jruoho {
    121  1.1.1.3  christos     const UINT8             *Limit;
    122  1.1.1.3  christos     const UINT8             *Rover;
    123  1.1.1.3  christos     UINT8                   Sum = 0;
    124      1.1    jruoho 
    125      1.1    jruoho 
    126      1.1    jruoho     if (Buffer && Length)
    127      1.1    jruoho     {
    128      1.1    jruoho         /* Buffer and Length are valid */
    129      1.1    jruoho 
    130  1.1.1.3  christos         Limit = (UINT8 *) Buffer + Length;
    131      1.1    jruoho 
    132  1.1.1.3  christos         for (Rover = Buffer; Rover < Limit; Rover++)
    133      1.1    jruoho         {
    134  1.1.1.3  christos             Sum = (UINT8) (Sum + *Rover);
    135      1.1    jruoho         }
    136      1.1    jruoho     }
    137  1.1.1.3  christos 
    138  1.1.1.3  christos     return (Sum);
    139      1.1    jruoho }
    140      1.1    jruoho 
    141      1.1    jruoho 
    142      1.1    jruoho /*******************************************************************************
    143      1.1    jruoho  *
    144      1.1    jruoho  * FUNCTION:    AbPrintHeaderInfo
    145      1.1    jruoho  *
    146      1.1    jruoho  * PARAMETERS:  Header              - An ACPI table header
    147      1.1    jruoho  *
    148      1.1    jruoho  * RETURNS      None.
    149      1.1    jruoho  *
    150      1.1    jruoho  * DESCRIPTION: Format and display header contents.
    151      1.1    jruoho  *
    152      1.1    jruoho  ******************************************************************************/
    153      1.1    jruoho 
    154      1.1    jruoho static void
    155      1.1    jruoho AbPrintHeaderInfo (
    156      1.1    jruoho     ACPI_TABLE_HEADER       *Header)
    157      1.1    jruoho {
    158      1.1    jruoho 
    159      1.1    jruoho     /* Display header information */
    160      1.1    jruoho 
    161      1.1    jruoho     printf ("Signature         : %4.4s\n",    Header->Signature);
    162      1.1    jruoho     printf ("Length            : %8.8X\n",    Header->Length);
    163      1.1    jruoho     printf ("Revision          : %2.2X\n",    Header->Revision);
    164      1.1    jruoho     printf ("Checksum          : %2.2X\n",    Header->Checksum);
    165  1.1.1.3  christos     printf ("OEM ID            : %.6s\n",     Header->OemId);
    166  1.1.1.3  christos     printf ("OEM Table ID      : %.8s\n",     Header->OemTableId);
    167      1.1    jruoho     printf ("OEM Revision      : %8.8X\n",    Header->OemRevision);
    168  1.1.1.3  christos     printf ("ASL Compiler ID   : %.4s\n",     Header->AslCompilerId);
    169      1.1    jruoho     printf ("Compiler Revision : %8.8X\n",    Header->AslCompilerRevision);
    170      1.1    jruoho     printf ("\n");
    171      1.1    jruoho }
    172      1.1    jruoho 
    173  1.1.1.2  christos static void
    174  1.1.1.2  christos AbPrintHeadersInfo (
    175  1.1.1.2  christos     ACPI_TABLE_HEADER       *Header,
    176  1.1.1.2  christos     ACPI_TABLE_HEADER       *Header2)
    177  1.1.1.2  christos {
    178  1.1.1.2  christos 
    179  1.1.1.2  christos     /* Display header information for both headers */
    180  1.1.1.2  christos 
    181  1.1.1.2  christos     printf ("Signature          %8.4s : %4.4s\n",    Header->Signature, Header2->Signature);
    182  1.1.1.2  christos     printf ("Length             %8.8X : %8.8X\n",    Header->Length, Header2->Length);
    183  1.1.1.2  christos     printf ("Revision           %8.2X : %2.2X\n",    Header->Revision, Header2->Revision);
    184  1.1.1.2  christos     printf ("Checksum           %8.2X : %2.2X\n",    Header->Checksum, Header2->Checksum);
    185  1.1.1.3  christos     printf ("OEM ID             %8.6s : %.6s\n",     Header->OemId, Header2->OemId);
    186  1.1.1.3  christos     printf ("OEM Table ID       %8.8s : %.8s\n",     Header->OemTableId, Header2->OemTableId);
    187  1.1.1.2  christos     printf ("OEM Revision       %8.8X : %8.8X\n",    Header->OemRevision, Header2->OemRevision);
    188  1.1.1.3  christos     printf ("ASL Compiler ID    %8.4s : %.4s\n",     Header->AslCompilerId, Header2->AslCompilerId);
    189  1.1.1.2  christos     printf ("Compiler Revision  %8.8X : %8.8X\n",    Header->AslCompilerRevision, Header2->AslCompilerRevision);
    190  1.1.1.2  christos     printf ("\n");
    191  1.1.1.2  christos }
    192  1.1.1.2  christos 
    193      1.1    jruoho 
    194      1.1    jruoho /******************************************************************************
    195      1.1    jruoho  *
    196      1.1    jruoho  * FUNCTION:    AbDisplayHeader
    197      1.1    jruoho  *
    198      1.1    jruoho  * DESCRIPTION: Display an ACPI table header
    199      1.1    jruoho  *
    200      1.1    jruoho  ******************************************************************************/
    201      1.1    jruoho 
    202      1.1    jruoho void
    203      1.1    jruoho AbDisplayHeader (
    204  1.1.1.3  christos     char                    *FilePath)
    205      1.1    jruoho {
    206  1.1.1.2  christos     UINT32                  Actual;
    207  1.1.1.3  christos     FILE                    *File;
    208      1.1    jruoho 
    209      1.1    jruoho 
    210  1.1.1.3  christos     File = fopen (FilePath, "rb");
    211  1.1.1.3  christos     if (!File)
    212      1.1    jruoho     {
    213  1.1.1.3  christos         printf ("Could not open file %s\n", FilePath);
    214      1.1    jruoho         return;
    215      1.1    jruoho     }
    216      1.1    jruoho 
    217  1.1.1.3  christos     Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File);
    218  1.1.1.3  christos     fclose (File);
    219  1.1.1.3  christos 
    220  1.1.1.2  christos     if (Actual != sizeof (ACPI_TABLE_HEADER))
    221      1.1    jruoho     {
    222  1.1.1.3  christos         printf ("File %s does not contain a valid ACPI table header\n", FilePath);
    223      1.1    jruoho         return;
    224      1.1    jruoho     }
    225      1.1    jruoho 
    226      1.1    jruoho     if (!AbValidateHeader (&Header1))
    227      1.1    jruoho     {
    228      1.1    jruoho         return;
    229      1.1    jruoho     }
    230      1.1    jruoho 
    231      1.1    jruoho     AbPrintHeaderInfo (&Header1);
    232      1.1    jruoho }
    233      1.1    jruoho 
    234      1.1    jruoho 
    235      1.1    jruoho /******************************************************************************
    236      1.1    jruoho  *
    237      1.1    jruoho  * FUNCTION:    AbComputeChecksum
    238      1.1    jruoho  *
    239      1.1    jruoho  * DESCRIPTION: Compute proper checksum for an ACPI table
    240      1.1    jruoho  *
    241      1.1    jruoho  ******************************************************************************/
    242      1.1    jruoho 
    243      1.1    jruoho void
    244      1.1    jruoho AbComputeChecksum (
    245  1.1.1.3  christos     char                    *FilePath)
    246      1.1    jruoho {
    247  1.1.1.2  christos     UINT32                  Actual;
    248      1.1    jruoho     ACPI_TABLE_HEADER       *Table;
    249      1.1    jruoho     UINT8                   Checksum;
    250  1.1.1.3  christos     FILE                    *File;
    251      1.1    jruoho 
    252      1.1    jruoho 
    253  1.1.1.3  christos     File = fopen (FilePath, "rb");
    254  1.1.1.3  christos     if (!File)
    255      1.1    jruoho     {
    256  1.1.1.3  christos         printf ("Could not open file %s\n", FilePath);
    257      1.1    jruoho         return;
    258      1.1    jruoho     }
    259      1.1    jruoho 
    260  1.1.1.3  christos     Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File);
    261  1.1.1.2  christos     if (Actual < sizeof (ACPI_TABLE_HEADER))
    262      1.1    jruoho     {
    263  1.1.1.3  christos         printf ("File %s does not contain a valid ACPI table header\n", FilePath);
    264  1.1.1.3  christos         goto Exit1;
    265      1.1    jruoho     }
    266      1.1    jruoho 
    267      1.1    jruoho     if (!AbValidateHeader (&Header1))
    268      1.1    jruoho     {
    269  1.1.1.3  christos         goto Exit1;
    270      1.1    jruoho     }
    271      1.1    jruoho 
    272      1.1    jruoho     if (!Gbl_TerseMode)
    273      1.1    jruoho     {
    274      1.1    jruoho         AbPrintHeaderInfo (&Header1);
    275      1.1    jruoho     }
    276      1.1    jruoho 
    277      1.1    jruoho     /* Allocate a buffer to hold the entire table */
    278      1.1    jruoho 
    279      1.1    jruoho     Table = AcpiOsAllocate (Header1.Length);
    280      1.1    jruoho     if (!Table)
    281      1.1    jruoho     {
    282  1.1.1.3  christos         printf ("Could not allocate buffer for table\n");
    283  1.1.1.3  christos         goto Exit1;
    284      1.1    jruoho     }
    285      1.1    jruoho 
    286      1.1    jruoho     /* Read the entire table, including header */
    287      1.1    jruoho 
    288  1.1.1.3  christos     fseek (File, 0, SEEK_SET);
    289  1.1.1.3  christos     Actual = fread (Table, 1, Header1.Length, File);
    290  1.1.1.2  christos     if (Actual != Header1.Length)
    291      1.1    jruoho     {
    292  1.1.1.3  christos         printf ("Could not read table, length %u\n", Header1.Length);
    293  1.1.1.3  christos         goto Exit2;
    294      1.1    jruoho     }
    295      1.1    jruoho 
    296      1.1    jruoho     /* Compute the checksum for the table */
    297      1.1    jruoho 
    298      1.1    jruoho     Table->Checksum = 0;
    299      1.1    jruoho 
    300      1.1    jruoho     Checksum = (UINT8) (0 - AcpiTbSumTable (Table, Table->Length));
    301      1.1    jruoho     printf ("Computed checksum: 0x%X\n\n", Checksum);
    302      1.1    jruoho 
    303      1.1    jruoho     if (Header1.Checksum == Checksum)
    304      1.1    jruoho     {
    305  1.1.1.3  christos         printf ("Checksum OK in AML file, not updating\n");
    306  1.1.1.3  christos         goto Exit2;
    307      1.1    jruoho     }
    308      1.1    jruoho 
    309      1.1    jruoho     /* Open the target file for writing, to update checksum */
    310      1.1    jruoho 
    311  1.1.1.3  christos     fclose (File);
    312  1.1.1.3  christos     File = fopen (FilePath, "r+b");
    313  1.1.1.3  christos     if (!File)
    314      1.1    jruoho     {
    315  1.1.1.3  christos         printf ("Could not open file %s for writing\n", FilePath);
    316  1.1.1.3  christos         goto Exit2;
    317      1.1    jruoho     }
    318      1.1    jruoho 
    319      1.1    jruoho     /* Set the checksum, write the new header */
    320      1.1    jruoho 
    321      1.1    jruoho     Header1.Checksum = Checksum;
    322      1.1    jruoho 
    323  1.1.1.3  christos     Actual = fwrite (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File);
    324  1.1.1.2  christos     if (Actual != sizeof (ACPI_TABLE_HEADER))
    325      1.1    jruoho     {
    326      1.1    jruoho         printf ("Could not write updated table header\n");
    327  1.1.1.3  christos         goto Exit2;
    328      1.1    jruoho     }
    329      1.1    jruoho 
    330      1.1    jruoho     printf ("Wrote new checksum\n");
    331  1.1.1.3  christos 
    332  1.1.1.3  christos Exit2:
    333  1.1.1.3  christos     AcpiOsFree (Table);
    334  1.1.1.3  christos 
    335  1.1.1.3  christos Exit1:
    336  1.1.1.3  christos     if (File)
    337  1.1.1.3  christos     {
    338  1.1.1.3  christos         fclose (File);
    339  1.1.1.3  christos     }
    340      1.1    jruoho     return;
    341      1.1    jruoho }
    342      1.1    jruoho 
    343      1.1    jruoho 
    344      1.1    jruoho /******************************************************************************
    345      1.1    jruoho  *
    346      1.1    jruoho  * FUNCTION:    AbCompareAmlFiles
    347      1.1    jruoho  *
    348      1.1    jruoho  * DESCRIPTION: Compare two AML files
    349      1.1    jruoho  *
    350      1.1    jruoho  ******************************************************************************/
    351      1.1    jruoho 
    352      1.1    jruoho int
    353      1.1    jruoho AbCompareAmlFiles (
    354      1.1    jruoho     char                    *File1Path,
    355      1.1    jruoho     char                    *File2Path)
    356      1.1    jruoho {
    357      1.1    jruoho     UINT32                  Actual1;
    358      1.1    jruoho     UINT32                  Actual2;
    359      1.1    jruoho     UINT32                  Offset;
    360      1.1    jruoho     UINT8                   Char1;
    361      1.1    jruoho     UINT8                   Char2;
    362      1.1    jruoho     UINT8                   Mismatches = 0;
    363      1.1    jruoho     BOOLEAN                 HeaderMismatch = FALSE;
    364  1.1.1.3  christos     FILE                    *File1;
    365  1.1.1.3  christos     FILE                    *File2;
    366  1.1.1.3  christos     int                     Status = -1;
    367      1.1    jruoho 
    368      1.1    jruoho 
    369      1.1    jruoho     File1 = fopen (File1Path, "rb");
    370      1.1    jruoho     if (!File1)
    371      1.1    jruoho     {
    372      1.1    jruoho         printf ("Could not open file %s\n", File1Path);
    373  1.1.1.2  christos         return (-1);
    374      1.1    jruoho     }
    375      1.1    jruoho 
    376      1.1    jruoho     File2 = fopen (File2Path, "rb");
    377      1.1    jruoho     if (!File2)
    378      1.1    jruoho     {
    379      1.1    jruoho         printf ("Could not open file %s\n", File2Path);
    380  1.1.1.3  christos         goto Exit1;
    381      1.1    jruoho     }
    382      1.1    jruoho 
    383      1.1    jruoho     /* Read the ACPI header from each file */
    384      1.1    jruoho 
    385      1.1    jruoho     Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1);
    386  1.1.1.2  christos     if (Actual1 != sizeof (ACPI_TABLE_HEADER))
    387      1.1    jruoho     {
    388      1.1    jruoho         printf ("File %s does not contain an ACPI table header\n", File1Path);
    389  1.1.1.3  christos         goto Exit2;
    390      1.1    jruoho     }
    391      1.1    jruoho 
    392      1.1    jruoho     Actual2 = fread (&Header2, 1, sizeof (ACPI_TABLE_HEADER), File2);
    393  1.1.1.2  christos     if (Actual2 != sizeof (ACPI_TABLE_HEADER))
    394      1.1    jruoho     {
    395      1.1    jruoho         printf ("File %s does not contain an ACPI table header\n", File2Path);
    396  1.1.1.3  christos         goto Exit2;
    397      1.1    jruoho     }
    398      1.1    jruoho 
    399      1.1    jruoho     if ((!AbValidateHeader (&Header1)) ||
    400      1.1    jruoho         (!AbValidateHeader (&Header2)))
    401      1.1    jruoho     {
    402  1.1.1.3  christos         goto Exit2;
    403      1.1    jruoho     }
    404      1.1    jruoho 
    405      1.1    jruoho     /* Table signatures must match */
    406      1.1    jruoho 
    407      1.1    jruoho     if (*((UINT32 *) Header1.Signature) != *((UINT32 *) Header2.Signature))
    408      1.1    jruoho     {
    409      1.1    jruoho         printf ("Table signatures do not match\n");
    410  1.1.1.3  christos         goto Exit2;
    411      1.1    jruoho     }
    412      1.1    jruoho 
    413      1.1    jruoho     if (!Gbl_TerseMode)
    414      1.1    jruoho     {
    415      1.1    jruoho         /* Display header information */
    416      1.1    jruoho 
    417  1.1.1.8  christos         printf ("Comparing %s to %s\n", File1Path, File2Path);
    418  1.1.1.2  christos         AbPrintHeadersInfo (&Header1, &Header2);
    419      1.1    jruoho     }
    420      1.1    jruoho 
    421  1.1.1.2  christos     if (memcmp (&Header1, &Header2, sizeof (ACPI_TABLE_HEADER)))
    422      1.1    jruoho     {
    423      1.1    jruoho         printf ("Headers do not match exactly\n");
    424      1.1    jruoho         HeaderMismatch = TRUE;
    425      1.1    jruoho     }
    426      1.1    jruoho 
    427      1.1    jruoho     /* Do the byte-by-byte compare */
    428      1.1    jruoho 
    429  1.1.1.8  christos     printf ("Compare offset: %u\n", AbGbl_CompareOffset);
    430  1.1.1.8  christos     if (AbGbl_CompareOffset)
    431  1.1.1.8  christos     {
    432  1.1.1.8  christos         fseek (File2, AbGbl_CompareOffset, SEEK_CUR);
    433  1.1.1.8  christos     }
    434  1.1.1.8  christos 
    435      1.1    jruoho     Actual1 = fread (&Char1, 1, 1, File1);
    436      1.1    jruoho     Actual2 = fread (&Char2, 1, 1, File2);
    437      1.1    jruoho     Offset = sizeof (ACPI_TABLE_HEADER);
    438      1.1    jruoho 
    439  1.1.1.2  christos     while ((Actual1 == 1) && (Actual2 == 1))
    440      1.1    jruoho     {
    441      1.1    jruoho         if (Char1 != Char2)
    442      1.1    jruoho         {
    443  1.1.1.7  christos             printf ("Error - Byte mismatch at offset %8.4X: 0x%2.2X 0x%2.2X\n",
    444      1.1    jruoho                 Offset, Char1, Char2);
    445      1.1    jruoho             Mismatches++;
    446  1.1.1.8  christos             if ((Mismatches > 100) && (!AbGbl_DisplayAllMiscompares))
    447      1.1    jruoho             {
    448      1.1    jruoho                 printf ("100 Mismatches: Too many mismatches\n");
    449  1.1.1.3  christos                 goto Exit2;
    450      1.1    jruoho             }
    451      1.1    jruoho         }
    452      1.1    jruoho 
    453      1.1    jruoho         Offset++;
    454      1.1    jruoho         Actual1 = fread (&Char1, 1, 1, File1);
    455      1.1    jruoho         Actual2 = fread (&Char2, 1, 1, File2);
    456      1.1    jruoho     }
    457      1.1    jruoho 
    458      1.1    jruoho     if (Actual1)
    459      1.1    jruoho     {
    460      1.1    jruoho         printf ("Error - file %s is longer than file %s\n", File1Path, File2Path);
    461      1.1    jruoho         Mismatches++;
    462      1.1    jruoho     }
    463      1.1    jruoho     else if (Actual2)
    464      1.1    jruoho     {
    465      1.1    jruoho         printf ("Error - file %s is shorter than file %s\n", File1Path, File2Path);
    466      1.1    jruoho         Mismatches++;
    467      1.1    jruoho     }
    468      1.1    jruoho     else if (!Mismatches)
    469      1.1    jruoho     {
    470      1.1    jruoho         if (HeaderMismatch)
    471      1.1    jruoho         {
    472      1.1    jruoho             printf ("Files compare exactly after header\n");
    473      1.1    jruoho         }
    474      1.1    jruoho         else
    475      1.1    jruoho         {
    476      1.1    jruoho             printf ("Files compare exactly\n");
    477      1.1    jruoho         }
    478      1.1    jruoho     }
    479      1.1    jruoho 
    480      1.1    jruoho     printf ("%u Mismatches found\n", Mismatches);
    481  1.1.1.7  christos     if (Mismatches == 0)
    482  1.1.1.7  christos     {
    483  1.1.1.7  christos         Status = 0;
    484  1.1.1.7  christos     }
    485      1.1    jruoho 
    486  1.1.1.3  christos Exit2:
    487  1.1.1.3  christos     fclose (File2);
    488      1.1    jruoho 
    489  1.1.1.3  christos Exit1:
    490  1.1.1.3  christos     fclose (File1);
    491  1.1.1.3  christos     return (Status);
    492  1.1.1.2  christos }
    493  1.1.1.2  christos 
    494  1.1.1.2  christos 
    495  1.1.1.2  christos /******************************************************************************
    496  1.1.1.2  christos  *
    497  1.1.1.2  christos  * FUNCTION:    AbGetFile
    498      1.1    jruoho  *
    499      1.1    jruoho  * DESCRIPTION: Open a file and read it entirely into a new buffer
    500      1.1    jruoho  *
    501      1.1    jruoho  ******************************************************************************/
    502      1.1    jruoho 
    503      1.1    jruoho static char *
    504      1.1    jruoho AbGetFile (
    505      1.1    jruoho     char                    *Filename,
    506      1.1    jruoho     UINT32                  *FileSize)
    507      1.1    jruoho {
    508  1.1.1.2  christos     FILE                    *File;
    509      1.1    jruoho     UINT32                  Size;
    510      1.1    jruoho     char                    *Buffer = NULL;
    511  1.1.1.2  christos     size_t                  Actual;
    512      1.1    jruoho 
    513      1.1    jruoho 
    514      1.1    jruoho     /* Binary mode does not alter CR/LF pairs */
    515      1.1    jruoho 
    516  1.1.1.2  christos     File = fopen (Filename, "rb");
    517  1.1.1.2  christos     if (!File)
    518      1.1    jruoho     {
    519  1.1.1.2  christos         printf ("Could not open file %s\n", Filename);
    520  1.1.1.2  christos         return (NULL);
    521      1.1    jruoho     }
    522      1.1    jruoho 
    523      1.1    jruoho     /* Need file size to allocate a buffer */
    524      1.1    jruoho 
    525  1.1.1.3  christos     Size = CmGetFileSize (File);
    526  1.1.1.3  christos     if (Size == ACPI_UINT32_MAX)
    527      1.1    jruoho     {
    528  1.1.1.2  christos         printf ("Could not get file size (seek) for %s\n", Filename);
    529      1.1    jruoho         goto ErrorExit;
    530      1.1    jruoho     }
    531      1.1    jruoho 
    532      1.1    jruoho     /* Allocate a buffer for the entire file */
    533      1.1    jruoho 
    534      1.1    jruoho     Buffer = calloc (Size, 1);
    535      1.1    jruoho     if (!Buffer)
    536      1.1    jruoho     {
    537      1.1    jruoho         printf ("Could not allocate buffer of size %u\n", Size);
    538      1.1    jruoho         goto ErrorExit;
    539      1.1    jruoho     }
    540      1.1    jruoho 
    541      1.1    jruoho     /* Read the entire file */
    542      1.1    jruoho 
    543  1.1.1.2  christos     Actual = fread (Buffer, 1, Size, File);
    544  1.1.1.2  christos     if (Actual != Size)
    545      1.1    jruoho     {
    546      1.1    jruoho         printf ("Could not read the input file %s\n", Filename);
    547      1.1    jruoho         free (Buffer);
    548      1.1    jruoho         Buffer = NULL;
    549      1.1    jruoho         goto ErrorExit;
    550      1.1    jruoho     }
    551      1.1    jruoho 
    552      1.1    jruoho     *FileSize = Size;
    553      1.1    jruoho 
    554      1.1    jruoho ErrorExit:
    555  1.1.1.2  christos     fclose (File);
    556      1.1    jruoho     return (Buffer);
    557      1.1    jruoho }
    558      1.1    jruoho 
    559      1.1    jruoho 
    560      1.1    jruoho /******************************************************************************
    561      1.1    jruoho  *
    562      1.1    jruoho  * FUNCTION:    AbDumpAmlFile
    563      1.1    jruoho  *
    564      1.1    jruoho  * DESCRIPTION: Dump a binary AML file to a text file
    565      1.1    jruoho  *
    566      1.1    jruoho  ******************************************************************************/
    567      1.1    jruoho 
    568      1.1    jruoho int
    569      1.1    jruoho AbDumpAmlFile (
    570      1.1    jruoho     char                    *File1Path,
    571      1.1    jruoho     char                    *File2Path)
    572      1.1    jruoho {
    573      1.1    jruoho     char                    *FileBuffer;
    574      1.1    jruoho     FILE                    *FileOutHandle;
    575  1.1.1.2  christos     UINT32                  FileSize = 0;
    576  1.1.1.3  christos     int                     Status = -1;
    577      1.1    jruoho 
    578      1.1    jruoho 
    579      1.1    jruoho     /* Get the entire AML file, validate header */
    580      1.1    jruoho 
    581      1.1    jruoho     FileBuffer = AbGetFile (File1Path, &FileSize);
    582  1.1.1.2  christos     if (!FileBuffer)
    583  1.1.1.2  christos     {
    584  1.1.1.2  christos         return (-1);
    585  1.1.1.2  christos     }
    586  1.1.1.2  christos 
    587  1.1.1.2  christos     printf ("Input file:  %s contains %u (0x%X) bytes\n",
    588  1.1.1.2  christos         File1Path, FileSize, FileSize);
    589      1.1    jruoho 
    590      1.1    jruoho     FileOutHandle = fopen (File2Path, "wb");
    591      1.1    jruoho     if (!FileOutHandle)
    592      1.1    jruoho     {
    593  1.1.1.2  christos         printf ("Could not open file %s\n", File2Path);
    594  1.1.1.3  christos         goto Exit1;
    595      1.1    jruoho     }
    596      1.1    jruoho 
    597      1.1    jruoho     if (!AbValidateHeader ((ACPI_TABLE_HEADER *) FileBuffer))
    598      1.1    jruoho     {
    599  1.1.1.3  christos         goto Exit2;
    600      1.1    jruoho     }
    601      1.1    jruoho 
    602      1.1    jruoho     /* Convert binary AML to text, using common dump buffer routine */
    603      1.1    jruoho 
    604      1.1    jruoho     AcpiGbl_DebugFile = FileOutHandle;
    605      1.1    jruoho     AcpiGbl_DbOutputFlags = ACPI_DB_REDIRECTABLE_OUTPUT;
    606      1.1    jruoho 
    607  1.1.1.2  christos     AcpiOsPrintf ("%4.4s @ 0x%8.8X\n",
    608  1.1.1.2  christos         ((ACPI_TABLE_HEADER *) FileBuffer)->Signature, 0);
    609  1.1.1.2  christos 
    610  1.1.1.2  christos     AcpiUtDumpBuffer ((UINT8 *) FileBuffer, FileSize, DB_BYTE_DISPLAY, 0);
    611      1.1    jruoho 
    612  1.1.1.2  christos     /* Summary for the output file */
    613  1.1.1.2  christos 
    614  1.1.1.3  christos     FileSize = CmGetFileSize (FileOutHandle);
    615  1.1.1.2  christos     printf ("Output file: %s contains %u (0x%X) bytes\n\n",
    616  1.1.1.2  christos         File2Path, FileSize, FileSize);
    617  1.1.1.2  christos 
    618  1.1.1.3  christos     Status = 0;
    619      1.1    jruoho 
    620  1.1.1.3  christos Exit2:
    621      1.1    jruoho     fclose (FileOutHandle);
    622  1.1.1.3  christos 
    623  1.1.1.3  christos Exit1:
    624  1.1.1.3  christos     free (FileBuffer);
    625  1.1.1.3  christos     return (Status);
    626      1.1    jruoho }
    627