BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / bus_managers / acpi / acpica / common / adisasm.c
blobdf7000158eb276b43842e104ec7d4bc71cf80955
1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2014, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acparser.h"
120 #include "amlcode.h"
121 #include "acdebug.h"
122 #include "acdisasm.h"
123 #include "acdispat.h"
124 #include "acnamesp.h"
125 #include "actables.h"
126 #include "acapps.h"
128 #include <stdio.h>
129 #include <time.h>
132 #define _COMPONENT ACPI_TOOLS
133 ACPI_MODULE_NAME ("adisasm")
136 * Older versions of Bison won't emit this external in the generated header.
137 * Newer versions do emit the external, so we don't need to do it.
139 #ifndef ASLCOMPILER_ASLCOMPILERPARSE_H
140 extern int AslCompilerdebug;
141 #endif
143 ACPI_STATUS
144 NsDisplayNamespace (
145 void);
147 void
148 NsSetupNamespaceListing (
149 void *Handle);
152 /* Local prototypes */
154 static void
155 AdCreateTableHeader (
156 char *Filename,
157 ACPI_TABLE_HEADER *Table);
159 /* Stubs for ASL compiler */
161 #ifndef ACPI_ASL_COMPILER
162 BOOLEAN
163 AcpiDsIsResultUsed (
164 ACPI_PARSE_OBJECT *Op,
165 ACPI_WALK_STATE *WalkState)
167 return TRUE;
170 ACPI_STATUS
171 AcpiDsMethodError (
172 ACPI_STATUS Status,
173 ACPI_WALK_STATE *WalkState)
175 return (Status);
177 #endif
179 ACPI_STATUS
180 AcpiNsLoadTable (
181 UINT32 TableIndex,
182 ACPI_NAMESPACE_NODE *Node)
184 return (AE_NOT_IMPLEMENTED);
187 ACPI_STATUS
188 AcpiDsRestartControlMethod (
189 ACPI_WALK_STATE *WalkState,
190 ACPI_OPERAND_OBJECT *ReturnDesc)
192 return (AE_OK);
195 void
196 AcpiDsTerminateControlMethod (
197 ACPI_OPERAND_OBJECT *MethodDesc,
198 ACPI_WALK_STATE *WalkState)
200 return;
203 ACPI_STATUS
204 AcpiDsCallControlMethod (
205 ACPI_THREAD_STATE *Thread,
206 ACPI_WALK_STATE *WalkState,
207 ACPI_PARSE_OBJECT *Op)
209 return (AE_OK);
212 ACPI_STATUS
213 AcpiDsMethodDataInitArgs (
214 ACPI_OPERAND_OBJECT **Params,
215 UINT32 MaxParamCount,
216 ACPI_WALK_STATE *WalkState)
218 return (AE_OK);
222 static ACPI_TABLE_DESC LocalTables[1];
223 static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
226 /*******************************************************************************
228 * FUNCTION: AdInitialize
230 * PARAMETERS: None
232 * RETURN: Status
234 * DESCRIPTION: ACPICA and local initialization
236 ******************************************************************************/
238 ACPI_STATUS
239 AdInitialize (
240 void)
242 ACPI_STATUS Status;
245 /* ACPICA subsystem initialization */
247 Status = AcpiOsInitialize ();
248 if (ACPI_FAILURE (Status))
250 return (Status);
253 Status = AcpiUtInitGlobals ();
254 if (ACPI_FAILURE (Status))
256 return (Status);
259 Status = AcpiUtMutexInitialize ();
260 if (ACPI_FAILURE (Status))
262 return (Status);
265 Status = AcpiNsRootInitialize ();
266 if (ACPI_FAILURE (Status))
268 return (Status);
271 /* Setup the Table Manager (cheat - there is no RSDT) */
273 AcpiGbl_RootTableList.MaxTableCount = 1;
274 AcpiGbl_RootTableList.CurrentTableCount = 0;
275 AcpiGbl_RootTableList.Tables = LocalTables;
277 return (Status);
281 /******************************************************************************
283 * FUNCTION: AdAmlDisassemble
285 * PARAMETERS: Filename - AML input filename
286 * OutToFile - TRUE if output should go to a file
287 * Prefix - Path prefix for output
288 * OutFilename - where the filename is returned
290 * RETURN: Status
292 * DESCRIPTION: Disassemble an entire ACPI table
294 *****************************************************************************/
296 ACPI_STATUS
297 AdAmlDisassemble (
298 BOOLEAN OutToFile,
299 char *Filename,
300 char *Prefix,
301 char **OutFilename)
303 ACPI_STATUS Status;
304 char *DisasmFilename = NULL;
305 char *ExternalFilename;
306 ACPI_EXTERNAL_FILE *ExternalFileList = AcpiGbl_ExternalFileList;
307 FILE *File = NULL;
308 ACPI_TABLE_HEADER *Table = NULL;
309 ACPI_TABLE_HEADER *ExternalTable;
310 ACPI_OWNER_ID OwnerId;
314 * Input: AML code from either a file or via GetTables (memory or
315 * registry)
317 if (Filename)
319 Status = AcpiDbGetTableFromFile (Filename, &Table);
320 if (ACPI_FAILURE (Status))
322 return (Status);
326 * External filenames separated by commas
327 * Example: iasl -e file1,file2,file3 -d xxx.aml
329 while (ExternalFileList)
331 ExternalFilename = ExternalFileList->Path;
332 if (!ACPI_STRCMP (ExternalFilename, Filename))
334 /* Next external file */
336 ExternalFileList = ExternalFileList->Next;
337 continue;
340 Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
341 if (ACPI_FAILURE (Status))
343 return (Status);
346 /* Load external table for symbol resolution */
348 if (ExternalTable)
350 Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
351 if (ACPI_FAILURE (Status))
353 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
354 AcpiFormatException (Status));
355 return (Status);
359 * Load namespace from names created within control methods
360 * Set owner id of nodes in external table
362 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
363 AcpiGbl_RootNode, OwnerId);
364 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
367 /* Next external file */
369 ExternalFileList = ExternalFileList->Next;
372 /* Clear external list generated by Scope in external tables */
374 if (AcpiGbl_ExternalFileList)
376 AcpiDmClearExternalList ();
379 /* Load any externals defined in the optional external ref file */
381 AcpiDmGetExternalsFromFile ();
383 else
385 Status = AdGetLocalTables ();
386 if (ACPI_FAILURE (Status))
388 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
389 AcpiFormatException (Status));
390 return (Status);
393 if (!AcpiGbl_DbOpt_disasm)
395 return (AE_OK);
398 /* Obtained the local tables, just disassemble the DSDT */
400 Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
401 if (ACPI_FAILURE (Status))
403 AcpiOsPrintf ("Could not get DSDT, %s\n",
404 AcpiFormatException (Status));
405 return (Status);
408 AcpiOsPrintf ("\nDisassembly of DSDT\n");
409 Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
413 * Output: ASL code. Redirect to a file if requested
415 if (OutToFile)
417 /* Create/Open a disassembly output file */
419 DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
420 if (!DisasmFilename)
422 fprintf (stderr, "Could not generate output filename\n");
423 Status = AE_ERROR;
424 goto Cleanup;
427 File = fopen (DisasmFilename, "w+");
428 if (!File)
430 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
431 Status = AE_ERROR;
432 ACPI_FREE (DisasmFilename);
433 goto Cleanup;
436 AcpiOsRedirectOutput (File);
439 *OutFilename = DisasmFilename;
441 if (!AcpiUtIsAmlTable (Table))
443 AdDisassemblerHeader (Filename);
444 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
445 Table->Signature);
446 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] "
447 "FieldName : FieldValue\n */\n\n");
449 AcpiDmDumpDataTable (Table);
450 fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
451 Table->Signature);
452 fprintf (stderr, "Formatted output: %s - %u bytes\n",
453 DisasmFilename, CmGetFileSize (File));
455 else
457 /* Always parse the tables, only option is what to display */
459 Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
460 if (ACPI_FAILURE (Status))
462 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
463 AcpiFormatException (Status));
464 goto Cleanup;
467 if (AslCompilerdebug)
469 AcpiOsPrintf ("/**** Before second load\n");
471 NsSetupNamespaceListing (File);
472 NsDisplayNamespace ();
473 AcpiOsPrintf ("*****/\n");
476 /* Load namespace from names created within control methods */
478 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
479 AcpiGbl_RootNode, OwnerId);
482 * Cross reference the namespace here, in order to
483 * generate External() statements
485 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
486 AcpiGbl_RootNode, OwnerId);
488 if (AslCompilerdebug)
490 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
493 /* Find possible calls to external control methods */
495 AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
498 * If we found any external control methods, we must reparse
499 * the entire tree with the new information (namely, the
500 * number of arguments per method)
502 if (AcpiDmGetExternalMethodCount ())
504 fprintf (stderr,
505 "\nFound %u external control methods, "
506 "reparsing with new information\n",
507 AcpiDmGetExternalMethodCount ());
509 /* Reparse, rebuild namespace */
511 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
512 AcpiGbl_ParseOpRoot = NULL;
513 AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
515 AcpiGbl_RootNode = NULL;
516 AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
517 AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
518 AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;
519 AcpiGbl_RootNodeStruct.Parent = NULL;
520 AcpiGbl_RootNodeStruct.Child = NULL;
521 AcpiGbl_RootNodeStruct.Peer = NULL;
522 AcpiGbl_RootNodeStruct.Object = NULL;
523 AcpiGbl_RootNodeStruct.Flags = 0;
525 Status = AcpiNsRootInitialize ();
527 /* New namespace, add the external definitions first */
529 AcpiDmAddExternalsToNamespace ();
531 /* Parse the table again. No need to reload it, however */
533 Status = AdParseTable (Table, NULL, FALSE, FALSE);
534 if (ACPI_FAILURE (Status))
536 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
537 AcpiFormatException (Status));
538 goto Cleanup;
541 /* Cross reference the namespace again */
543 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
544 AcpiGbl_RootNode, OwnerId);
546 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
547 AcpiGbl_RootNode, OwnerId);
549 if (AslCompilerdebug)
551 AcpiOsPrintf ("/**** After second load and resource conversion\n");
552 NsSetupNamespaceListing (File);
553 NsDisplayNamespace ();
554 AcpiOsPrintf ("*****/\n");
556 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
561 * Now that the namespace is finalized, we can perform namespace
562 * transforms.
564 * 1) Convert fixed-offset references to resource descriptors
565 * to symbolic references (Note: modifies namespace)
567 AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
569 /* Optional displays */
571 if (AcpiGbl_DbOpt_disasm)
573 /* This is the real disassembly */
575 AdDisplayTables (Filename, Table);
577 /* Dump hex table if requested (-vt) */
579 AcpiDmDumpDataTable (Table);
581 fprintf (stderr, "Disassembly completed\n");
582 fprintf (stderr, "ASL Output: %s - %u bytes\n",
583 DisasmFilename, CmGetFileSize (File));
587 Cleanup:
589 if (Table && !AcpiUtIsAmlTable (Table))
591 ACPI_FREE (Table);
594 if (OutToFile && File)
596 if (AslCompilerdebug) /* Display final namespace, with transforms */
598 NsSetupNamespaceListing (File);
599 NsDisplayNamespace ();
602 fclose (File);
603 AcpiOsRedirectOutput (stdout);
606 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
607 AcpiGbl_ParseOpRoot = NULL;
608 return (Status);
612 /******************************************************************************
614 * FUNCTION: AdDisassemblerHeader
616 * PARAMETERS: Filename - Input file for the table
618 * RETURN: None
620 * DESCRIPTION: Create the disassembler header, including ACPICA signon with
621 * current time and date.
623 *****************************************************************************/
625 void
626 AdDisassemblerHeader (
627 char *Filename)
629 time_t Timer;
631 time (&Timer);
633 /* Header and input table info */
635 AcpiOsPrintf ("/*\n");
636 AcpiOsPrintf (ACPI_COMMON_HEADER ("AML Disassembler", " * "));
638 AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
639 AcpiOsPrintf (" *\n");
643 /******************************************************************************
645 * FUNCTION: AdCreateTableHeader
647 * PARAMETERS: Filename - Input file for the table
648 * Table - Pointer to the raw table
650 * RETURN: None
652 * DESCRIPTION: Create the ASL table header, including ACPICA signon with
653 * current time and date.
655 *****************************************************************************/
657 static void
658 AdCreateTableHeader (
659 char *Filename,
660 ACPI_TABLE_HEADER *Table)
662 char *NewFilename;
663 UINT8 Checksum;
667 * Print file header and dump original table header
669 AdDisassemblerHeader (Filename);
671 AcpiOsPrintf (" * Original Table Header:\n");
672 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
673 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
675 /* Print and validate the revision */
677 AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
679 switch (Table->Revision)
681 case 0:
683 AcpiOsPrintf (" **** Invalid Revision");
684 break;
686 case 1:
688 /* Revision of DSDT controls the ACPI integer width */
690 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
692 AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
694 break;
696 default:
698 break;
700 AcpiOsPrintf ("\n");
702 /* Print and validate the table checksum */
704 AcpiOsPrintf (" * Checksum 0x%2.2X", Table->Checksum);
706 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
707 if (Checksum)
709 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
710 (UINT8) (Table->Checksum - Checksum));
712 AcpiOsPrintf ("\n");
714 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
715 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
716 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
717 AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
718 AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
719 AcpiOsPrintf (" */\n");
721 /* Create AML output filename based on input filename */
723 if (Filename)
725 NewFilename = FlGenerateFilename (Filename, "aml");
727 else
729 NewFilename = ACPI_ALLOCATE_ZEROED (9);
730 if (NewFilename)
732 strncat (NewFilename, Table->Signature, 4);
733 strcat (NewFilename, ".aml");
737 if (!NewFilename)
739 AcpiOsPrintf (" **** Could not generate AML output filename\n");
740 return;
743 /* Open the ASL definition block */
745 AcpiOsPrintf (
746 "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
747 NewFilename, Table->Signature, Table->Revision,
748 Table->OemId, Table->OemTableId, Table->OemRevision);
750 ACPI_FREE (NewFilename);
754 /******************************************************************************
756 * FUNCTION: AdDisplayTables
758 * PARAMETERS: Filename - Input file for the table
759 * Table - Pointer to the raw table
761 * RETURN: Status
763 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
765 *****************************************************************************/
767 ACPI_STATUS
768 AdDisplayTables (
769 char *Filename,
770 ACPI_TABLE_HEADER *Table)
774 if (!AcpiGbl_ParseOpRoot)
776 return (AE_NOT_EXIST);
779 if (!AcpiGbl_DbOpt_verbose)
781 AdCreateTableHeader (Filename, Table);
784 AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
786 if (AcpiGbl_DbOpt_verbose)
788 AcpiOsPrintf ("\n\nTable Header:\n");
789 AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
790 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
792 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
793 AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
794 Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
797 return (AE_OK);
801 /******************************************************************************
803 * FUNCTION: AdGetLocalTables
805 * PARAMETERS: None
807 * RETURN: Status
809 * DESCRIPTION: Get the ACPI tables from either memory or a file
811 *****************************************************************************/
813 ACPI_STATUS
814 AdGetLocalTables (
815 void)
817 ACPI_STATUS Status;
818 ACPI_TABLE_HEADER TableHeader;
819 ACPI_TABLE_HEADER *NewTable;
820 UINT32 TableIndex;
823 /* Get the DSDT via table override */
825 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
826 AcpiOsTableOverride (&TableHeader, &NewTable);
827 if (!NewTable)
829 fprintf (stderr, "Could not obtain DSDT\n");
830 return (AE_NO_ACPI_TABLES);
833 AdWriteTable (NewTable, NewTable->Length,
834 ACPI_SIG_DSDT, NewTable->OemTableId);
836 /* Store DSDT in the Table Manager */
838 Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
839 0, &TableIndex);
840 if (ACPI_FAILURE (Status))
842 fprintf (stderr, "Could not store DSDT\n");
843 return (AE_NO_ACPI_TABLES);
846 return (AE_OK);
850 /******************************************************************************
852 * FUNCTION: AdParseTable
854 * PARAMETERS: Table - Pointer to the raw table
855 * OwnerId - Returned OwnerId of the table
856 * LoadTable - If add table to the global table list
857 * External - If this is an external table
859 * RETURN: Status
861 * DESCRIPTION: Parse the DSDT.
863 *****************************************************************************/
865 ACPI_STATUS
866 AdParseTable (
867 ACPI_TABLE_HEADER *Table,
868 ACPI_OWNER_ID *OwnerId,
869 BOOLEAN LoadTable,
870 BOOLEAN External)
872 ACPI_STATUS Status = AE_OK;
873 ACPI_WALK_STATE *WalkState;
874 UINT8 *AmlStart;
875 UINT32 AmlLength;
876 UINT32 TableIndex;
879 if (!Table)
881 return (AE_NOT_EXIST);
884 /* Pass 1: Parse everything except control method bodies */
886 fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
888 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
889 AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
891 /* Create the root object */
893 AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
894 if (!AcpiGbl_ParseOpRoot)
896 return (AE_NO_MEMORY);
899 /* Create and initialize a new walk state */
901 WalkState = AcpiDsCreateWalkState (0,
902 AcpiGbl_ParseOpRoot, NULL, NULL);
903 if (!WalkState)
905 return (AE_NO_MEMORY);
908 Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
909 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
910 if (ACPI_FAILURE (Status))
912 return (Status);
915 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
916 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
918 Status = AcpiPsParseAml (WalkState);
919 if (ACPI_FAILURE (Status))
921 return (Status);
924 /* If LoadTable is FALSE, we are parsing the last loaded table */
926 TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
928 /* Pass 2 */
930 if (LoadTable)
932 Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
933 Table->Length, ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL,
934 &TableIndex);
935 if (ACPI_FAILURE (Status))
937 return (Status);
939 Status = AcpiTbAllocateOwnerId (TableIndex);
940 if (ACPI_FAILURE (Status))
942 return (Status);
944 if (OwnerId)
946 Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
947 if (ACPI_FAILURE (Status))
949 return (Status);
954 fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
956 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
957 if (ACPI_FAILURE (Status))
959 return (Status);
962 /* No need to parse control methods of external table */
964 if (External)
966 return (AE_OK);
970 * Pass 3: Parse control methods and link their parse trees
971 * into the main parse tree
973 fprintf (stderr,
974 "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
975 Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
976 fprintf (stderr, "\n");
978 /* Process Resource Templates */
980 AcpiDmFindResources (AcpiGbl_ParseOpRoot);
982 fprintf (stderr, "Parsing completed\n");
983 return (AE_OK);