Home | History | Annotate | Line # | Download | only in debugger
dbfileio.c revision 1.1
      1  1.1  jruoho /*******************************************************************************
      2  1.1  jruoho  *
      3  1.1  jruoho  * Module Name: dbfileio - Debugger file I/O commands. These can't usually
      4  1.1  jruoho  *              be used when running the debugger in Ring 0 (Kernel mode)
      5  1.1  jruoho  *
      6  1.1  jruoho  ******************************************************************************/
      7  1.1  jruoho 
      8  1.1  jruoho /******************************************************************************
      9  1.1  jruoho  *
     10  1.1  jruoho  * 1. Copyright Notice
     11  1.1  jruoho  *
     12  1.1  jruoho  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     13  1.1  jruoho  * All rights reserved.
     14  1.1  jruoho  *
     15  1.1  jruoho  * 2. License
     16  1.1  jruoho  *
     17  1.1  jruoho  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  1.1  jruoho  * rights.  You may have additional license terms from the party that provided
     19  1.1  jruoho  * you this software, covering your right to use that party's intellectual
     20  1.1  jruoho  * property rights.
     21  1.1  jruoho  *
     22  1.1  jruoho  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  1.1  jruoho  * copy of the source code appearing in this file ("Covered Code") an
     24  1.1  jruoho  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  1.1  jruoho  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  1.1  jruoho  * make derivatives, distribute, use and display any portion of the Covered
     27  1.1  jruoho  * Code in any form, with the right to sublicense such rights; and
     28  1.1  jruoho  *
     29  1.1  jruoho  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  1.1  jruoho  * license (with the right to sublicense), under only those claims of Intel
     31  1.1  jruoho  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  1.1  jruoho  * offer to sell, and import the Covered Code and derivative works thereof
     33  1.1  jruoho  * solely to the minimum extent necessary to exercise the above copyright
     34  1.1  jruoho  * license, and in no event shall the patent license extend to any additions
     35  1.1  jruoho  * to or modifications of the Original Intel Code.  No other license or right
     36  1.1  jruoho  * is granted directly or by implication, estoppel or otherwise;
     37  1.1  jruoho  *
     38  1.1  jruoho  * The above copyright and patent license is granted only if the following
     39  1.1  jruoho  * conditions are met:
     40  1.1  jruoho  *
     41  1.1  jruoho  * 3. Conditions
     42  1.1  jruoho  *
     43  1.1  jruoho  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     45  1.1  jruoho  * Code or modification with rights to further distribute source must include
     46  1.1  jruoho  * the above Copyright Notice, the above License, this list of Conditions,
     47  1.1  jruoho  * and the following Disclaimer and Export Compliance provision.  In addition,
     48  1.1  jruoho  * Licensee must cause all Covered Code to which Licensee contributes to
     49  1.1  jruoho  * contain a file documenting the changes Licensee made to create that Covered
     50  1.1  jruoho  * Code and the date of any change.  Licensee must include in that file the
     51  1.1  jruoho  * documentation of any changes made by any predecessor Licensee.  Licensee
     52  1.1  jruoho  * must include a prominent statement that the modification is derived,
     53  1.1  jruoho  * directly or indirectly, from Original Intel Code.
     54  1.1  jruoho  *
     55  1.1  jruoho  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     57  1.1  jruoho  * Code or modification without rights to further distribute source must
     58  1.1  jruoho  * include the following Disclaimer and Export Compliance provision in the
     59  1.1  jruoho  * documentation and/or other materials provided with distribution.  In
     60  1.1  jruoho  * addition, Licensee may not authorize further sublicense of source of any
     61  1.1  jruoho  * portion of the Covered Code, and must include terms to the effect that the
     62  1.1  jruoho  * license from Licensee to its licensee is limited to the intellectual
     63  1.1  jruoho  * property embodied in the software Licensee provides to its licensee, and
     64  1.1  jruoho  * not to intellectual property embodied in modifications its licensee may
     65  1.1  jruoho  * make.
     66  1.1  jruoho  *
     67  1.1  jruoho  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  1.1  jruoho  * substantial portion of the Covered Code or modification must reproduce the
     69  1.1  jruoho  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  1.1  jruoho  * provision in the documentation and/or other materials provided with the
     71  1.1  jruoho  * distribution.
     72  1.1  jruoho  *
     73  1.1  jruoho  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  1.1  jruoho  * Intel Code.
     75  1.1  jruoho  *
     76  1.1  jruoho  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  1.1  jruoho  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  1.1  jruoho  * other dealings in products derived from or relating to the Covered Code
     79  1.1  jruoho  * without prior written authorization from Intel.
     80  1.1  jruoho  *
     81  1.1  jruoho  * 4. Disclaimer and Export Compliance
     82  1.1  jruoho  *
     83  1.1  jruoho  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  1.1  jruoho  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  1.1  jruoho  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     86  1.1  jruoho  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     87  1.1  jruoho  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     88  1.1  jruoho  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  1.1  jruoho  * PARTICULAR PURPOSE.
     90  1.1  jruoho  *
     91  1.1  jruoho  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  1.1  jruoho  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  1.1  jruoho  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  1.1  jruoho  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  1.1  jruoho  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  1.1  jruoho  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     97  1.1  jruoho  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  1.1  jruoho  * LIMITED REMEDY.
     99  1.1  jruoho  *
    100  1.1  jruoho  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  1.1  jruoho  * software or system incorporating such software without first obtaining any
    102  1.1  jruoho  * required license or other approval from the U. S. Department of Commerce or
    103  1.1  jruoho  * any other agency or department of the United States Government.  In the
    104  1.1  jruoho  * event Licensee exports any such software from the United States or
    105  1.1  jruoho  * re-exports any such software from a foreign destination, Licensee shall
    106  1.1  jruoho  * ensure that the distribution and export/re-export of the software is in
    107  1.1  jruoho  * compliance with all laws, regulations, orders, or other restrictions of the
    108  1.1  jruoho  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  1.1  jruoho  * any of its subsidiaries will export/re-export any technical data, process,
    110  1.1  jruoho  * software, or service, directly or indirectly, to any country for which the
    111  1.1  jruoho  * United States government or any agency thereof requires an export license,
    112  1.1  jruoho  * other governmental approval, or letter of assurance, without first obtaining
    113  1.1  jruoho  * such license, approval or letter.
    114  1.1  jruoho  *
    115  1.1  jruoho  *****************************************************************************/
    116  1.1  jruoho 
    117  1.1  jruoho 
    118  1.1  jruoho #include "acpi.h"
    119  1.1  jruoho #include "accommon.h"
    120  1.1  jruoho #include "acdebug.h"
    121  1.1  jruoho 
    122  1.1  jruoho #ifdef ACPI_APPLICATION
    123  1.1  jruoho #include "actables.h"
    124  1.1  jruoho #endif
    125  1.1  jruoho 
    126  1.1  jruoho #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
    127  1.1  jruoho 
    128  1.1  jruoho #define _COMPONENT          ACPI_CA_DEBUGGER
    129  1.1  jruoho         ACPI_MODULE_NAME    ("dbfileio")
    130  1.1  jruoho 
    131  1.1  jruoho /*
    132  1.1  jruoho  * NOTE: this is here for lack of a better place. It is used in all
    133  1.1  jruoho  * flavors of the debugger, need LCD file
    134  1.1  jruoho  */
    135  1.1  jruoho #ifdef ACPI_APPLICATION
    136  1.1  jruoho #include <stdio.h>
    137  1.1  jruoho FILE                        *AcpiGbl_DebugFile = NULL;
    138  1.1  jruoho #endif
    139  1.1  jruoho 
    140  1.1  jruoho 
    141  1.1  jruoho #ifdef ACPI_DEBUGGER
    142  1.1  jruoho 
    143  1.1  jruoho /* Local prototypes */
    144  1.1  jruoho 
    145  1.1  jruoho #ifdef ACPI_APPLICATION
    146  1.1  jruoho 
    147  1.1  jruoho static ACPI_STATUS
    148  1.1  jruoho AcpiDbCheckTextModeCorruption (
    149  1.1  jruoho     UINT8                   *Table,
    150  1.1  jruoho     UINT32                  TableLength,
    151  1.1  jruoho     UINT32                  FileLength);
    152  1.1  jruoho 
    153  1.1  jruoho #endif
    154  1.1  jruoho 
    155  1.1  jruoho /*******************************************************************************
    156  1.1  jruoho  *
    157  1.1  jruoho  * FUNCTION:    AcpiDbCloseDebugFile
    158  1.1  jruoho  *
    159  1.1  jruoho  * PARAMETERS:  None
    160  1.1  jruoho  *
    161  1.1  jruoho  * RETURN:      None
    162  1.1  jruoho  *
    163  1.1  jruoho  * DESCRIPTION: If open, close the current debug output file
    164  1.1  jruoho  *
    165  1.1  jruoho  ******************************************************************************/
    166  1.1  jruoho 
    167  1.1  jruoho void
    168  1.1  jruoho AcpiDbCloseDebugFile (
    169  1.1  jruoho     void)
    170  1.1  jruoho {
    171  1.1  jruoho 
    172  1.1  jruoho #ifdef ACPI_APPLICATION
    173  1.1  jruoho 
    174  1.1  jruoho     if (AcpiGbl_DebugFile)
    175  1.1  jruoho     {
    176  1.1  jruoho        fclose (AcpiGbl_DebugFile);
    177  1.1  jruoho        AcpiGbl_DebugFile = NULL;
    178  1.1  jruoho        AcpiGbl_DbOutputToFile = FALSE;
    179  1.1  jruoho        AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
    180  1.1  jruoho     }
    181  1.1  jruoho #endif
    182  1.1  jruoho }
    183  1.1  jruoho 
    184  1.1  jruoho 
    185  1.1  jruoho /*******************************************************************************
    186  1.1  jruoho  *
    187  1.1  jruoho  * FUNCTION:    AcpiDbOpenDebugFile
    188  1.1  jruoho  *
    189  1.1  jruoho  * PARAMETERS:  Name                - Filename to open
    190  1.1  jruoho  *
    191  1.1  jruoho  * RETURN:      None
    192  1.1  jruoho  *
    193  1.1  jruoho  * DESCRIPTION: Open a file where debug output will be directed.
    194  1.1  jruoho  *
    195  1.1  jruoho  ******************************************************************************/
    196  1.1  jruoho 
    197  1.1  jruoho void
    198  1.1  jruoho AcpiDbOpenDebugFile (
    199  1.1  jruoho     char                    *Name)
    200  1.1  jruoho {
    201  1.1  jruoho 
    202  1.1  jruoho #ifdef ACPI_APPLICATION
    203  1.1  jruoho 
    204  1.1  jruoho     AcpiDbCloseDebugFile ();
    205  1.1  jruoho     AcpiGbl_DebugFile = fopen (Name, "w+");
    206  1.1  jruoho     if (AcpiGbl_DebugFile)
    207  1.1  jruoho     {
    208  1.1  jruoho         AcpiOsPrintf ("Debug output file %s opened\n", Name);
    209  1.1  jruoho         ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
    210  1.1  jruoho         AcpiGbl_DbOutputToFile = TRUE;
    211  1.1  jruoho     }
    212  1.1  jruoho     else
    213  1.1  jruoho     {
    214  1.1  jruoho         AcpiOsPrintf ("Could not open debug file %s\n", Name);
    215  1.1  jruoho     }
    216  1.1  jruoho 
    217  1.1  jruoho #endif
    218  1.1  jruoho }
    219  1.1  jruoho #endif
    220  1.1  jruoho 
    221  1.1  jruoho 
    222  1.1  jruoho #ifdef ACPI_APPLICATION
    223  1.1  jruoho /*******************************************************************************
    224  1.1  jruoho  *
    225  1.1  jruoho  * FUNCTION:    AcpiDbCheckTextModeCorruption
    226  1.1  jruoho  *
    227  1.1  jruoho  * PARAMETERS:  Table           - Table buffer
    228  1.1  jruoho  *              TableLength     - Length of table from the table header
    229  1.1  jruoho  *              FileLength      - Length of the file that contains the table
    230  1.1  jruoho  *
    231  1.1  jruoho  * RETURN:      Status
    232  1.1  jruoho  *
    233  1.1  jruoho  * DESCRIPTION: Check table for text mode file corruption where all linefeed
    234  1.1  jruoho  *              characters (LF) have been replaced by carriage return linefeed
    235  1.1  jruoho  *              pairs (CR/LF).
    236  1.1  jruoho  *
    237  1.1  jruoho  ******************************************************************************/
    238  1.1  jruoho 
    239  1.1  jruoho static ACPI_STATUS
    240  1.1  jruoho AcpiDbCheckTextModeCorruption (
    241  1.1  jruoho     UINT8                   *Table,
    242  1.1  jruoho     UINT32                  TableLength,
    243  1.1  jruoho     UINT32                  FileLength)
    244  1.1  jruoho {
    245  1.1  jruoho     UINT32                  i;
    246  1.1  jruoho     UINT32                  Pairs = 0;
    247  1.1  jruoho 
    248  1.1  jruoho 
    249  1.1  jruoho     if (TableLength != FileLength)
    250  1.1  jruoho     {
    251  1.1  jruoho         ACPI_WARNING ((AE_INFO,
    252  1.1  jruoho             "File length (0x%X) is not the same as the table length (0x%X)",
    253  1.1  jruoho             FileLength, TableLength));
    254  1.1  jruoho     }
    255  1.1  jruoho 
    256  1.1  jruoho     /* Scan entire table to determine if each LF has been prefixed with a CR */
    257  1.1  jruoho 
    258  1.1  jruoho     for (i = 1; i < FileLength; i++)
    259  1.1  jruoho     {
    260  1.1  jruoho         if (Table[i] == 0x0A)
    261  1.1  jruoho         {
    262  1.1  jruoho             if (Table[i - 1] != 0x0D)
    263  1.1  jruoho             {
    264  1.1  jruoho                 /* The LF does not have a preceding CR, table not corrupted */
    265  1.1  jruoho 
    266  1.1  jruoho                 return (AE_OK);
    267  1.1  jruoho             }
    268  1.1  jruoho             else
    269  1.1  jruoho             {
    270  1.1  jruoho                 /* Found a CR/LF pair */
    271  1.1  jruoho 
    272  1.1  jruoho                 Pairs++;
    273  1.1  jruoho             }
    274  1.1  jruoho             i++;
    275  1.1  jruoho         }
    276  1.1  jruoho     }
    277  1.1  jruoho 
    278  1.1  jruoho     if (!Pairs)
    279  1.1  jruoho     {
    280  1.1  jruoho         return (AE_OK);
    281  1.1  jruoho     }
    282  1.1  jruoho 
    283  1.1  jruoho     /*
    284  1.1  jruoho      * Entire table scanned, each CR is part of a CR/LF pair --
    285  1.1  jruoho      * meaning that the table was treated as a text file somewhere.
    286  1.1  jruoho      *
    287  1.1  jruoho      * NOTE: We can't "fix" the table, because any existing CR/LF pairs in the
    288  1.1  jruoho      * original table are left untouched by the text conversion process --
    289  1.1  jruoho      * meaning that we cannot simply replace CR/LF pairs with LFs.
    290  1.1  jruoho      */
    291  1.1  jruoho     AcpiOsPrintf ("Table has been corrupted by text mode conversion\n");
    292  1.1  jruoho     AcpiOsPrintf ("All LFs (%u) were changed to CR/LF pairs\n", Pairs);
    293  1.1  jruoho     AcpiOsPrintf ("Table cannot be repaired!\n");
    294  1.1  jruoho     return (AE_BAD_VALUE);
    295  1.1  jruoho }
    296  1.1  jruoho 
    297  1.1  jruoho 
    298  1.1  jruoho /*******************************************************************************
    299  1.1  jruoho  *
    300  1.1  jruoho  * FUNCTION:    AcpiDbReadTable
    301  1.1  jruoho  *
    302  1.1  jruoho  * PARAMETERS:  fp              - File that contains table
    303  1.1  jruoho  *              Table           - Return value, buffer with table
    304  1.1  jruoho  *              TableLength     - Return value, length of table
    305  1.1  jruoho  *
    306  1.1  jruoho  * RETURN:      Status
    307  1.1  jruoho  *
    308  1.1  jruoho  * DESCRIPTION: Load the DSDT from the file pointer
    309  1.1  jruoho  *
    310  1.1  jruoho  ******************************************************************************/
    311  1.1  jruoho 
    312  1.1  jruoho static ACPI_STATUS
    313  1.1  jruoho AcpiDbReadTable (
    314  1.1  jruoho     FILE                    *fp,
    315  1.1  jruoho     ACPI_TABLE_HEADER       **Table,
    316  1.1  jruoho     UINT32                  *TableLength)
    317  1.1  jruoho {
    318  1.1  jruoho     ACPI_TABLE_HEADER       TableHeader;
    319  1.1  jruoho     UINT32                  Actual;
    320  1.1  jruoho     ACPI_STATUS             Status;
    321  1.1  jruoho     UINT32                  FileSize;
    322  1.1  jruoho     BOOLEAN                 StandardHeader = TRUE;
    323  1.1  jruoho 
    324  1.1  jruoho 
    325  1.1  jruoho     /* Get the file size */
    326  1.1  jruoho 
    327  1.1  jruoho     fseek (fp, 0, SEEK_END);
    328  1.1  jruoho     FileSize = (UINT32) ftell (fp);
    329  1.1  jruoho     fseek (fp, 0, SEEK_SET);
    330  1.1  jruoho 
    331  1.1  jruoho     if (FileSize < 4)
    332  1.1  jruoho     {
    333  1.1  jruoho         return (AE_BAD_HEADER);
    334  1.1  jruoho     }
    335  1.1  jruoho 
    336  1.1  jruoho     /* Read the signature */
    337  1.1  jruoho 
    338  1.1  jruoho     if (fread (&TableHeader, 1, 4, fp) != 4)
    339  1.1  jruoho     {
    340  1.1  jruoho         AcpiOsPrintf ("Could not read the table signature\n");
    341  1.1  jruoho         return (AE_BAD_HEADER);
    342  1.1  jruoho     }
    343  1.1  jruoho 
    344  1.1  jruoho     fseek (fp, 0, SEEK_SET);
    345  1.1  jruoho 
    346  1.1  jruoho     /* The RSDT and FACS tables do not have standard ACPI headers */
    347  1.1  jruoho 
    348  1.1  jruoho     if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
    349  1.1  jruoho         ACPI_COMPARE_NAME (TableHeader.Signature, "FACS"))
    350  1.1  jruoho     {
    351  1.1  jruoho         *TableLength = FileSize;
    352  1.1  jruoho         StandardHeader = FALSE;
    353  1.1  jruoho     }
    354  1.1  jruoho     else
    355  1.1  jruoho     {
    356  1.1  jruoho         /* Read the table header */
    357  1.1  jruoho 
    358  1.1  jruoho         if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
    359  1.1  jruoho                 sizeof (ACPI_TABLE_HEADER))
    360  1.1  jruoho         {
    361  1.1  jruoho             AcpiOsPrintf ("Could not read the table header\n");
    362  1.1  jruoho             return (AE_BAD_HEADER);
    363  1.1  jruoho         }
    364  1.1  jruoho 
    365  1.1  jruoho #if 0
    366  1.1  jruoho         /* Validate the table header/length */
    367  1.1  jruoho 
    368  1.1  jruoho         Status = AcpiTbValidateTableHeader (&TableHeader);
    369  1.1  jruoho         if (ACPI_FAILURE (Status))
    370  1.1  jruoho         {
    371  1.1  jruoho             AcpiOsPrintf ("Table header is invalid!\n");
    372  1.1  jruoho             return (Status);
    373  1.1  jruoho         }
    374  1.1  jruoho #endif
    375  1.1  jruoho 
    376  1.1  jruoho         /* File size must be at least as long as the Header-specified length */
    377  1.1  jruoho 
    378  1.1  jruoho         if (TableHeader.Length > FileSize)
    379  1.1  jruoho         {
    380  1.1  jruoho             AcpiOsPrintf (
    381  1.1  jruoho                 "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
    382  1.1  jruoho                 TableHeader.Length, FileSize);
    383  1.1  jruoho             return (AE_BAD_HEADER);
    384  1.1  jruoho         }
    385  1.1  jruoho 
    386  1.1  jruoho #ifdef ACPI_OBSOLETE_CODE
    387  1.1  jruoho         /* We only support a limited number of table types */
    388  1.1  jruoho 
    389  1.1  jruoho         if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
    390  1.1  jruoho             ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
    391  1.1  jruoho             ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
    392  1.1  jruoho         {
    393  1.1  jruoho             AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
    394  1.1  jruoho                 (char *) TableHeader.Signature);
    395  1.1  jruoho             ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
    396  1.1  jruoho             return (AE_ERROR);
    397  1.1  jruoho         }
    398  1.1  jruoho #endif
    399  1.1  jruoho 
    400  1.1  jruoho         *TableLength = TableHeader.Length;
    401  1.1  jruoho     }
    402  1.1  jruoho 
    403  1.1  jruoho     /* Allocate a buffer for the table */
    404  1.1  jruoho 
    405  1.1  jruoho     *Table = AcpiOsAllocate ((size_t) FileSize);
    406  1.1  jruoho     if (!*Table)
    407  1.1  jruoho     {
    408  1.1  jruoho         AcpiOsPrintf (
    409  1.1  jruoho             "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
    410  1.1  jruoho             TableHeader.Signature, *TableLength);
    411  1.1  jruoho         return (AE_NO_MEMORY);
    412  1.1  jruoho     }
    413  1.1  jruoho 
    414  1.1  jruoho     /* Get the rest of the table */
    415  1.1  jruoho 
    416  1.1  jruoho     fseek (fp, 0, SEEK_SET);
    417  1.1  jruoho     Actual = fread (*Table, 1, (size_t) FileSize, fp);
    418  1.1  jruoho     if (Actual == FileSize)
    419  1.1  jruoho     {
    420  1.1  jruoho         if (StandardHeader)
    421  1.1  jruoho         {
    422  1.1  jruoho             /* Now validate the checksum */
    423  1.1  jruoho 
    424  1.1  jruoho             Status = AcpiTbVerifyChecksum ((void *) *Table,
    425  1.1  jruoho                         ACPI_CAST_PTR (ACPI_TABLE_HEADER, *Table)->Length);
    426  1.1  jruoho 
    427  1.1  jruoho             if (Status == AE_BAD_CHECKSUM)
    428  1.1  jruoho             {
    429  1.1  jruoho                 Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
    430  1.1  jruoho                             FileSize, (*Table)->Length);
    431  1.1  jruoho                 return (Status);
    432  1.1  jruoho             }
    433  1.1  jruoho         }
    434  1.1  jruoho         return (AE_OK);
    435  1.1  jruoho     }
    436  1.1  jruoho 
    437  1.1  jruoho     if (Actual > 0)
    438  1.1  jruoho     {
    439  1.1  jruoho         AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
    440  1.1  jruoho             FileSize, Actual);
    441  1.1  jruoho         return (AE_OK);
    442  1.1  jruoho     }
    443  1.1  jruoho 
    444  1.1  jruoho     AcpiOsPrintf ("Error - could not read the table file\n");
    445  1.1  jruoho     AcpiOsFree (*Table);
    446  1.1  jruoho     *Table = NULL;
    447  1.1  jruoho     *TableLength = 0;
    448  1.1  jruoho 
    449  1.1  jruoho     return (AE_ERROR);
    450  1.1  jruoho }
    451  1.1  jruoho 
    452  1.1  jruoho 
    453  1.1  jruoho /*******************************************************************************
    454  1.1  jruoho  *
    455  1.1  jruoho  * FUNCTION:    AeLocalLoadTable
    456  1.1  jruoho  *
    457  1.1  jruoho  * PARAMETERS:  Table           - pointer to a buffer containing the entire
    458  1.1  jruoho  *                                table to be loaded
    459  1.1  jruoho  *
    460  1.1  jruoho  * RETURN:      Status
    461  1.1  jruoho  *
    462  1.1  jruoho  * DESCRIPTION: This function is called to load a table from the caller's
    463  1.1  jruoho  *              buffer. The buffer must contain an entire ACPI Table including
    464  1.1  jruoho  *              a valid header. The header fields will be verified, and if it
    465  1.1  jruoho  *              is determined that the table is invalid, the call will fail.
    466  1.1  jruoho  *
    467  1.1  jruoho  ******************************************************************************/
    468  1.1  jruoho 
    469  1.1  jruoho static ACPI_STATUS
    470  1.1  jruoho AeLocalLoadTable (
    471  1.1  jruoho     ACPI_TABLE_HEADER       *Table)
    472  1.1  jruoho {
    473  1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    474  1.1  jruoho /*    ACPI_TABLE_DESC         TableInfo; */
    475  1.1  jruoho 
    476  1.1  jruoho 
    477  1.1  jruoho     ACPI_FUNCTION_TRACE (AeLocalLoadTable);
    478  1.1  jruoho #if 0
    479  1.1  jruoho 
    480  1.1  jruoho 
    481  1.1  jruoho     if (!Table)
    482  1.1  jruoho     {
    483  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    484  1.1  jruoho     }
    485  1.1  jruoho 
    486  1.1  jruoho     TableInfo.Pointer = Table;
    487  1.1  jruoho     Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
    488  1.1  jruoho     if (ACPI_FAILURE (Status))
    489  1.1  jruoho     {
    490  1.1  jruoho         return_ACPI_STATUS (Status);
    491  1.1  jruoho     }
    492  1.1  jruoho 
    493  1.1  jruoho     /* Install the new table into the local data structures */
    494  1.1  jruoho 
    495  1.1  jruoho     Status = AcpiTbInstallTable (&TableInfo);
    496  1.1  jruoho     if (ACPI_FAILURE (Status))
    497  1.1  jruoho     {
    498  1.1  jruoho         if (Status == AE_ALREADY_EXISTS)
    499  1.1  jruoho         {
    500  1.1  jruoho             /* Table already exists, no error */
    501  1.1  jruoho 
    502  1.1  jruoho             Status = AE_OK;
    503  1.1  jruoho         }
    504  1.1  jruoho 
    505  1.1  jruoho         /* Free table allocated by AcpiTbGetTable */
    506  1.1  jruoho 
    507  1.1  jruoho         AcpiTbDeleteSingleTable (&TableInfo);
    508  1.1  jruoho         return_ACPI_STATUS (Status);
    509  1.1  jruoho     }
    510  1.1  jruoho 
    511  1.1  jruoho #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
    512  1.1  jruoho 
    513  1.1  jruoho     Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
    514  1.1  jruoho     if (ACPI_FAILURE (Status))
    515  1.1  jruoho     {
    516  1.1  jruoho         /* Uninstall table and free the buffer */
    517  1.1  jruoho 
    518  1.1  jruoho         AcpiTbDeleteTablesByType (ACPI_TABLE_ID_DSDT);
    519  1.1  jruoho         return_ACPI_STATUS (Status);
    520  1.1  jruoho     }
    521  1.1  jruoho #endif
    522  1.1  jruoho #endif
    523  1.1  jruoho 
    524  1.1  jruoho     return_ACPI_STATUS (Status);
    525  1.1  jruoho }
    526  1.1  jruoho 
    527  1.1  jruoho 
    528  1.1  jruoho /*******************************************************************************
    529  1.1  jruoho  *
    530  1.1  jruoho  * FUNCTION:    AcpiDbReadTableFromFile
    531  1.1  jruoho  *
    532  1.1  jruoho  * PARAMETERS:  Filename         - File where table is located
    533  1.1  jruoho  *              Table            - Where a pointer to the table is returned
    534  1.1  jruoho  *
    535  1.1  jruoho  * RETURN:      Status
    536  1.1  jruoho  *
    537  1.1  jruoho  * DESCRIPTION: Get an ACPI table from a file
    538  1.1  jruoho  *
    539  1.1  jruoho  ******************************************************************************/
    540  1.1  jruoho 
    541  1.1  jruoho ACPI_STATUS
    542  1.1  jruoho AcpiDbReadTableFromFile (
    543  1.1  jruoho     char                    *Filename,
    544  1.1  jruoho     ACPI_TABLE_HEADER       **Table)
    545  1.1  jruoho {
    546  1.1  jruoho     FILE                    *fp;
    547  1.1  jruoho     UINT32                  TableLength;
    548  1.1  jruoho     ACPI_STATUS             Status;
    549  1.1  jruoho 
    550  1.1  jruoho 
    551  1.1  jruoho     /* Open the file */
    552  1.1  jruoho 
    553  1.1  jruoho     fp = fopen (Filename, "rb");
    554  1.1  jruoho     if (!fp)
    555  1.1  jruoho     {
    556  1.1  jruoho         AcpiOsPrintf ("Could not open input file %s\n", Filename);
    557  1.1  jruoho         return (AE_ERROR);
    558  1.1  jruoho     }
    559  1.1  jruoho 
    560  1.1  jruoho     /* Get the entire file */
    561  1.1  jruoho 
    562  1.1  jruoho     fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
    563  1.1  jruoho     Status = AcpiDbReadTable (fp, Table, &TableLength);
    564  1.1  jruoho     fclose(fp);
    565  1.1  jruoho 
    566  1.1  jruoho     if (ACPI_FAILURE (Status))
    567  1.1  jruoho     {
    568  1.1  jruoho         AcpiOsPrintf ("Could not get table from the file\n");
    569  1.1  jruoho         return (Status);
    570  1.1  jruoho     }
    571  1.1  jruoho 
    572  1.1  jruoho     return (AE_OK);
    573  1.1  jruoho  }
    574  1.1  jruoho #endif
    575  1.1  jruoho 
    576  1.1  jruoho 
    577  1.1  jruoho /*******************************************************************************
    578  1.1  jruoho  *
    579  1.1  jruoho  * FUNCTION:    AcpiDbGetTableFromFile
    580  1.1  jruoho  *
    581  1.1  jruoho  * PARAMETERS:  Filename        - File where table is located
    582  1.1  jruoho  *              ReturnTable     - Where a pointer to the table is returned
    583  1.1  jruoho  *
    584  1.1  jruoho  * RETURN:      Status
    585  1.1  jruoho  *
    586  1.1  jruoho  * DESCRIPTION: Load an ACPI table from a file
    587  1.1  jruoho  *
    588  1.1  jruoho  ******************************************************************************/
    589  1.1  jruoho 
    590  1.1  jruoho ACPI_STATUS
    591  1.1  jruoho AcpiDbGetTableFromFile (
    592  1.1  jruoho     char                    *Filename,
    593  1.1  jruoho     ACPI_TABLE_HEADER       **ReturnTable)
    594  1.1  jruoho {
    595  1.1  jruoho #ifdef ACPI_APPLICATION
    596  1.1  jruoho     ACPI_STATUS             Status;
    597  1.1  jruoho     ACPI_TABLE_HEADER       *Table;
    598  1.1  jruoho     BOOLEAN                 IsAmlTable = TRUE;
    599  1.1  jruoho 
    600  1.1  jruoho 
    601  1.1  jruoho     Status = AcpiDbReadTableFromFile (Filename, &Table);
    602  1.1  jruoho     if (ACPI_FAILURE (Status))
    603  1.1  jruoho     {
    604  1.1  jruoho         return (Status);
    605  1.1  jruoho     }
    606  1.1  jruoho 
    607  1.1  jruoho #ifdef ACPI_DATA_TABLE_DISASSEMBLY
    608  1.1  jruoho     IsAmlTable = AcpiUtIsAmlTable (Table);
    609  1.1  jruoho #endif
    610  1.1  jruoho 
    611  1.1  jruoho     if (IsAmlTable)
    612  1.1  jruoho     {
    613  1.1  jruoho         /* Attempt to recognize and install the table */
    614  1.1  jruoho 
    615  1.1  jruoho         Status = AeLocalLoadTable (Table);
    616  1.1  jruoho         if (ACPI_FAILURE (Status))
    617  1.1  jruoho         {
    618  1.1  jruoho             if (Status == AE_ALREADY_EXISTS)
    619  1.1  jruoho             {
    620  1.1  jruoho                 AcpiOsPrintf ("Table %4.4s is already installed\n",
    621  1.1  jruoho                     Table->Signature);
    622  1.1  jruoho             }
    623  1.1  jruoho             else
    624  1.1  jruoho             {
    625  1.1  jruoho                 AcpiOsPrintf ("Could not install table, %s\n",
    626  1.1  jruoho                     AcpiFormatException (Status));
    627  1.1  jruoho             }
    628  1.1  jruoho 
    629  1.1  jruoho             return (Status);
    630  1.1  jruoho         }
    631  1.1  jruoho 
    632  1.1  jruoho         fprintf (stderr,
    633  1.1  jruoho             "Acpi table [%4.4s] successfully installed and loaded\n",
    634  1.1  jruoho             Table->Signature);
    635  1.1  jruoho     }
    636  1.1  jruoho 
    637  1.1  jruoho     AcpiGbl_AcpiHardwarePresent = FALSE;
    638  1.1  jruoho     if (ReturnTable)
    639  1.1  jruoho     {
    640  1.1  jruoho         *ReturnTable = Table;
    641  1.1  jruoho     }
    642  1.1  jruoho 
    643  1.1  jruoho 
    644  1.1  jruoho #endif  /* ACPI_APPLICATION */
    645  1.1  jruoho     return (AE_OK);
    646  1.1  jruoho }
    647  1.1  jruoho 
    648  1.1  jruoho #endif  /* ACPI_DEBUGGER */
    649  1.1  jruoho 
    650