1 /*******************************************************************************
2 *
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)
5 *
6 ******************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acdebug.h"
49
50 #ifdef ACPI_APPLICATION
51 #include "actables.h"
52 #endif
53
54 #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
55
56 #define _COMPONENT ACPI_CA_DEBUGGER
57 ACPI_MODULE_NAME ("dbfileio")
58
59 /*
60 * NOTE: this is here for lack of a better place. It is used in all
61 * flavors of the debugger, need LCD file
62 */
63 #ifdef ACPI_APPLICATION
64 #include <stdio.h>
65 FILE *AcpiGbl_DebugFile = NULL;
66 #endif
67
68
69 #ifdef ACPI_DEBUGGER
70
71 /* Local prototypes */
72
73 #ifdef ACPI_APPLICATION
74
75 static ACPI_STATUS
76 AcpiDbCheckTextModeCorruption (
77 UINT8 *Table,
78 UINT32 TableLength,
79 UINT32 FileLength);
80
81 #endif
82
83 /*******************************************************************************
84 *
85 * FUNCTION: AcpiDbCloseDebugFile
86 *
87 * PARAMETERS: None
88 *
114 *
115 * FUNCTION: AcpiDbOpenDebugFile
116 *
117 * PARAMETERS: Name - Filename to open
118 *
119 * RETURN: None
120 *
121 * DESCRIPTION: Open a file where debug output will be directed.
122 *
123 ******************************************************************************/
124
125 void
126 AcpiDbOpenDebugFile (
127 char *Name)
128 {
129
130 #ifdef ACPI_APPLICATION
131
132 AcpiDbCloseDebugFile ();
133 AcpiGbl_DebugFile = fopen (Name, "w+");
134 if (AcpiGbl_DebugFile)
135 {
136 AcpiOsPrintf ("Debug output file %s opened\n", Name);
137 ACPI_STRCPY (AcpiGbl_DbDebugFilename, Name);
138 AcpiGbl_DbOutputToFile = TRUE;
139 }
140 else
141 {
142 AcpiOsPrintf ("Could not open debug file %s\n", Name);
143 }
144
145 #endif
146 }
147 #endif
148
149
150 #ifdef ACPI_APPLICATION
151 /*******************************************************************************
152 *
153 * FUNCTION: AcpiDbCheckTextModeCorruption
154 *
155 * PARAMETERS: Table - Table buffer
156 * TableLength - Length of table from the table header
157 * FileLength - Length of the file that contains the table
158 *
159 * RETURN: Status
160 *
161 * DESCRIPTION: Check table for text mode file corruption where all linefeed
162 * characters (LF) have been replaced by carriage return linefeed
163 * pairs (CR/LF).
164 *
254
255 fseek (fp, 0, SEEK_END);
256 FileSize = (UINT32) ftell (fp);
257 fseek (fp, 0, SEEK_SET);
258
259 if (FileSize < 4)
260 {
261 return (AE_BAD_HEADER);
262 }
263
264 /* Read the signature */
265
266 if (fread (&TableHeader, 1, 4, fp) != 4)
267 {
268 AcpiOsPrintf ("Could not read the table signature\n");
269 return (AE_BAD_HEADER);
270 }
271
272 fseek (fp, 0, SEEK_SET);
273
274 /* The RSDT and FACS tables do not have standard ACPI headers */
275
276 if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD ") ||
277 ACPI_COMPARE_NAME (TableHeader.Signature, "FACS"))
278 {
279 *TableLength = FileSize;
280 StandardHeader = FALSE;
281 }
282 else
283 {
284 /* Read the table header */
285
286 if (fread (&TableHeader, 1, sizeof (TableHeader), fp) !=
287 sizeof (ACPI_TABLE_HEADER))
288 {
289 AcpiOsPrintf ("Could not read the table header\n");
290 return (AE_BAD_HEADER);
291 }
292
293 #if 0
294 /* Validate the table header/length */
295
296 Status = AcpiTbValidateTableHeader (&TableHeader);
297 if (ACPI_FAILURE (Status))
298 {
299 AcpiOsPrintf ("Table header is invalid!\n");
300 return (Status);
301 }
302 #endif
303
304 /* File size must be at least as long as the Header-specified length */
305
306 if (TableHeader.Length > FileSize)
307 {
308 AcpiOsPrintf (
309 "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
310 TableHeader.Length, FileSize);
311 return (AE_BAD_HEADER);
312 }
313
314 #ifdef ACPI_OBSOLETE_CODE
315 /* We only support a limited number of table types */
316
317 if (ACPI_STRNCMP ((char *) TableHeader.Signature, DSDT_SIG, 4) &&
318 ACPI_STRNCMP ((char *) TableHeader.Signature, PSDT_SIG, 4) &&
319 ACPI_STRNCMP ((char *) TableHeader.Signature, SSDT_SIG, 4))
320 {
321 AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
322 (char *) TableHeader.Signature);
323 ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
324 return (AE_ERROR);
325 }
326 #endif
327
328 *TableLength = TableHeader.Length;
329 }
330
331 /* Allocate a buffer for the table */
332
333 *Table = AcpiOsAllocate ((size_t) FileSize);
334 if (!*Table)
335 {
336 AcpiOsPrintf (
337 "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
338 TableHeader.Signature, *TableLength);
339 return (AE_NO_MEMORY);
356 {
357 Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
358 FileSize, (*Table)->Length);
359 return (Status);
360 }
361 }
362 return (AE_OK);
363 }
364
365 if (Actual > 0)
366 {
367 AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
368 FileSize, Actual);
369 return (AE_OK);
370 }
371
372 AcpiOsPrintf ("Error - could not read the table file\n");
373 AcpiOsFree (*Table);
374 *Table = NULL;
375 *TableLength = 0;
376
377 return (AE_ERROR);
378 }
379
380
381 /*******************************************************************************
382 *
383 * FUNCTION: AeLocalLoadTable
384 *
385 * PARAMETERS: Table - pointer to a buffer containing the entire
386 * table to be loaded
387 *
388 * RETURN: Status
389 *
390 * DESCRIPTION: This function is called to load a table from the caller's
391 * buffer. The buffer must contain an entire ACPI Table including
392 * a valid header. The header fields will be verified, and if it
393 * is determined that the table is invalid, the call will fail.
394 *
395 ******************************************************************************/
396
454
455
456 /*******************************************************************************
457 *
458 * FUNCTION: AcpiDbReadTableFromFile
459 *
460 * PARAMETERS: Filename - File where table is located
461 * Table - Where a pointer to the table is returned
462 *
463 * RETURN: Status
464 *
465 * DESCRIPTION: Get an ACPI table from a file
466 *
467 ******************************************************************************/
468
469 ACPI_STATUS
470 AcpiDbReadTableFromFile (
471 char *Filename,
472 ACPI_TABLE_HEADER **Table)
473 {
474 FILE *fp;
475 UINT32 TableLength;
476 ACPI_STATUS Status;
477
478
479 /* Open the file */
480
481 fp = fopen (Filename, "rb");
482 if (!fp)
483 {
484 AcpiOsPrintf ("Could not open input file %s\n", Filename);
485 return (AE_ERROR);
486 }
487
488 /* Get the entire file */
489
490 fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
491 Status = AcpiDbReadTable (fp, Table, &TableLength);
492 fclose(fp);
493
494 if (ACPI_FAILURE (Status))
495 {
496 AcpiOsPrintf ("Could not get table from the file\n");
497 return (Status);
498 }
499
500 return (AE_OK);
501 }
502 #endif
503
504
505 /*******************************************************************************
506 *
507 * FUNCTION: AcpiDbGetTableFromFile
508 *
509 * PARAMETERS: Filename - File where table is located
510 * ReturnTable - Where a pointer to the table is returned
511 *
512 * RETURN: Status
557 return (Status);
558 }
559
560 fprintf (stderr,
561 "Acpi table [%4.4s] successfully installed and loaded\n",
562 Table->Signature);
563 }
564
565 AcpiGbl_AcpiHardwarePresent = FALSE;
566 if (ReturnTable)
567 {
568 *ReturnTable = Table;
569 }
570
571
572 #endif /* ACPI_APPLICATION */
573 return (AE_OK);
574 }
575
576 #endif /* ACPI_DEBUGGER */
577
|
1 /*******************************************************************************
2 *
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)
5 *
6 ******************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2013, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
45
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acdebug.h"
49
50 #ifdef ACPI_APPLICATION
51 #include "actables.h"
52 #endif
53
54 #ifdef ACPI_ASL_COMPILER
55 #include "aslcompiler.h"
56 #endif
57
58 #if (defined ACPI_DEBUGGER || defined ACPI_DISASSEMBLER)
59
60 #define _COMPONENT ACPI_CA_DEBUGGER
61 ACPI_MODULE_NAME ("dbfileio")
62
63 #ifdef ACPI_DEBUGGER
64
65 /* Local prototypes */
66
67 #ifdef ACPI_APPLICATION
68
69 static ACPI_STATUS
70 AcpiDbCheckTextModeCorruption (
71 UINT8 *Table,
72 UINT32 TableLength,
73 UINT32 FileLength);
74
75 #endif
76
77 /*******************************************************************************
78 *
79 * FUNCTION: AcpiDbCloseDebugFile
80 *
81 * PARAMETERS: None
82 *
108 *
109 * FUNCTION: AcpiDbOpenDebugFile
110 *
111 * PARAMETERS: Name - Filename to open
112 *
113 * RETURN: None
114 *
115 * DESCRIPTION: Open a file where debug output will be directed.
116 *
117 ******************************************************************************/
118
119 void
120 AcpiDbOpenDebugFile (
121 char *Name)
122 {
123
124 #ifdef ACPI_APPLICATION
125
126 AcpiDbCloseDebugFile ();
127 AcpiGbl_DebugFile = fopen (Name, "w+");
128 if (!AcpiGbl_DebugFile)
129 {
130 AcpiOsPrintf ("Could not open debug file %s\n", Name);
131 return;
132 }
133
134 AcpiOsPrintf ("Debug output file %s opened\n", Name);
135 ACPI_STRNCPY (AcpiGbl_DbDebugFilename, Name,
136 sizeof (AcpiGbl_DbDebugFilename));
137 AcpiGbl_DbOutputToFile = TRUE;
138
139 #endif
140 }
141 #endif
142
143
144 #ifdef ACPI_APPLICATION
145 /*******************************************************************************
146 *
147 * FUNCTION: AcpiDbCheckTextModeCorruption
148 *
149 * PARAMETERS: Table - Table buffer
150 * TableLength - Length of table from the table header
151 * FileLength - Length of the file that contains the table
152 *
153 * RETURN: Status
154 *
155 * DESCRIPTION: Check table for text mode file corruption where all linefeed
156 * characters (LF) have been replaced by carriage return linefeed
157 * pairs (CR/LF).
158 *
248
249 fseek (fp, 0, SEEK_END);
250 FileSize = (UINT32) ftell (fp);
251 fseek (fp, 0, SEEK_SET);
252
253 if (FileSize < 4)
254 {
255 return (AE_BAD_HEADER);
256 }
257
258 /* Read the signature */
259
260 if (fread (&TableHeader, 1, 4, fp) != 4)
261 {
262 AcpiOsPrintf ("Could not read the table signature\n");
263 return (AE_BAD_HEADER);
264 }
265
266 fseek (fp, 0, SEEK_SET);
267
268 /* The RSDP table does not have standard ACPI header */
269
270 if (ACPI_COMPARE_NAME (TableHeader.Signature, "RSD "))
271 {
272 *TableLength = FileSize;
273 StandardHeader = FALSE;
274 }
275 else
276 {
277 /* Read the table header */
278
279 if (fread (&TableHeader, 1, sizeof (ACPI_TABLE_HEADER), fp) !=
280 sizeof (ACPI_TABLE_HEADER))
281 {
282 AcpiOsPrintf ("Could not read the table header\n");
283 return (AE_BAD_HEADER);
284 }
285
286 #if 0
287 /* Validate the table header/length */
288
289 Status = AcpiTbValidateTableHeader (&TableHeader);
290 if (ACPI_FAILURE (Status))
291 {
292 AcpiOsPrintf ("Table header is invalid!\n");
293 return (Status);
294 }
295 #endif
296
297 /* File size must be at least as long as the Header-specified length */
298
299 if (TableHeader.Length > FileSize)
300 {
301 AcpiOsPrintf (
302 "TableHeader length [0x%X] greater than the input file size [0x%X]\n",
303 TableHeader.Length, FileSize);
304
305 #ifdef ACPI_ASL_COMPILER
306 Status = FlCheckForAscii (fp, NULL, FALSE);
307 if (ACPI_SUCCESS (Status))
308 {
309 AcpiOsPrintf ("File appears to be ASCII only, must be binary\n",
310 TableHeader.Length, FileSize);
311 }
312 #endif
313 return (AE_BAD_HEADER);
314 }
315
316 #ifdef ACPI_OBSOLETE_CODE
317 /* We only support a limited number of table types */
318
319 if (!ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_DSDT) &&
320 !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_PSDT) &&
321 !ACPI_COMPARE_NAME ((char *) TableHeader.Signature, ACPI_SIG_SSDT))
322 {
323 AcpiOsPrintf ("Table signature [%4.4s] is invalid or not supported\n",
324 (char *) TableHeader.Signature);
325 ACPI_DUMP_BUFFER (&TableHeader, sizeof (ACPI_TABLE_HEADER));
326 return (AE_ERROR);
327 }
328 #endif
329
330 *TableLength = TableHeader.Length;
331 }
332
333 /* Allocate a buffer for the table */
334
335 *Table = AcpiOsAllocate ((size_t) FileSize);
336 if (!*Table)
337 {
338 AcpiOsPrintf (
339 "Could not allocate memory for ACPI table %4.4s (size=0x%X)\n",
340 TableHeader.Signature, *TableLength);
341 return (AE_NO_MEMORY);
358 {
359 Status = AcpiDbCheckTextModeCorruption ((UINT8 *) *Table,
360 FileSize, (*Table)->Length);
361 return (Status);
362 }
363 }
364 return (AE_OK);
365 }
366
367 if (Actual > 0)
368 {
369 AcpiOsPrintf ("Warning - reading table, asked for %X got %X\n",
370 FileSize, Actual);
371 return (AE_OK);
372 }
373
374 AcpiOsPrintf ("Error - could not read the table file\n");
375 AcpiOsFree (*Table);
376 *Table = NULL;
377 *TableLength = 0;
378 return (AE_ERROR);
379 }
380
381
382 /*******************************************************************************
383 *
384 * FUNCTION: AeLocalLoadTable
385 *
386 * PARAMETERS: Table - pointer to a buffer containing the entire
387 * table to be loaded
388 *
389 * RETURN: Status
390 *
391 * DESCRIPTION: This function is called to load a table from the caller's
392 * buffer. The buffer must contain an entire ACPI Table including
393 * a valid header. The header fields will be verified, and if it
394 * is determined that the table is invalid, the call will fail.
395 *
396 ******************************************************************************/
397
455
456
457 /*******************************************************************************
458 *
459 * FUNCTION: AcpiDbReadTableFromFile
460 *
461 * PARAMETERS: Filename - File where table is located
462 * Table - Where a pointer to the table is returned
463 *
464 * RETURN: Status
465 *
466 * DESCRIPTION: Get an ACPI table from a file
467 *
468 ******************************************************************************/
469
470 ACPI_STATUS
471 AcpiDbReadTableFromFile (
472 char *Filename,
473 ACPI_TABLE_HEADER **Table)
474 {
475 FILE *File;
476 UINT32 TableLength;
477 ACPI_STATUS Status;
478
479
480 /* Open the file */
481
482 File = fopen (Filename, "rb");
483 if (!File)
484 {
485 perror ("Could not open input file");
486 return (AE_ERROR);
487 }
488
489 /* Get the entire file */
490
491 fprintf (stderr, "Loading Acpi table from file %s\n", Filename);
492 Status = AcpiDbReadTable (File, Table, &TableLength);
493 fclose(File);
494
495 if (ACPI_FAILURE (Status))
496 {
497 AcpiOsPrintf ("Could not get table from the file\n");
498 return (Status);
499 }
500
501 return (AE_OK);
502 }
503 #endif
504
505
506 /*******************************************************************************
507 *
508 * FUNCTION: AcpiDbGetTableFromFile
509 *
510 * PARAMETERS: Filename - File where table is located
511 * ReturnTable - Where a pointer to the table is returned
512 *
513 * RETURN: Status
558 return (Status);
559 }
560
561 fprintf (stderr,
562 "Acpi table [%4.4s] successfully installed and loaded\n",
563 Table->Signature);
564 }
565
566 AcpiGbl_AcpiHardwarePresent = FALSE;
567 if (ReturnTable)
568 {
569 *ReturnTable = Table;
570 }
571
572
573 #endif /* ACPI_APPLICATION */
574 return (AE_OK);
575 }
576
577 #endif /* ACPI_DEBUGGER */
|