Home | History | Annotate | Line # | Download | only in acpibin
abcompare.c revision 1.1.1.1.2.1
      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.1.2.1    yamt  * Copyright (C) 2000 - 2013, 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 FILE                        *File1;
     48          1.1  jruoho FILE                        *File2;
     49          1.1  jruoho ACPI_TABLE_HEADER           Header1;
     50          1.1  jruoho ACPI_TABLE_HEADER           Header2;
     51          1.1  jruoho 
     52          1.1  jruoho #define BUFFER_SIZE         256
     53          1.1  jruoho char                        Buffer[BUFFER_SIZE];
     54          1.1  jruoho 
     55          1.1  jruoho 
     56          1.1  jruoho /* Local prototypes */
     57          1.1  jruoho 
     58          1.1  jruoho static BOOLEAN
     59          1.1  jruoho AbValidateHeader (
     60          1.1  jruoho     ACPI_TABLE_HEADER       *Header);
     61          1.1  jruoho 
     62          1.1  jruoho static UINT8
     63          1.1  jruoho AcpiTbSumTable (
     64          1.1  jruoho     void                    *Buffer,
     65          1.1  jruoho     UINT32                  Length);
     66          1.1  jruoho 
     67          1.1  jruoho static char *
     68          1.1  jruoho AbGetFile (
     69          1.1  jruoho     char                    *Filename,
     70          1.1  jruoho     UINT32                  *FileSize);
     71          1.1  jruoho 
     72  1.1.1.1.2.1    yamt static UINT32
     73  1.1.1.1.2.1    yamt AbGetFileSize (
     74  1.1.1.1.2.1    yamt     FILE                    *File);
     75  1.1.1.1.2.1    yamt 
     76          1.1  jruoho static void
     77          1.1  jruoho AbPrintHeaderInfo (
     78          1.1  jruoho     ACPI_TABLE_HEADER       *Header);
     79          1.1  jruoho 
     80  1.1.1.1.2.1    yamt static void
     81  1.1.1.1.2.1    yamt AbPrintHeadersInfo (
     82  1.1.1.1.2.1    yamt     ACPI_TABLE_HEADER       *Header,
     83  1.1.1.1.2.1    yamt     ACPI_TABLE_HEADER       *Header2);
     84  1.1.1.1.2.1    yamt 
     85          1.1  jruoho ACPI_PHYSICAL_ADDRESS
     86          1.1  jruoho AeLocalGetRootPointer (
     87          1.1  jruoho     void);
     88          1.1  jruoho 
     89          1.1  jruoho 
     90          1.1  jruoho /*******************************************************************************
     91          1.1  jruoho  *
     92          1.1  jruoho  * FUNCTION:    UtHexCharToValue
     93          1.1  jruoho  *
     94          1.1  jruoho  * PARAMETERS:  HexChar         - Hex character in Ascii
     95          1.1  jruoho  *
     96          1.1  jruoho  * RETURN:      The binary value of the hex character
     97          1.1  jruoho  *
     98          1.1  jruoho  * DESCRIPTION: Perform ascii-to-hex translation
     99          1.1  jruoho  *
    100          1.1  jruoho  ******************************************************************************/
    101          1.1  jruoho 
    102          1.1  jruoho static UINT8
    103          1.1  jruoho UtHexCharToValue (
    104          1.1  jruoho     int                     HexChar,
    105          1.1  jruoho     UINT8                   *OutBinary)
    106          1.1  jruoho {
    107          1.1  jruoho 
    108          1.1  jruoho     if (HexChar >= 0x30 && HexChar <= 0x39)
    109          1.1  jruoho     {
    110          1.1  jruoho         *OutBinary = (UINT8) (HexChar - 0x30);
    111          1.1  jruoho         return (1);
    112          1.1  jruoho     }
    113          1.1  jruoho 
    114          1.1  jruoho     else if (HexChar >= 0x41 && HexChar <= 0x46)
    115          1.1  jruoho     {
    116          1.1  jruoho         *OutBinary = (UINT8) (HexChar - 0x37);
    117          1.1  jruoho         return (1);
    118          1.1  jruoho     }
    119          1.1  jruoho 
    120          1.1  jruoho     else if (HexChar >= 0x61 && HexChar <= 0x66)
    121          1.1  jruoho     {
    122          1.1  jruoho         *OutBinary = (UINT8) (HexChar - 0x57);
    123          1.1  jruoho         return (1);
    124          1.1  jruoho     }
    125          1.1  jruoho     return (0);
    126          1.1  jruoho }
    127          1.1  jruoho 
    128          1.1  jruoho static UINT8
    129          1.1  jruoho AbHexByteToBinary (
    130          1.1  jruoho     char                    *HexString,
    131          1.1  jruoho     char                    *OutBinary)
    132          1.1  jruoho {
    133          1.1  jruoho     UINT8                   Local1;
    134          1.1  jruoho     UINT8                   Local2;
    135          1.1  jruoho 
    136          1.1  jruoho 
    137          1.1  jruoho     if (!UtHexCharToValue (HexString[0], &Local1))
    138          1.1  jruoho     {
    139          1.1  jruoho         return (0);
    140          1.1  jruoho     }
    141          1.1  jruoho     if (!UtHexCharToValue (HexString[1], &Local2))
    142          1.1  jruoho     {
    143          1.1  jruoho         return (0);
    144          1.1  jruoho     }
    145          1.1  jruoho 
    146          1.1  jruoho     *OutBinary = (UINT8) ((Local1 << 4) | Local2);
    147          1.1  jruoho     return (2);
    148          1.1  jruoho 
    149          1.1  jruoho }
    150          1.1  jruoho 
    151          1.1  jruoho 
    152          1.1  jruoho /******************************************************************************
    153          1.1  jruoho  *
    154          1.1  jruoho  * FUNCTION:    AbValidateHeader
    155          1.1  jruoho  *
    156          1.1  jruoho  * DESCRIPTION: Check for valid ACPI table header
    157          1.1  jruoho  *
    158          1.1  jruoho  ******************************************************************************/
    159          1.1  jruoho 
    160          1.1  jruoho static BOOLEAN
    161          1.1  jruoho AbValidateHeader (
    162          1.1  jruoho     ACPI_TABLE_HEADER       *Header)
    163          1.1  jruoho {
    164          1.1  jruoho 
    165  1.1.1.1.2.1    yamt     if (!AcpiUtValidAcpiName (Header->Signature))
    166          1.1  jruoho     {
    167          1.1  jruoho         printf ("Header signature is invalid\n");
    168  1.1.1.1.2.1    yamt         return (FALSE);
    169          1.1  jruoho     }
    170          1.1  jruoho 
    171  1.1.1.1.2.1    yamt     return (TRUE);
    172          1.1  jruoho }
    173          1.1  jruoho 
    174          1.1  jruoho 
    175          1.1  jruoho /*******************************************************************************
    176          1.1  jruoho  *
    177          1.1  jruoho  * FUNCTION:    AcpiTbSumTable
    178          1.1  jruoho  *
    179          1.1  jruoho  * PARAMETERS:  Buffer              - Buffer to checksum
    180          1.1  jruoho  *              Length              - Size of the buffer
    181          1.1  jruoho  *
    182          1.1  jruoho  * RETURNS      8 bit checksum of buffer
    183          1.1  jruoho  *
    184          1.1  jruoho  * DESCRIPTION: Computes an 8 bit checksum of the buffer(length) and returns it.
    185          1.1  jruoho  *
    186          1.1  jruoho  ******************************************************************************/
    187          1.1  jruoho 
    188          1.1  jruoho static UINT8
    189          1.1  jruoho AcpiTbSumTable (
    190          1.1  jruoho     void                    *Buffer,
    191          1.1  jruoho     UINT32                  Length)
    192          1.1  jruoho {
    193          1.1  jruoho     const UINT8             *limit;
    194          1.1  jruoho     const UINT8             *rover;
    195          1.1  jruoho     UINT8                   sum = 0;
    196          1.1  jruoho 
    197          1.1  jruoho 
    198          1.1  jruoho     if (Buffer && Length)
    199          1.1  jruoho     {
    200          1.1  jruoho         /* Buffer and Length are valid */
    201          1.1  jruoho 
    202          1.1  jruoho         limit = (UINT8 *) Buffer + Length;
    203          1.1  jruoho 
    204          1.1  jruoho         for (rover = Buffer; rover < limit; rover++)
    205          1.1  jruoho         {
    206          1.1  jruoho             sum = (UINT8) (sum + *rover);
    207          1.1  jruoho         }
    208          1.1  jruoho     }
    209          1.1  jruoho     return (sum);
    210          1.1  jruoho }
    211          1.1  jruoho 
    212          1.1  jruoho 
    213          1.1  jruoho /*******************************************************************************
    214          1.1  jruoho  *
    215          1.1  jruoho  * FUNCTION:    AbPrintHeaderInfo
    216          1.1  jruoho  *
    217          1.1  jruoho  * PARAMETERS:  Header              - An ACPI table header
    218          1.1  jruoho  *
    219          1.1  jruoho  * RETURNS      None.
    220          1.1  jruoho  *
    221          1.1  jruoho  * DESCRIPTION: Format and display header contents.
    222          1.1  jruoho  *
    223          1.1  jruoho  ******************************************************************************/
    224          1.1  jruoho 
    225          1.1  jruoho static void
    226          1.1  jruoho AbPrintHeaderInfo (
    227          1.1  jruoho     ACPI_TABLE_HEADER       *Header)
    228          1.1  jruoho {
    229          1.1  jruoho 
    230          1.1  jruoho     /* Display header information */
    231          1.1  jruoho 
    232          1.1  jruoho     printf ("Signature         : %4.4s\n",    Header->Signature);
    233          1.1  jruoho     printf ("Length            : %8.8X\n",    Header->Length);
    234          1.1  jruoho     printf ("Revision          : %2.2X\n",    Header->Revision);
    235          1.1  jruoho     printf ("Checksum          : %2.2X\n",    Header->Checksum);
    236          1.1  jruoho     printf ("OEM ID            : %6.6s\n",    Header->OemId);
    237          1.1  jruoho     printf ("OEM Table ID      : %8.8s\n",    Header->OemTableId);
    238          1.1  jruoho     printf ("OEM Revision      : %8.8X\n",    Header->OemRevision);
    239          1.1  jruoho     printf ("ASL Compiler ID   : %4.4s\n",    Header->AslCompilerId);
    240          1.1  jruoho     printf ("Compiler Revision : %8.8X\n",    Header->AslCompilerRevision);
    241          1.1  jruoho     printf ("\n");
    242          1.1  jruoho }
    243          1.1  jruoho 
    244  1.1.1.1.2.1    yamt static void
    245  1.1.1.1.2.1    yamt AbPrintHeadersInfo (
    246  1.1.1.1.2.1    yamt     ACPI_TABLE_HEADER       *Header,
    247  1.1.1.1.2.1    yamt     ACPI_TABLE_HEADER       *Header2)
    248  1.1.1.1.2.1    yamt {
    249  1.1.1.1.2.1    yamt 
    250  1.1.1.1.2.1    yamt     /* Display header information for both headers */
    251  1.1.1.1.2.1    yamt 
    252  1.1.1.1.2.1    yamt     printf ("Signature          %8.4s : %4.4s\n",    Header->Signature, Header2->Signature);
    253  1.1.1.1.2.1    yamt     printf ("Length             %8.8X : %8.8X\n",    Header->Length, Header2->Length);
    254  1.1.1.1.2.1    yamt     printf ("Revision           %8.2X : %2.2X\n",    Header->Revision, Header2->Revision);
    255  1.1.1.1.2.1    yamt     printf ("Checksum           %8.2X : %2.2X\n",    Header->Checksum, Header2->Checksum);
    256  1.1.1.1.2.1    yamt     printf ("OEM ID             %8.6s : %6.6s\n",    Header->OemId, Header2->OemId);
    257  1.1.1.1.2.1    yamt     printf ("OEM Table ID       %8.8s : %8.8s\n",    Header->OemTableId, Header2->OemTableId);
    258  1.1.1.1.2.1    yamt     printf ("OEM Revision       %8.8X : %8.8X\n",    Header->OemRevision, Header2->OemRevision);
    259  1.1.1.1.2.1    yamt     printf ("ASL Compiler ID    %8.4s : %4.4s\n",    Header->AslCompilerId, Header2->AslCompilerId);
    260  1.1.1.1.2.1    yamt     printf ("Compiler Revision  %8.8X : %8.8X\n",    Header->AslCompilerRevision, Header2->AslCompilerRevision);
    261  1.1.1.1.2.1    yamt     printf ("\n");
    262  1.1.1.1.2.1    yamt }
    263  1.1.1.1.2.1    yamt 
    264          1.1  jruoho 
    265          1.1  jruoho /******************************************************************************
    266          1.1  jruoho  *
    267          1.1  jruoho  * FUNCTION:    AbDisplayHeader
    268          1.1  jruoho  *
    269          1.1  jruoho  * DESCRIPTION: Display an ACPI table header
    270          1.1  jruoho  *
    271          1.1  jruoho  ******************************************************************************/
    272          1.1  jruoho 
    273          1.1  jruoho void
    274          1.1  jruoho AbDisplayHeader (
    275          1.1  jruoho     char                    *File1Path)
    276          1.1  jruoho {
    277  1.1.1.1.2.1    yamt     UINT32                  Actual;
    278          1.1  jruoho 
    279          1.1  jruoho 
    280          1.1  jruoho     File1 = fopen (File1Path, "rb");
    281          1.1  jruoho     if (!File1)
    282          1.1  jruoho     {
    283          1.1  jruoho         printf ("Could not open file %s\n", File1Path);
    284          1.1  jruoho         return;
    285          1.1  jruoho     }
    286          1.1  jruoho 
    287  1.1.1.1.2.1    yamt     Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1);
    288  1.1.1.1.2.1    yamt     if (Actual != sizeof (ACPI_TABLE_HEADER))
    289          1.1  jruoho     {
    290          1.1  jruoho         printf ("File %s does not contain an ACPI table header\n", File1Path);
    291          1.1  jruoho         return;
    292          1.1  jruoho     }
    293          1.1  jruoho 
    294          1.1  jruoho     if (!AbValidateHeader (&Header1))
    295          1.1  jruoho     {
    296          1.1  jruoho         return;
    297          1.1  jruoho     }
    298          1.1  jruoho 
    299          1.1  jruoho     AbPrintHeaderInfo (&Header1);
    300          1.1  jruoho }
    301          1.1  jruoho 
    302          1.1  jruoho 
    303          1.1  jruoho /******************************************************************************
    304          1.1  jruoho  *
    305          1.1  jruoho  * FUNCTION:    AbComputeChecksum
    306          1.1  jruoho  *
    307          1.1  jruoho  * DESCRIPTION: Compute proper checksum for an ACPI table
    308          1.1  jruoho  *
    309          1.1  jruoho  ******************************************************************************/
    310          1.1  jruoho 
    311          1.1  jruoho void
    312          1.1  jruoho AbComputeChecksum (
    313          1.1  jruoho     char                    *File1Path)
    314          1.1  jruoho {
    315  1.1.1.1.2.1    yamt     UINT32                  Actual;
    316          1.1  jruoho     ACPI_TABLE_HEADER       *Table;
    317          1.1  jruoho     UINT8                   Checksum;
    318          1.1  jruoho 
    319          1.1  jruoho 
    320          1.1  jruoho     File1 = fopen (File1Path, "rb");
    321          1.1  jruoho     if (!File1)
    322          1.1  jruoho     {
    323          1.1  jruoho         printf ("Could not open file %s\n", File1Path);
    324          1.1  jruoho         return;
    325          1.1  jruoho     }
    326          1.1  jruoho 
    327  1.1.1.1.2.1    yamt     Actual = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1);
    328  1.1.1.1.2.1    yamt     if (Actual < sizeof (ACPI_TABLE_HEADER))
    329          1.1  jruoho     {
    330          1.1  jruoho         printf ("File %s does not contain an ACPI table header\n", File1Path);
    331          1.1  jruoho         return;
    332          1.1  jruoho     }
    333          1.1  jruoho 
    334          1.1  jruoho     if (!AbValidateHeader (&Header1))
    335          1.1  jruoho     {
    336          1.1  jruoho         return;
    337          1.1  jruoho     }
    338          1.1  jruoho 
    339          1.1  jruoho     if (!Gbl_TerseMode)
    340          1.1  jruoho     {
    341          1.1  jruoho         AbPrintHeaderInfo (&Header1);
    342          1.1  jruoho     }
    343          1.1  jruoho 
    344          1.1  jruoho     /* Allocate a buffer to hold the entire table */
    345          1.1  jruoho 
    346          1.1  jruoho     Table = AcpiOsAllocate (Header1.Length);
    347          1.1  jruoho     if (!Table)
    348          1.1  jruoho     {
    349          1.1  jruoho         printf ("could not allocate\n");
    350          1.1  jruoho         return;
    351          1.1  jruoho     }
    352          1.1  jruoho 
    353          1.1  jruoho     /* Read the entire table, including header */
    354          1.1  jruoho 
    355          1.1  jruoho     fseek (File1, 0, SEEK_SET);
    356  1.1.1.1.2.1    yamt     Actual = fread (Table, 1, Header1.Length, File1);
    357  1.1.1.1.2.1    yamt     if (Actual != Header1.Length)
    358          1.1  jruoho     {
    359  1.1.1.1.2.1    yamt         printf ("could not read table, length %u\n", Header1.Length);
    360          1.1  jruoho         return;
    361          1.1  jruoho     }
    362          1.1  jruoho 
    363          1.1  jruoho     /* Compute the checksum for the table */
    364          1.1  jruoho 
    365          1.1  jruoho     Table->Checksum = 0;
    366          1.1  jruoho 
    367          1.1  jruoho     Checksum = (UINT8) (0 - AcpiTbSumTable (Table, Table->Length));
    368          1.1  jruoho     printf ("Computed checksum: 0x%X\n\n", Checksum);
    369          1.1  jruoho 
    370          1.1  jruoho     if (Header1.Checksum == Checksum)
    371          1.1  jruoho     {
    372          1.1  jruoho         printf ("Checksum ok in AML file, not updating\n");
    373          1.1  jruoho         return;
    374          1.1  jruoho     }
    375          1.1  jruoho 
    376          1.1  jruoho     /* Open the target file for writing, to update checksum */
    377          1.1  jruoho 
    378          1.1  jruoho     fclose (File1);
    379          1.1  jruoho     File1 = fopen (File1Path, "r+b");
    380          1.1  jruoho     if (!File1)
    381          1.1  jruoho     {
    382          1.1  jruoho         printf ("Could not open file %s for writing\n", File1Path);
    383          1.1  jruoho         return;
    384          1.1  jruoho     }
    385          1.1  jruoho 
    386          1.1  jruoho     /* Set the checksum, write the new header */
    387          1.1  jruoho 
    388          1.1  jruoho     Header1.Checksum = Checksum;
    389          1.1  jruoho 
    390  1.1.1.1.2.1    yamt     Actual = fwrite (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1);
    391  1.1.1.1.2.1    yamt     if (Actual != sizeof (ACPI_TABLE_HEADER))
    392          1.1  jruoho     {
    393          1.1  jruoho         printf ("Could not write updated table header\n");
    394          1.1  jruoho         return;
    395          1.1  jruoho     }
    396          1.1  jruoho 
    397          1.1  jruoho     printf ("Wrote new checksum\n");
    398          1.1  jruoho     return;
    399          1.1  jruoho }
    400          1.1  jruoho 
    401          1.1  jruoho 
    402          1.1  jruoho /******************************************************************************
    403          1.1  jruoho  *
    404          1.1  jruoho  * FUNCTION:    AbCompareAmlFiles
    405          1.1  jruoho  *
    406          1.1  jruoho  * DESCRIPTION: Compare two AML files
    407          1.1  jruoho  *
    408          1.1  jruoho  ******************************************************************************/
    409          1.1  jruoho 
    410          1.1  jruoho int
    411          1.1  jruoho AbCompareAmlFiles (
    412          1.1  jruoho     char                    *File1Path,
    413          1.1  jruoho     char                    *File2Path)
    414          1.1  jruoho {
    415          1.1  jruoho     UINT32                  Actual1;
    416          1.1  jruoho     UINT32                  Actual2;
    417          1.1  jruoho     UINT32                  Offset;
    418          1.1  jruoho     UINT8                   Char1;
    419          1.1  jruoho     UINT8                   Char2;
    420          1.1  jruoho     UINT8                   Mismatches = 0;
    421          1.1  jruoho     BOOLEAN                 HeaderMismatch = FALSE;
    422          1.1  jruoho 
    423          1.1  jruoho 
    424          1.1  jruoho     File1 = fopen (File1Path, "rb");
    425          1.1  jruoho     if (!File1)
    426          1.1  jruoho     {
    427          1.1  jruoho         printf ("Could not open file %s\n", File1Path);
    428  1.1.1.1.2.1    yamt         return (-1);
    429          1.1  jruoho     }
    430          1.1  jruoho 
    431          1.1  jruoho     File2 = fopen (File2Path, "rb");
    432          1.1  jruoho     if (!File2)
    433          1.1  jruoho     {
    434          1.1  jruoho         printf ("Could not open file %s\n", File2Path);
    435  1.1.1.1.2.1    yamt         return (-1);
    436          1.1  jruoho     }
    437          1.1  jruoho 
    438          1.1  jruoho     /* Read the ACPI header from each file */
    439          1.1  jruoho 
    440          1.1  jruoho     Actual1 = fread (&Header1, 1, sizeof (ACPI_TABLE_HEADER), File1);
    441  1.1.1.1.2.1    yamt     if (Actual1 != sizeof (ACPI_TABLE_HEADER))
    442          1.1  jruoho     {
    443          1.1  jruoho         printf ("File %s does not contain an ACPI table header\n", File1Path);
    444  1.1.1.1.2.1    yamt         return (-1);
    445          1.1  jruoho     }
    446          1.1  jruoho 
    447          1.1  jruoho     Actual2 = fread (&Header2, 1, sizeof (ACPI_TABLE_HEADER), File2);
    448  1.1.1.1.2.1    yamt     if (Actual2 != sizeof (ACPI_TABLE_HEADER))
    449          1.1  jruoho     {
    450          1.1  jruoho         printf ("File %s does not contain an ACPI table header\n", File2Path);
    451  1.1.1.1.2.1    yamt         return (-1);
    452          1.1  jruoho     }
    453          1.1  jruoho 
    454          1.1  jruoho     if ((!AbValidateHeader (&Header1)) ||
    455          1.1  jruoho         (!AbValidateHeader (&Header2)))
    456          1.1  jruoho     {
    457  1.1.1.1.2.1    yamt         return (-1);
    458          1.1  jruoho     }
    459          1.1  jruoho 
    460          1.1  jruoho     /* Table signatures must match */
    461          1.1  jruoho 
    462          1.1  jruoho     if (*((UINT32 *) Header1.Signature) != *((UINT32 *) Header2.Signature))
    463          1.1  jruoho     {
    464          1.1  jruoho         printf ("Table signatures do not match\n");
    465  1.1.1.1.2.1    yamt         return (-1);
    466          1.1  jruoho     }
    467          1.1  jruoho 
    468          1.1  jruoho     if (!Gbl_TerseMode)
    469          1.1  jruoho     {
    470          1.1  jruoho         /* Display header information */
    471          1.1  jruoho 
    472  1.1.1.1.2.1    yamt         AbPrintHeadersInfo (&Header1, &Header2);
    473          1.1  jruoho     }
    474          1.1  jruoho 
    475  1.1.1.1.2.1    yamt     if (memcmp (&Header1, &Header2, sizeof (ACPI_TABLE_HEADER)))
    476          1.1  jruoho     {
    477          1.1  jruoho         printf ("Headers do not match exactly\n");
    478          1.1  jruoho         HeaderMismatch = TRUE;
    479          1.1  jruoho     }
    480          1.1  jruoho 
    481          1.1  jruoho     /* Do the byte-by-byte compare */
    482          1.1  jruoho 
    483          1.1  jruoho     Actual1 = fread (&Char1, 1, 1, File1);
    484          1.1  jruoho     Actual2 = fread (&Char2, 1, 1, File2);
    485          1.1  jruoho     Offset = sizeof (ACPI_TABLE_HEADER);
    486          1.1  jruoho 
    487  1.1.1.1.2.1    yamt     while ((Actual1 == 1) && (Actual2 == 1))
    488          1.1  jruoho     {
    489          1.1  jruoho         if (Char1 != Char2)
    490          1.1  jruoho         {
    491          1.1  jruoho             printf ("Error - Byte mismatch at offset %8.8X: 0x%2.2X 0x%2.2X\n",
    492          1.1  jruoho                 Offset, Char1, Char2);
    493          1.1  jruoho             Mismatches++;
    494          1.1  jruoho             if (Mismatches > 100)
    495          1.1  jruoho             {
    496          1.1  jruoho                 printf ("100 Mismatches: Too many mismatches\n");
    497  1.1.1.1.2.1    yamt                 return (-1);
    498          1.1  jruoho             }
    499          1.1  jruoho         }
    500          1.1  jruoho 
    501          1.1  jruoho         Offset++;
    502          1.1  jruoho         Actual1 = fread (&Char1, 1, 1, File1);
    503          1.1  jruoho         Actual2 = fread (&Char2, 1, 1, File2);
    504          1.1  jruoho     }
    505          1.1  jruoho 
    506          1.1  jruoho     if (Actual1)
    507          1.1  jruoho     {
    508          1.1  jruoho         printf ("Error - file %s is longer than file %s\n", File1Path, File2Path);
    509          1.1  jruoho         Mismatches++;
    510          1.1  jruoho     }
    511          1.1  jruoho     else if (Actual2)
    512          1.1  jruoho     {
    513          1.1  jruoho         printf ("Error - file %s is shorter than file %s\n", File1Path, File2Path);
    514          1.1  jruoho         Mismatches++;
    515          1.1  jruoho     }
    516          1.1  jruoho     else if (!Mismatches)
    517          1.1  jruoho     {
    518          1.1  jruoho         if (HeaderMismatch)
    519          1.1  jruoho         {
    520          1.1  jruoho             printf ("Files compare exactly after header\n");
    521          1.1  jruoho         }
    522          1.1  jruoho         else
    523          1.1  jruoho         {
    524          1.1  jruoho             printf ("Files compare exactly\n");
    525          1.1  jruoho         }
    526          1.1  jruoho     }
    527          1.1  jruoho 
    528          1.1  jruoho     printf ("%u Mismatches found\n", Mismatches);
    529  1.1.1.1.2.1    yamt     return (0);
    530          1.1  jruoho }
    531          1.1  jruoho 
    532          1.1  jruoho 
    533          1.1  jruoho /******************************************************************************
    534          1.1  jruoho  *
    535  1.1.1.1.2.1    yamt  * FUNCTION:    AbGetFileSize
    536  1.1.1.1.2.1    yamt  *
    537  1.1.1.1.2.1    yamt  * DESCRIPTION: Get the size of an open file
    538  1.1.1.1.2.1    yamt  *
    539  1.1.1.1.2.1    yamt  ******************************************************************************/
    540  1.1.1.1.2.1    yamt 
    541  1.1.1.1.2.1    yamt static UINT32
    542  1.1.1.1.2.1    yamt AbGetFileSize (
    543  1.1.1.1.2.1    yamt     FILE                    *File)
    544  1.1.1.1.2.1    yamt {
    545  1.1.1.1.2.1    yamt     UINT32                  FileSize;
    546  1.1.1.1.2.1    yamt     long                    Offset;
    547  1.1.1.1.2.1    yamt 
    548  1.1.1.1.2.1    yamt 
    549  1.1.1.1.2.1    yamt     Offset = ftell (File);
    550  1.1.1.1.2.1    yamt 
    551  1.1.1.1.2.1    yamt     if (fseek (File, 0, SEEK_END))
    552  1.1.1.1.2.1    yamt     {
    553  1.1.1.1.2.1    yamt         return (0);
    554  1.1.1.1.2.1    yamt     }
    555  1.1.1.1.2.1    yamt 
    556  1.1.1.1.2.1    yamt     FileSize = (UINT32) ftell (File);
    557  1.1.1.1.2.1    yamt 
    558  1.1.1.1.2.1    yamt     /* Restore file pointer */
    559  1.1.1.1.2.1    yamt 
    560  1.1.1.1.2.1    yamt     if (fseek (File, Offset, SEEK_SET))
    561  1.1.1.1.2.1    yamt     {
    562  1.1.1.1.2.1    yamt         return (0);
    563  1.1.1.1.2.1    yamt     }
    564  1.1.1.1.2.1    yamt 
    565  1.1.1.1.2.1    yamt     return (FileSize);
    566  1.1.1.1.2.1    yamt }
    567  1.1.1.1.2.1    yamt 
    568  1.1.1.1.2.1    yamt 
    569  1.1.1.1.2.1    yamt /******************************************************************************
    570  1.1.1.1.2.1    yamt  *
    571  1.1.1.1.2.1    yamt  * FUNCTION:    AbGetFile
    572          1.1  jruoho  *
    573          1.1  jruoho  * DESCRIPTION: Open a file and read it entirely into a new buffer
    574          1.1  jruoho  *
    575          1.1  jruoho  ******************************************************************************/
    576          1.1  jruoho 
    577          1.1  jruoho static char *
    578          1.1  jruoho AbGetFile (
    579          1.1  jruoho     char                    *Filename,
    580          1.1  jruoho     UINT32                  *FileSize)
    581          1.1  jruoho {
    582  1.1.1.1.2.1    yamt     FILE                    *File;
    583          1.1  jruoho     UINT32                  Size;
    584          1.1  jruoho     char                    *Buffer = NULL;
    585  1.1.1.1.2.1    yamt     size_t                  Actual;
    586          1.1  jruoho 
    587          1.1  jruoho 
    588          1.1  jruoho     /* Binary mode does not alter CR/LF pairs */
    589          1.1  jruoho 
    590  1.1.1.1.2.1    yamt     File = fopen (Filename, "rb");
    591  1.1.1.1.2.1    yamt     if (!File)
    592          1.1  jruoho     {
    593  1.1.1.1.2.1    yamt         printf ("Could not open file %s\n", Filename);
    594  1.1.1.1.2.1    yamt         return (NULL);
    595          1.1  jruoho     }
    596          1.1  jruoho 
    597          1.1  jruoho     /* Need file size to allocate a buffer */
    598          1.1  jruoho 
    599  1.1.1.1.2.1    yamt     Size = AbGetFileSize (File);
    600  1.1.1.1.2.1    yamt     if (!Size)
    601          1.1  jruoho     {
    602  1.1.1.1.2.1    yamt         printf ("Could not get file size (seek) for %s\n", Filename);
    603          1.1  jruoho         goto ErrorExit;
    604          1.1  jruoho     }
    605          1.1  jruoho 
    606          1.1  jruoho     /* Allocate a buffer for the entire file */
    607          1.1  jruoho 
    608          1.1  jruoho     Buffer = calloc (Size, 1);
    609          1.1  jruoho     if (!Buffer)
    610          1.1  jruoho     {
    611          1.1  jruoho         printf ("Could not allocate buffer of size %u\n", Size);
    612          1.1  jruoho         goto ErrorExit;
    613          1.1  jruoho     }
    614          1.1  jruoho 
    615          1.1  jruoho     /* Read the entire file */
    616          1.1  jruoho 
    617  1.1.1.1.2.1    yamt     Actual = fread (Buffer, 1, Size, File);
    618  1.1.1.1.2.1    yamt     if (Actual != Size)
    619          1.1  jruoho     {
    620          1.1  jruoho         printf ("Could not read the input file %s\n", Filename);
    621          1.1  jruoho         free (Buffer);
    622          1.1  jruoho         Buffer = NULL;
    623          1.1  jruoho         goto ErrorExit;
    624          1.1  jruoho     }
    625          1.1  jruoho 
    626          1.1  jruoho     *FileSize = Size;
    627          1.1  jruoho 
    628          1.1  jruoho ErrorExit:
    629  1.1.1.1.2.1    yamt     fclose (File);
    630          1.1  jruoho     return (Buffer);
    631          1.1  jruoho }
    632          1.1  jruoho 
    633          1.1  jruoho 
    634          1.1  jruoho /******************************************************************************
    635          1.1  jruoho  *
    636          1.1  jruoho  * FUNCTION:    AbDumpAmlFile
    637          1.1  jruoho  *
    638          1.1  jruoho  * DESCRIPTION: Dump a binary AML file to a text file
    639          1.1  jruoho  *
    640          1.1  jruoho  ******************************************************************************/
    641          1.1  jruoho 
    642          1.1  jruoho int
    643          1.1  jruoho AbDumpAmlFile (
    644          1.1  jruoho     char                    *File1Path,
    645          1.1  jruoho     char                    *File2Path)
    646          1.1  jruoho {
    647          1.1  jruoho     char                    *FileBuffer;
    648          1.1  jruoho     FILE                    *FileOutHandle;
    649  1.1.1.1.2.1    yamt     UINT32                  FileSize = 0;
    650          1.1  jruoho 
    651          1.1  jruoho 
    652          1.1  jruoho     /* Get the entire AML file, validate header */
    653          1.1  jruoho 
    654          1.1  jruoho     FileBuffer = AbGetFile (File1Path, &FileSize);
    655  1.1.1.1.2.1    yamt     if (!FileBuffer)
    656  1.1.1.1.2.1    yamt     {
    657  1.1.1.1.2.1    yamt         return (-1);
    658  1.1.1.1.2.1    yamt     }
    659  1.1.1.1.2.1    yamt 
    660  1.1.1.1.2.1    yamt     printf ("Input file:  %s contains %u (0x%X) bytes\n",
    661  1.1.1.1.2.1    yamt         File1Path, FileSize, FileSize);
    662          1.1  jruoho 
    663          1.1  jruoho     FileOutHandle = fopen (File2Path, "wb");
    664          1.1  jruoho     if (!FileOutHandle)
    665          1.1  jruoho     {
    666  1.1.1.1.2.1    yamt         printf ("Could not open file %s\n", File2Path);
    667  1.1.1.1.2.1    yamt         return (-1);
    668          1.1  jruoho     }
    669          1.1  jruoho 
    670          1.1  jruoho     if (!AbValidateHeader ((ACPI_TABLE_HEADER *) FileBuffer))
    671          1.1  jruoho     {
    672  1.1.1.1.2.1    yamt         return (-1);
    673          1.1  jruoho     }
    674          1.1  jruoho 
    675          1.1  jruoho     /* Convert binary AML to text, using common dump buffer routine */
    676          1.1  jruoho 
    677          1.1  jruoho     AcpiGbl_DebugFile = FileOutHandle;
    678          1.1  jruoho     AcpiGbl_DbOutputFlags = ACPI_DB_REDIRECTABLE_OUTPUT;
    679          1.1  jruoho 
    680  1.1.1.1.2.1    yamt     AcpiOsPrintf ("%4.4s @ 0x%8.8X\n",
    681  1.1.1.1.2.1    yamt         ((ACPI_TABLE_HEADER *) FileBuffer)->Signature, 0);
    682  1.1.1.1.2.1    yamt 
    683  1.1.1.1.2.1    yamt     AcpiUtDumpBuffer ((UINT8 *) FileBuffer, FileSize, DB_BYTE_DISPLAY, 0);
    684          1.1  jruoho 
    685  1.1.1.1.2.1    yamt     /* Summary for the output file */
    686  1.1.1.1.2.1    yamt 
    687  1.1.1.1.2.1    yamt     FileSize = AbGetFileSize (FileOutHandle);
    688  1.1.1.1.2.1    yamt     printf ("Output file: %s contains %u (0x%X) bytes\n\n",
    689  1.1.1.1.2.1    yamt         File2Path, FileSize, FileSize);
    690  1.1.1.1.2.1    yamt 
    691  1.1.1.1.2.1    yamt     return (0);
    692          1.1  jruoho }
    693          1.1  jruoho 
    694          1.1  jruoho 
    695          1.1  jruoho /******************************************************************************
    696          1.1  jruoho  *
    697          1.1  jruoho  * FUNCTION:    AbExtractAmlFile
    698          1.1  jruoho  *
    699          1.1  jruoho  * DESCRIPTION: Extract a binary AML file from a text file (as produced by the
    700  1.1.1.1.2.1    yamt  *              DumpAmlFile procedure or the "acpidump" table utility.
    701          1.1  jruoho  *
    702          1.1  jruoho  ******************************************************************************/
    703          1.1  jruoho 
    704          1.1  jruoho int
    705          1.1  jruoho AbExtractAmlFile (
    706          1.1  jruoho     char                    *TableSig,
    707          1.1  jruoho     char                    *File1Path,
    708          1.1  jruoho     char                    *File2Path)
    709          1.1  jruoho {
    710          1.1  jruoho     char                    *Table;
    711          1.1  jruoho     char                    Value;
    712          1.1  jruoho     UINT32                  i;
    713          1.1  jruoho     FILE                    *FileHandle;
    714          1.1  jruoho     FILE                    *FileOutHandle;
    715          1.1  jruoho     UINT32                  Count = 0;
    716          1.1  jruoho     int                     Scanned;
    717          1.1  jruoho 
    718          1.1  jruoho 
    719          1.1  jruoho     /* Open in/out files. input is in text mode, output is in binary mode */
    720          1.1  jruoho 
    721          1.1  jruoho     FileHandle = fopen (File1Path, "rt");
    722          1.1  jruoho     if (!FileHandle)
    723          1.1  jruoho     {
    724  1.1.1.1.2.1    yamt         printf ("Could not open file %s\n", File1Path);
    725  1.1.1.1.2.1    yamt         return (-1);
    726          1.1  jruoho     }
    727          1.1  jruoho 
    728          1.1  jruoho     FileOutHandle = fopen (File2Path, "w+b");
    729          1.1  jruoho     if (!FileOutHandle)
    730          1.1  jruoho     {
    731  1.1.1.1.2.1    yamt         printf ("Could not open file %s\n", File2Path);
    732  1.1.1.1.2.1    yamt         return (-1);
    733          1.1  jruoho     }
    734          1.1  jruoho 
    735          1.1  jruoho     /* Force input table sig to uppercase */
    736          1.1  jruoho 
    737          1.1  jruoho     AcpiUtStrupr (TableSig);
    738          1.1  jruoho 
    739          1.1  jruoho 
    740          1.1  jruoho     /* TBD: examine input for ASCII */
    741          1.1  jruoho 
    742          1.1  jruoho 
    743          1.1  jruoho     /* We have an ascii file, grab one line at a time */
    744          1.1  jruoho 
    745          1.1  jruoho     while (fgets (Buffer, BUFFER_SIZE, FileHandle))
    746          1.1  jruoho     {
    747          1.1  jruoho         /* The 4-char ACPI signature appears at the beginning of a line */
    748          1.1  jruoho 
    749  1.1.1.1.2.1    yamt         if (ACPI_COMPARE_NAME (Buffer, TableSig))
    750          1.1  jruoho         {
    751          1.1  jruoho             printf ("Found table [%4.4s]\n", TableSig);
    752          1.1  jruoho 
    753          1.1  jruoho             /*
    754          1.1  jruoho              * Eat all lines in the table, of the form:
    755          1.1  jruoho              *   <offset>: <16 bytes of hex data, separated by spaces> <ASCII representation> <newline>
    756          1.1  jruoho              *
    757          1.1  jruoho              * Example:
    758          1.1  jruoho              *
    759          1.1  jruoho              *   02C0: 5F 53 42 5F 4C 4E 4B 44 00 12 13 04 0C FF FF 08  _SB_LNKD........
    760          1.1  jruoho              *
    761          1.1  jruoho              */
    762          1.1  jruoho             while (fgets (Buffer, BUFFER_SIZE, FileHandle))
    763          1.1  jruoho             {
    764          1.1  jruoho                 /* Get past the offset, terminated by a colon */
    765          1.1  jruoho 
    766          1.1  jruoho                 Table = strchr (Buffer, ':');
    767          1.1  jruoho                 if (!Table)
    768          1.1  jruoho                 {
    769          1.1  jruoho                     /* No colon, all done */
    770          1.1  jruoho                     goto Exit;
    771          1.1  jruoho                 }
    772          1.1  jruoho 
    773          1.1  jruoho                 Table += 2; /* Eat the colon + space */
    774          1.1  jruoho 
    775          1.1  jruoho                 for (i = 0; i < 16; i++)
    776          1.1  jruoho                 {
    777          1.1  jruoho                     Scanned = AbHexByteToBinary (Table, &Value);
    778          1.1  jruoho                     if (!Scanned)
    779          1.1  jruoho                     {
    780          1.1  jruoho                         goto Exit;
    781          1.1  jruoho                     }
    782          1.1  jruoho 
    783          1.1  jruoho                     Table += 3; /* Go past this hex byte and space */
    784          1.1  jruoho 
    785          1.1  jruoho                     /* Write the converted (binary) byte */
    786          1.1  jruoho 
    787  1.1.1.1.2.1    yamt                     if (fwrite (&Value, 1, 1, FileOutHandle) != 1)
    788  1.1.1.1.2.1    yamt                     {
    789  1.1.1.1.2.1    yamt                         printf ("Error writing byte %u to output file: %s\n",
    790  1.1.1.1.2.1    yamt                             Count, File2Path);
    791  1.1.1.1.2.1    yamt                         goto Exit;
    792  1.1.1.1.2.1    yamt                     }
    793          1.1  jruoho                     Count++;
    794          1.1  jruoho                 }
    795          1.1  jruoho             }
    796          1.1  jruoho 
    797          1.1  jruoho             /* No more lines, EOF, all done */
    798          1.1  jruoho 
    799          1.1  jruoho             goto Exit;
    800          1.1  jruoho         }
    801          1.1  jruoho     }
    802          1.1  jruoho 
    803          1.1  jruoho     /* Searched entire file, no match to table signature */
    804          1.1  jruoho 
    805          1.1  jruoho     printf ("Could not match table signature\n");
    806          1.1  jruoho     fclose (FileHandle);
    807  1.1.1.1.2.1    yamt     return (-1);
    808          1.1  jruoho 
    809          1.1  jruoho Exit:
    810          1.1  jruoho     printf ("%u (0x%X) bytes written to %s\n", Count, Count, File2Path);
    811          1.1  jruoho     fclose (FileHandle);
    812          1.1  jruoho     fclose (FileOutHandle);
    813  1.1.1.1.2.1    yamt     return (0);
    814          1.1  jruoho }
    815          1.1  jruoho 
    816          1.1  jruoho 
    817          1.1  jruoho /******************************************************************************
    818          1.1  jruoho  *
    819          1.1  jruoho  * FUNCTION:    Stubs
    820          1.1  jruoho  *
    821          1.1  jruoho  * DESCRIPTION: For linkage
    822          1.1  jruoho  *
    823          1.1  jruoho  ******************************************************************************/
    824          1.1  jruoho 
    825          1.1  jruoho ACPI_PHYSICAL_ADDRESS
    826          1.1  jruoho AeLocalGetRootPointer (
    827          1.1  jruoho     void)
    828          1.1  jruoho {
    829  1.1.1.1.2.1    yamt     return (AE_OK);
    830          1.1  jruoho }
    831          1.1  jruoho 
    832          1.1  jruoho ACPI_THREAD_ID
    833          1.1  jruoho AcpiOsGetThreadId (
    834          1.1  jruoho     void)
    835          1.1  jruoho {
    836          1.1  jruoho     return (0xFFFF);
    837          1.1  jruoho }
    838          1.1  jruoho 
    839          1.1  jruoho ACPI_STATUS
    840          1.1  jruoho AcpiOsExecute (
    841          1.1  jruoho     ACPI_EXECUTE_TYPE       Type,
    842          1.1  jruoho     ACPI_OSD_EXEC_CALLBACK  Function,
    843          1.1  jruoho     void                    *Context)
    844          1.1  jruoho {
    845          1.1  jruoho     return (AE_SUPPORT);
    846          1.1  jruoho }
    847