1 /*******************************************************************************
3 * Module Name: dbfileio - Debugger file I/O commands. These can't usually
4 * be used when running the debugger in Ring 0 (Kernel mode)
7 ******************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
117 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/dbfileio.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $ */
121 #include "acnamesp.h"
122 #include "actables.h"
124 #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
126 #define _COMPONENT ACPI_CA_DEBUGGER
127 ACPI_MODULE_NAME ("dbfileio")
131 * NOTE: this is here for lack of a better place. It is used in all
132 * flavors of the debugger, need LCD file
134 #ifdef ACPI_APPLICATION
136 FILE *AcpiGbl_DebugFile = NULL;
141 /*******************************************************************************
143 * FUNCTION: AcpiDbCloseDebugFile
149 * DESCRIPTION: If open, close the current debug output file
151 ******************************************************************************/
154 AcpiDbCloseDebugFile (
158 #ifdef ACPI_APPLICATION
160 if (AcpiGbl_DebugFile)
162 fclose (AcpiGbl_DebugFile);
163 AcpiGbl_DebugFile = NULL;
164 AcpiGbl_DbOutputToFile = FALSE;
165 AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename);
171 /*******************************************************************************
173 * FUNCTION: AcpiDbOpenDebugFile
175 * PARAMETERS: Name - Filename to open
179 * DESCRIPTION: Open a file where debug output will be directed.
181 ******************************************************************************/
184 AcpiDbOpenDebugFile (
188 #ifdef ACPI_APPLICATION
190 AcpiDbCloseDebugFile ();
191 AcpiGbl_DebugFile = fopen (Name, "w+");
192 if (AcpiGbl_DebugFile)
194 AcpiOsPrintf ("Debug output file %s opened\n", Name);
195 ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
196 AcpiGbl_DbOutputToFile = TRUE;
200 AcpiOsPrintf ("Could not open debug file %s\n", Name);
208 #ifdef ACPI_APPLICATION
209 /*******************************************************************************
211 * FUNCTION: AcpiDbReadTable
213 * PARAMETERS: fp - File that contains table
214 * Table - Return value, buffer with table
215 * TableLength - Return value, length of table
219 * DESCRIPTION: Load the DSDT from the file pointer
221 ******************************************************************************/
226 ACPI_TABLE_HEADER **Table,
229 ACPI_TABLE_HEADER TableHeader;
236 /* Read the table header */
238 if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != sizeof (ACPI_TABLE_HEADER))
240 AcpiOsPrintf ("Couldn't read the table header\n");
241 return (AE_BAD_SIGNATURE);
244 /* Validate the table header/length */
246 Status = AcpiTbValidateTableHeader (&TableHeader);
247 if ((ACPI_FAILURE (Status)) ||
248 (TableHeader.Length > 0x800000)) /* 8 Mbyte should be enough */
250 AcpiOsPrintf ("Table header is invalid!\n");
254 /* We only support a limited number of table types */
256 if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
257 ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
258 ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
260 AcpiOsPrintf ("Table signature is invalid\n");
261 ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
265 /* Allocate a buffer for the table */
267 *TableLength = TableHeader.Length;
268 *Table = AcpiOsAllocate ((size_t) *TableLength);
271 AcpiOsPrintf ("Could not allocate memory for ACPI table %4.4s (size=%X)\n",
272 TableHeader.Signature, TableHeader.Length);
273 return (AE_NO_MEMORY);
276 AmlStart = (UINT8 *) *Table + sizeof (TableHeader);
277 AmlLength = *TableLength - sizeof (TableHeader);
279 /* Copy the header to the buffer */
281 ACPI_MEMCPY (*Table, &TableHeader, sizeof (TableHeader));
283 /* Get the rest of the table */
285 Actual = fread (AmlStart, 1, (size_t) AmlLength, fp);
286 if (Actual == AmlLength)
288 /* Now validate the checksum */
290 Status = AcpiTbVerifyTableChecksum (*Table);
296 AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", AmlLength, Actual);
300 AcpiOsPrintf ("Error - could not read the table file\n");
310 /*******************************************************************************
312 * FUNCTION: AeLocalLoadTable
314 * PARAMETERS: Table - pointer to a buffer containing the entire
319 * DESCRIPTION: This function is called to load a table from the caller's
320 * buffer. The buffer must contain an entire ACPI Table including
321 * a valid header. The header fields will be verified, and if it
322 * is determined that the table is invalid, the call will fail.
324 ******************************************************************************/
328 ACPI_TABLE_HEADER *Table)
331 ACPI_TABLE_DESC TableInfo;
334 ACPI_FUNCTION_TRACE ("AeLocalLoadTable");
339 return_ACPI_STATUS (AE_BAD_PARAMETER);
342 TableInfo.Pointer = Table;
343 Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_ALL);
344 if (ACPI_FAILURE (Status))
346 return_ACPI_STATUS (Status);
349 /* Install the new table into the local data structures */
351 Status = AcpiTbInstallTable (&TableInfo);
352 if (ACPI_FAILURE (Status))
354 /* Free table allocated by AcpiTbGetTable */
356 AcpiTbDeleteSingleTable (&TableInfo);
357 return_ACPI_STATUS (Status);
360 #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY))
362 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode);
363 if (ACPI_FAILURE (Status))
365 /* Uninstall table and free the buffer */
367 AcpiTbDeleteAcpiTable (ACPI_TABLE_DSDT);
368 return_ACPI_STATUS (Status);
372 return_ACPI_STATUS (Status);
376 #ifdef ACPI_APPLICATION
377 /*******************************************************************************
379 * FUNCTION: AcpiDbReadTableFromFile
381 * PARAMETERS: Filename - File where table is located
382 * Table - Where a pointer to the table is returned
386 * DESCRIPTION: Get an ACPI table from a file
388 ******************************************************************************/
391 AcpiDbReadTableFromFile (
393 ACPI_TABLE_HEADER **Table)
402 fp = fopen (Filename, "rb");
405 AcpiOsPrintf ("Could not open input file %s\n", Filename);
409 /* Get the entire file */
411 fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
412 Status = AcpiDbReadTable (fp, Table, &TableLength);
415 if (ACPI_FAILURE (Status))
417 AcpiOsPrintf ("Couldn't get table from the file\n");
426 /*******************************************************************************
428 * FUNCTION: AcpiDbGetTableFromFile
430 * PARAMETERS: Filename - File where table is located
431 * Table - Where a pointer to the table is returned
435 * DESCRIPTION: Load an ACPI table from a file
437 ******************************************************************************/
440 AcpiDbGetTableFromFile (
442 ACPI_TABLE_HEADER **ReturnTable)
444 #ifdef ACPI_APPLICATION
446 ACPI_TABLE_HEADER *Table;
449 Status = AcpiDbReadTableFromFile (Filename, &Table);
450 if (ACPI_FAILURE (Status))
455 /* Attempt to recognize and install the table */
457 Status = AeLocalLoadTable (Table);
458 if (ACPI_FAILURE (Status))
460 if (Status == AE_ALREADY_EXISTS)
462 AcpiOsPrintf ("Table %4.4s is already installed\n",
467 AcpiOsPrintf ("Could not install table, %s\n",
468 AcpiFormatException (Status));
474 fprintf (stderr, "Acpi table [%4.4s] successfully installed and loaded\n",
477 AcpiGbl_AcpiHardwarePresent = FALSE;
480 *ReturnTable = Table;
484 #endif /* ACPI_APPLICATION */
488 #endif /* ACPI_DEBUGGER */