dbfileio.c revision 100966
119304Speter/******************************************************************************* 219304Speter * 319304Speter * Module Name: dbfileio - Debugger file I/O commands. These can't usually 419304Speter * be used when running the debugger in Ring 0 (Kernel mode) 519304Speter * $Revision: 67 $ 619304Speter * 719304Speter ******************************************************************************/ 819304Speter 9254225Speter/****************************************************************************** 1019304Speter * 1119304Speter * 1. Copyright Notice 1219304Speter * 1319304Speter * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp. 1419304Speter * All rights reserved. 1519304Speter * 1619304Speter * 2. License 1719304Speter * 1819304Speter * 2.1. This is your license from Intel Corp. under its intellectual property 1919304Speter * rights. You may have additional license terms from the party that provided 2019304Speter * you this software, covering your right to use that party's intellectual 2119304Speter * property rights. 2219304Speter * 2319304Speter * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2419304Speter * copy of the source code appearing in this file ("Covered Code") an 2519304Speter * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2619304Speter * base code distributed originally by Intel ("Original Intel Code") to copy, 2719304Speter * make derivatives, distribute, use and display any portion of the Covered 2819304Speter * Code in any form, with the right to sublicense such rights; and 2919304Speter * 3019304Speter * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3119304Speter * license (with the right to sublicense), under only those claims of Intel 3219304Speter * patents that are infringed by the Original Intel Code, to make, use, sell, 3319304Speter * offer to sell, and import the Covered Code and derivative works thereof 3419304Speter * solely to the minimum extent necessary to exercise the above copyright 35254225Speter * license, and in no event shall the patent license extend to any additions 3619304Speter * to or modifications of the Original Intel Code. No other license or right 3719304Speter * is granted directly or by implication, estoppel or otherwise; 3819304Speter * 3919304Speter * The above copyright and patent license is granted only if the following 4019304Speter * conditions are met: 4119304Speter * 4219304Speter * 3. Conditions 4319304Speter * 4419304Speter * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4519304Speter * Redistribution of source code of any substantial portion of the Covered 4619304Speter * Code or modification with rights to further distribute source must include 4719304Speter * the above Copyright Notice, the above License, this list of Conditions, 4819304Speter * and the following Disclaimer and Export Compliance provision. In addition, 4919304Speter * Licensee must cause all Covered Code to which Licensee contributes to 5019304Speter * contain a file documenting the changes Licensee made to create that Covered 5119304Speter * Code and the date of any change. Licensee must include in that file the 5219304Speter * documentation of any changes made by any predecessor Licensee. Licensee 5319304Speter * must include a prominent statement that the modification is derived, 5419304Speter * directly or indirectly, from Original Intel Code. 5519304Speter * 5619304Speter * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5719304Speter * Redistribution of source code of any substantial portion of the Covered 58254225Speter * Code or modification without rights to further distribute source must 59254225Speter * include the following Disclaimer and Export Compliance provision in the 6019304Speter * documentation and/or other materials provided with distribution. In 6119304Speter * addition, Licensee may not authorize further sublicense of source of any 6219304Speter * portion of the Covered Code, and must include terms to the effect that the 6319304Speter * license from Licensee to its licensee is limited to the intellectual 6419304Speter * property embodied in the software Licensee provides to its licensee, and 6519304Speter * not to intellectual property embodied in modifications its licensee may 6619304Speter * make. 6719304Speter * 6819304Speter * 3.3. Redistribution of Executable. Redistribution in executable form of any 6919304Speter * substantial portion of the Covered Code or modification must reproduce the 7019304Speter * above Copyright Notice, and the following Disclaimer and Export Compliance 7119304Speter * provision in the documentation and/or other materials provided with the 7219304Speter * distribution. 7319304Speter * 7419304Speter * 3.4. Intel retains all right, title, and interest in and to the Original 7519304Speter * Intel Code. 7619304Speter * 77254225Speter * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7819304Speter * Intel shall be used in advertising or otherwise to promote the sale, use or 7919304Speter * other dealings in products derived from or relating to the Covered Code 8019304Speter * without prior written authorization from Intel. 8119304Speter * 8219304Speter * 4. Disclaimer and Export Compliance 8319304Speter * 84254225Speter * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8519304Speter * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 86254225Speter * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8719304Speter * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8819304Speter * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8919304Speter * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 9019304Speter * PARTICULAR PURPOSE. 9119304Speter * 9219304Speter * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9319304Speter * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 94254225Speter * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9519304Speter * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 96254225Speter * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 97254225Speter * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 98254225Speter * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9919304Speter * LIMITED REMEDY. 10019304Speter * 10119304Speter * 4.3. Licensee shall not export, either directly or indirectly, any of this 10219304Speter * software or system incorporating such software without first obtaining any 10319304Speter * required license or other approval from the U. S. Department of Commerce or 10419304Speter * any other agency or department of the United States Government. In the 10519304Speter * event Licensee exports any such software from the United States or 10619304Speter * re-exports any such software from a foreign destination, Licensee shall 10719304Speter * ensure that the distribution and export/re-export of the software is in 10819304Speter * compliance with all laws, regulations, orders, or other restrictions of the 10919304Speter * U.S. Export Administration Regulations. Licensee agrees that neither it nor 11019304Speter * any of its subsidiaries will export/re-export any technical data, process, 111254225Speter * software, or service, directly or indirectly, to any country for which the 112254225Speter * United States government or any agency thereof requires an export license, 113254225Speter * other governmental approval, or letter of assurance, without first obtaining 114254225Speter * such license, approval or letter. 11519304Speter * 11619304Speter *****************************************************************************/ 11719304Speter 11819304Speter 11919304Speter#include "acpi.h" 12019304Speter#include "acdebug.h" 12119304Speter#include "acnamesp.h" 12219304Speter#include "actables.h" 12319304Speter 12419304Speter#if (defined ENABLE_DEBUGGER || defined ACPI_DISASSEMBLER) 12519304Speter 12619304Speter#define _COMPONENT ACPI_DEBUGGER 12719304Speter ACPI_MODULE_NAME ("dbfileio") 12819304Speter 129254225Speter 13019304Speter/* 13119304Speter * NOTE: this is here for lack of a better place. It is used in all 132254225Speter * flavors of the debugger, need LCD file 13319304Speter */ 134254225Speter#ifdef ACPI_APPLICATION 13519304Speter#include <stdio.h> 13619304SpeterFILE *AcpiGbl_DebugFile = NULL; 13719304Speter#endif 13819304Speter 13919304Speter 14019304SpeterACPI_TABLE_HEADER *AcpiGbl_DbTablePtr = NULL; 14119304Speter 14219304Speter 14319304Speter/******************************************************************************* 14419304Speter * 14519304Speter * FUNCTION: AcpiDbMatchArgument 14619304Speter * 14719304Speter * PARAMETERS: UserArgument - User command line 14819304Speter * Arguments - Array of commands to match against 14919304Speter * 15019304Speter * RETURN: Index into command array or ACPI_TYPE_NOT_FOUND if not found 15119304Speter * 15219304Speter * DESCRIPTION: Search command array for a command match 15319304Speter * 15419304Speter ******************************************************************************/ 15519304Speter 15619304SpeterACPI_OBJECT_TYPE 15719304SpeterAcpiDbMatchArgument ( 15819304Speter NATIVE_CHAR *UserArgument, 15919304Speter ARGUMENT_INFO *Arguments) 16019304Speter{ 16119304Speter UINT32 i; 16219304Speter 16319304Speter 16419304Speter if (!UserArgument || UserArgument[0] == 0) 16519304Speter { 16619304Speter return (ACPI_TYPE_NOT_FOUND); 16719304Speter } 16819304Speter 16919304Speter for (i = 0; Arguments[i].Name; i++) 17019304Speter { 17119304Speter if (ACPI_STRSTR (Arguments[i].Name, UserArgument) == Arguments[i].Name) 17219304Speter { 17319304Speter return (i); 17419304Speter } 17519304Speter } 17619304Speter 17719304Speter /* Argument not recognized */ 17819304Speter 17919304Speter return (ACPI_TYPE_NOT_FOUND); 18019304Speter} 18119304Speter 18219304Speter 18319304Speter#ifdef ENABLE_DEBUGGER 18419304Speter/******************************************************************************* 18519304Speter * 18619304Speter * FUNCTION: AcpiDbCloseDebugFile 18719304Speter * 18819304Speter * PARAMETERS: None 18919304Speter * 19019304Speter * RETURN: Status 19119304Speter * 19219304Speter * DESCRIPTION: If open, close the current debug output file 19319304Speter * 19419304Speter ******************************************************************************/ 19519304Speter 19619304Spetervoid 19719304SpeterAcpiDbCloseDebugFile ( 19819304Speter void) 19919304Speter{ 20019304Speter 20119304Speter#ifdef ACPI_APPLICATION 20219304Speter 20319304Speter if (AcpiGbl_DebugFile) 20419304Speter { 20519304Speter fclose (AcpiGbl_DebugFile); 20619304Speter AcpiGbl_DebugFile = NULL; 20719304Speter AcpiGbl_DbOutputToFile = FALSE; 20819304Speter AcpiOsPrintf ("Debug output file %s closed\n", AcpiGbl_DbDebugFilename); 209254225Speter } 21019304Speter#endif 21119304Speter 212} 213 214 215/******************************************************************************* 216 * 217 * FUNCTION: AcpiDbOpenDebugFile 218 * 219 * PARAMETERS: Name - Filename to open 220 * 221 * RETURN: Status 222 * 223 * DESCRIPTION: Open a file where debug output will be directed. 224 * 225 ******************************************************************************/ 226 227void 228AcpiDbOpenDebugFile ( 229 NATIVE_CHAR *Name) 230{ 231 232#ifdef ACPI_APPLICATION 233 234 AcpiDbCloseDebugFile (); 235 AcpiGbl_DebugFile = fopen (Name, "w+"); 236 if (AcpiGbl_DebugFile) 237 { 238 AcpiOsPrintf ("Debug output file %s opened\n", Name); 239 ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name); 240 AcpiGbl_DbOutputToFile = TRUE; 241 } 242 else 243 { 244 AcpiOsPrintf ("Could not open debug file %s\n", Name); 245 } 246 247#endif 248} 249#endif 250 251 252#ifdef ACPI_APPLICATION 253/******************************************************************************* 254 * 255 * FUNCTION: AcpiDbLoadTable 256 * 257 * PARAMETERS: fp - File that contains table 258 * TablePtr - Return value, buffer with table 259 * TableLenght - Return value, length of table 260 * 261 * RETURN: Status 262 * 263 * DESCRIPTION: Load the DSDT from the file pointer 264 * 265 ******************************************************************************/ 266 267static ACPI_STATUS 268AcpiDbLoadTable( 269 FILE *fp, 270 ACPI_TABLE_HEADER **TablePtr, 271 UINT32 *TableLength) 272{ 273 ACPI_TABLE_HEADER TableHeader; 274 UINT8 *AmlStart; 275 UINT32 AmlLength; 276 UINT32 Actual; 277 ACPI_STATUS Status; 278 279 280 /* Read the table header */ 281 282 if (fread (&TableHeader, 1, sizeof (TableHeader), fp) != sizeof (ACPI_TABLE_HEADER)) 283 { 284 AcpiOsPrintf ("Couldn't read the table header\n"); 285 return (AE_BAD_SIGNATURE); 286 } 287 288 289 /* Validate the table header/length */ 290 291 Status = AcpiTbValidateTableHeader (&TableHeader); 292 if ((ACPI_FAILURE (Status)) || 293 (TableHeader.Length > 0x800000)) /* 8 Mbyte should be enough */ 294 { 295 AcpiOsPrintf ("Table header is invalid!\n"); 296 return (AE_ERROR); 297 } 298 299 300 /* We only support a limited number of table types */ 301 302 if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) && 303 ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) && 304 ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4)) 305 { 306 AcpiOsPrintf ("Table signature is invalid\n"); 307 ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER)); 308 return (AE_ERROR); 309 } 310 311 /* Allocate a buffer for the table */ 312 313 *TableLength = TableHeader.Length; 314 *TablePtr = AcpiOsAllocate ((size_t) *TableLength); 315 if (!*TablePtr) 316 { 317 AcpiOsPrintf ("Could not allocate memory for ACPI table %4.4s (size=%X)\n", 318 TableHeader.Signature, TableHeader.Length); 319 return (AE_NO_MEMORY); 320 } 321 322 323 AmlStart = (UINT8 *) *TablePtr + sizeof (TableHeader); 324 AmlLength = *TableLength - sizeof (TableHeader); 325 326 /* Copy the header to the buffer */ 327 328 ACPI_MEMCPY (*TablePtr, &TableHeader, sizeof (TableHeader)); 329 330 /* Get the rest of the table */ 331 332 Actual = fread (AmlStart, 1, (size_t) AmlLength, fp); 333 if (Actual == AmlLength) 334 { 335 return (AE_OK); 336 } 337 338 if (Actual > 0) 339 { 340 AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n", AmlLength, Actual); 341 return (AE_OK); 342 } 343 344 345 AcpiOsPrintf ("Error - could not read the table file\n"); 346 AcpiOsFree (*TablePtr); 347 *TablePtr = NULL; 348 *TableLength = 0; 349 350 return (AE_ERROR); 351} 352#endif 353 354 355/******************************************************************************* 356 * 357 * FUNCTION: AeLocalLoadTable 358 * 359 * PARAMETERS: TablePtr - pointer to a buffer containing the entire 360 * table to be loaded 361 * 362 * RETURN: Status 363 * 364 * DESCRIPTION: This function is called to load a table from the caller's 365 * buffer. The buffer must contain an entire ACPI Table including 366 * a valid header. The header fields will be verified, and if it 367 * is determined that the table is invalid, the call will fail. 368 * 369 * If the call fails an appropriate status will be returned. 370 * 371 ******************************************************************************/ 372 373ACPI_STATUS 374AeLocalLoadTable ( 375 ACPI_TABLE_HEADER *TablePtr) 376{ 377 ACPI_STATUS Status; 378 ACPI_TABLE_DESC TableInfo; 379 380 381 ACPI_FUNCTION_TRACE ("AeLocalLoadTable"); 382 383 if (!TablePtr) 384 { 385 return_ACPI_STATUS (AE_BAD_PARAMETER); 386 } 387 388 TableInfo.Pointer = TablePtr; 389 Status = AcpiTbRecognizeTable (&TableInfo, ACPI_TABLE_SECONDARY); 390 if (ACPI_FAILURE (Status)) 391 { 392 return_ACPI_STATUS (Status); 393 } 394 395 /* Install the new table into the local data structures */ 396 397 Status = AcpiTbInstallTable (&TableInfo); 398 if (ACPI_FAILURE (Status)) 399 { 400 /* Free table allocated by AcpiTbGetTable */ 401 402 AcpiTbDeleteSingleTable (&TableInfo); 403 return_ACPI_STATUS (Status); 404 } 405 406 407#if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 408 Status = AcpiNsLoadTable (TableInfo.InstalledDesc, AcpiGbl_RootNode); 409 if (ACPI_FAILURE (Status)) 410 { 411 /* Uninstall table and free the buffer */ 412 413 AcpiTbDeleteAcpiTable (ACPI_TABLE_DSDT); 414 return_ACPI_STATUS (Status); 415 } 416#endif 417 418 return_ACPI_STATUS (Status); 419} 420 421 422#ifdef ACPI_APPLICATION 423ACPI_STATUS 424AcpiDbGetAcpiTable ( 425 NATIVE_CHAR *Filename) 426{ 427 FILE *fp; 428 UINT32 TableLength; 429 ACPI_STATUS Status; 430 431 /* Open the file */ 432 433 fp = fopen (Filename, "rb"); 434 if (!fp) 435 { 436 AcpiOsPrintf ("Could not open file %s\n", Filename); 437 return (AE_ERROR); 438 } 439 440 441 /* Get the entire file */ 442 443 fprintf (stderr, "Loading Acpi table from file %s\n", Filename); 444 Status = AcpiDbLoadTable (fp, &AcpiGbl_DbTablePtr, &TableLength); 445 fclose(fp); 446 447 if (ACPI_FAILURE (Status)) 448 { 449 AcpiOsPrintf ("Couldn't get table from the file\n"); 450 return (Status); 451 } 452 453 return (AE_OK); 454 } 455#endif 456 457/******************************************************************************* 458 * 459 * FUNCTION: AcpiDbLoadAcpiTable 460 * 461 * PARAMETERS: Filname - File where table is located 462 * 463 * RETURN: Status 464 * 465 * DESCRIPTION: Load an ACPI table from a file 466 * 467 ******************************************************************************/ 468 469ACPI_STATUS 470AcpiDbLoadAcpiTable ( 471 NATIVE_CHAR *Filename) 472{ 473#ifdef ACPI_APPLICATION 474 ACPI_STATUS Status; 475 476 477 Status = AcpiDbGetAcpiTable (Filename); 478 if (ACPI_FAILURE (Status)) 479 { 480 return (Status); 481 } 482 483 /* Attempt to recognize and install the table */ 484 485 Status = AeLocalLoadTable (AcpiGbl_DbTablePtr); 486 if (ACPI_FAILURE (Status)) 487 { 488 if (Status == AE_ALREADY_EXISTS) 489 { 490 AcpiOsPrintf ("Table %4.4s is already installed\n", 491 AcpiGbl_DbTablePtr->Signature); 492 } 493 else 494 { 495 AcpiOsPrintf ("Could not install table, %s\n", 496 AcpiFormatException (Status)); 497 } 498 499 return (Status); 500 } 501 502 fprintf (stderr, "Acpi table [%4.4s] successfully installed and loaded\n", 503 AcpiGbl_DbTablePtr->Signature); 504 505 AcpiGbl_AcpiHardwarePresent = FALSE; 506 507#endif /* ACPI_APPLICATION */ 508 return (AE_OK); 509} 510 511 512#endif /* ENABLE_DEBUGGER */ 513 514