1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
119 #include "acparser.h"
122 #include "acdisasm.h"
123 #include "acdispat.h"
124 #include "acnamesp.h"
125 #include "actables.h"
132 #define _COMPONENT ACPI_TOOLS
133 ACPI_MODULE_NAME ("adisasm")
135 extern int AslCompilerdebug;
142 LsSetupNsList (void * Handle);
145 /* Local prototypes */
148 AdCreateTableHeader (
150 ACPI_TABLE_HEADER *Table);
153 AdDisassemblerHeader (
156 ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
159 /* Stubs for ASL compiler */
161 #ifndef ACPI_ASL_COMPILER
164 ACPI_PARSE_OBJECT *Op,
165 ACPI_WALK_STATE *WalkState)
173 ACPI_WALK_STATE *WalkState)
182 ACPI_NATIVE_UINT TableIndex,
183 ACPI_NAMESPACE_NODE *Node)
185 return (AE_NOT_IMPLEMENTED);
189 AcpiDsRestartControlMethod (
190 ACPI_WALK_STATE *WalkState,
191 ACPI_OPERAND_OBJECT *ReturnDesc)
197 AcpiDsTerminateControlMethod (
198 ACPI_OPERAND_OBJECT *MethodDesc,
199 ACPI_WALK_STATE *WalkState)
205 AcpiDsCallControlMethod (
206 ACPI_THREAD_STATE *Thread,
207 ACPI_WALK_STATE *WalkState,
208 ACPI_PARSE_OBJECT *Op)
214 AcpiDsMethodDataInitArgs (
215 ACPI_OPERAND_OBJECT **Params,
216 UINT32 MaxParamCount,
217 ACPI_WALK_STATE *WalkState)
223 ACPI_TABLE_DESC LocalTables[1];
226 /*******************************************************************************
228 * FUNCTION: AdInitialize
234 * DESCRIPTION: CA initialization
236 ******************************************************************************/
245 /* ACPI CA subsystem initialization */
247 Status = AcpiOsInitialize ();
248 AcpiUtInitGlobals ();
250 Status = AcpiUtMutexInitialize ();
251 if (ACPI_FAILURE (Status))
256 Status = AcpiNsRootInitialize ();
257 if (ACPI_FAILURE (Status))
262 /* Setup the Table Manager (cheat - there is no RSDT) */
264 AcpiGbl_RootTableList.Size = 1;
265 AcpiGbl_RootTableList.Count = 0;
266 AcpiGbl_RootTableList.Tables = LocalTables;
272 /*******************************************************************************
274 * FUNCTION: AdAddExternalsToNamespace
282 ******************************************************************************/
285 AdAddExternalsToNamespace (
289 ACPI_NAMESPACE_NODE *Node;
290 ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
291 ACPI_OPERAND_OBJECT *MethodDesc;
296 Status = AcpiNsLookup (NULL, External->InternalPath, External->Type,
297 ACPI_IMODE_LOAD_PASS1, ACPI_NS_EXTERNAL | ACPI_NS_DONT_OPEN_SCOPE,
300 if (External->Type == ACPI_TYPE_METHOD)
302 MethodDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
303 MethodDesc->Method.ParamCount = (UINT8) External->Value;
304 Node->Object = MethodDesc;
307 External = External->Next;
312 /*******************************************************************************
314 * FUNCTION: AdMethodExternalCount
320 * DESCRIPTION: Return the number of externals that have been generated
322 ******************************************************************************/
325 AdMethodExternalCount (
328 ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
334 if (External->Type == ACPI_TYPE_METHOD)
339 External = External->Next;
346 /******************************************************************************
348 * FUNCTION: AdAmlDisassemble
350 * PARAMETERS: Filename - AML input filename
351 * OutToFile - TRUE if output should go to a file
352 * Prefix - Path prefix for output
353 * OutFilename - where the filename is returned
354 * GetAllTables - TRUE if all tables are desired
358 * DESCRIPTION: Disassemble an entire ACPI table
360 *****************************************************************************/
362 extern char *Gbl_ExternalFilename;
370 BOOLEAN GetAllTables)
373 char *DisasmFilename = NULL;
375 ACPI_TABLE_HEADER *Table;
376 ACPI_TABLE_HEADER *ExternalTable;
380 * Input: AML Code from either a file,
381 * or via GetTables (memory or registry)
385 Status = AcpiDbGetTableFromFile (Filename, &Table);
386 if (ACPI_FAILURE (Status))
391 if (Gbl_ExternalFilename)
393 Status = AcpiDbGetTableFromFile (Gbl_ExternalFilename, &ExternalTable);
394 if (ACPI_FAILURE (Status))
402 Status = AdGetLocalTables (Filename, GetAllTables);
403 if (ACPI_FAILURE (Status))
405 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
406 AcpiFormatException (Status));
410 if (!AcpiGbl_DbOpt_disasm)
415 /* Obtained the local tables, just disassemble the DSDT */
417 Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
418 if (ACPI_FAILURE (Status))
420 AcpiOsPrintf ("Could not get DSDT, %s\n",
421 AcpiFormatException (Status));
425 AcpiOsPrintf ("\nDisassembly of DSDT\n");
426 Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
431 * Redirect to a file if requested
435 /* Create/Open a disassembly output file */
437 DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
440 fprintf (stderr, "Could not generate output filename\n");
445 File = fopen (DisasmFilename, "w+");
448 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
453 AcpiOsRedirectOutput (File);
456 *OutFilename = DisasmFilename;
458 if (!AcpiUtIsAmlTable (Table))
460 AdDisassemblerHeader (Filename);
461 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
463 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue\n */\n\n");
465 AcpiDmDumpDataTable (Table);
466 fprintf (stderr, "Acpi Data Table [%4.4s] decoded, written to \"%s\"\n",
467 Table->Signature, DisasmFilename);
471 /* Always parse the tables, only option is what to display */
473 Status = AdParseTable (Table);
474 if (ACPI_FAILURE (Status))
476 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
477 AcpiFormatException (Status));
481 if (AslCompilerdebug)
483 AcpiOsPrintf ("/**** Before second load\n");
485 LsSetupNsList (File);
486 LsDisplayNamespace ();
487 AcpiOsPrintf ("*****/\n");
491 * Load namespace from names created within control methods
493 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
496 * Cross reference the namespace here, in order to generate External() statements
498 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
500 if (AslCompilerdebug)
502 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
505 /* Find possible calls to external control methods */
507 AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
509 /* Convert fixed-offset references to resource descriptors to symbolic references */
511 AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
513 if (AslCompilerdebug)
515 AcpiOsPrintf ("/**** After second load and resource conversion\n");
516 LsSetupNsList (File);
517 LsDisplayNamespace ();
518 AcpiOsPrintf ("*****/\n");
522 * If we found any external control methods, we must reparse the entire
523 * tree with the new information (namely, the number of arguments per
526 if (AdMethodExternalCount ())
529 "\nFound %d external control methods, reparsing with new information\n",
530 AdMethodExternalCount());
533 * Reparse, rebuild namespace. no need to xref namespace
535 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
536 AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
538 AcpiGbl_RootNode = NULL;
539 AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
540 AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
541 AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;
542 AcpiGbl_RootNodeStruct.Child = NULL;
543 AcpiGbl_RootNodeStruct.Peer = NULL;
544 AcpiGbl_RootNodeStruct.Object = NULL;
545 AcpiGbl_RootNodeStruct.Flags = ANOBJ_END_OF_PEER_LIST;
547 Status = AcpiNsRootInitialize ();
548 AdAddExternalsToNamespace ();
550 Status = AdParseTable (Table);
551 if (ACPI_FAILURE (Status))
553 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
554 AcpiFormatException (Status));
558 if (AslCompilerdebug)
560 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
564 /* Optional displays */
566 if (AcpiGbl_DbOpt_disasm)
568 AdDisplayTables (Filename, Table);
570 "Disassembly completed, written to \"%s\"\n",
576 if (OutToFile && File)
579 #ifdef ASL_DISASM_DEBUG
580 LsSetupNsList (File);
581 LsDisplayNamespace ();
584 AcpiOsRedirectOutput (stdout);
587 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
592 /******************************************************************************
594 * FUNCTION: AdDisassemblerHeader
596 * PARAMETERS: Filename - Input file for the table
600 * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
601 * current time and date.
603 *****************************************************************************/
606 AdDisassemblerHeader (
613 /* Header and input table info */
615 AcpiOsPrintf ("/*\n * Intel ACPI Component Architecture\n");
616 AcpiOsPrintf (" * AML Disassembler version %8.8X\n", ACPI_CA_VERSION);
618 AcpiOsPrintf (" *\n * Disassembly of %s, %s", Filename, ctime (&Timer));
619 AcpiOsPrintf (" *\n");
623 /******************************************************************************
625 * FUNCTION: AdCreateTableHeader
627 * PARAMETERS: Filename - Input file for the table
628 * Table - Pointer to the raw table
632 * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
633 * current time and date.
635 *****************************************************************************/
638 AdCreateTableHeader (
640 ACPI_TABLE_HEADER *Table)
645 AdDisassemblerHeader (Filename);
647 AcpiOsPrintf (" *\n * Original Table Header:\n");
648 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
649 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
650 AcpiOsPrintf (" * Revision 0x%2.2X\n", Table->Revision);
651 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
652 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
653 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
654 AcpiOsPrintf (" * Creator ID \"%.4s\"\n", Table->AslCompilerId);
655 AcpiOsPrintf (" * Creator Revision 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
656 AcpiOsPrintf (" */\n");
658 /* Create AML output filename based on input filename */
662 NewFilename = FlGenerateFilename (Filename, "aml");
666 NewFilename = ACPI_ALLOCATE_ZEROED (9);
667 strncat (NewFilename, Table->Signature, 4);
668 strcat (NewFilename, ".aml");
671 /* Open the ASL definition block */
674 "DefinitionBlock (\"%s\", \"%4.4s\", %hd, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
675 NewFilename, Table->Signature, Table->Revision,
676 Table->OemId, Table->OemTableId, Table->OemRevision);
680 /******************************************************************************
682 * FUNCTION: AdDisplayTables
684 * PARAMETERS: Filename - Input file for the table
685 * Table - Pointer to the raw table
689 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
691 *****************************************************************************/
696 ACPI_TABLE_HEADER *Table)
700 if (!AcpiGbl_ParseOpRoot)
705 if (!AcpiGbl_DbOpt_verbose)
707 AdCreateTableHeader (Filename, Table);
710 AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
712 if (AcpiGbl_DbOpt_verbose)
714 AcpiOsPrintf ("\n\nTable Header:\n");
715 AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
716 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
718 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
719 AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
720 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
727 /******************************************************************************
729 * FUNCTION: AdDeferredParse
731 * PARAMETERS: Op - Root Op of the deferred opcode
732 * Aml - Pointer to the raw AML
733 * AmlLength - Length of the AML
737 * DESCRIPTION: Parse one deferred opcode
738 * (Methods, operation regions, etc.)
740 *****************************************************************************/
744 ACPI_PARSE_OBJECT *Op,
748 ACPI_WALK_STATE *WalkState;
750 ACPI_PARSE_OBJECT *SearchOp;
751 ACPI_PARSE_OBJECT *StartOp;
752 UINT32 BaseAmlOffset;
753 ACPI_PARSE_OBJECT *ExtraOp;
756 ACPI_FUNCTION_TRACE (AdDeferredParse);
759 fprintf (stderr, ".");
761 if (!Aml || !AmlLength)
763 return_ACPI_STATUS (AE_OK);
766 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
767 Op->Common.AmlOpName, (char *) &Op->Named.Name));
769 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
772 return_ACPI_STATUS (AE_NO_MEMORY);
775 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
776 AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
777 if (ACPI_FAILURE (Status))
779 return_ACPI_STATUS (Status);
782 /* Parse the method */
784 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
785 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
786 Status = AcpiPsParseAml (WalkState);
789 * We need to update all of the Aml offsets, since the parser thought
790 * that the method began at offset zero. In reality, it began somewhere
791 * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
792 * was just created and update the AmlOffset in each Op
794 BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
795 StartOp = (Op->Common.Value.Arg)->Common.Next;
798 /* Walk the parse tree */
802 SearchOp->Common.AmlOffset += BaseAmlOffset;
803 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
807 * Link the newly parsed subtree into the main parse tree
809 switch (Op->Common.AmlOpcode)
813 case AML_VAR_PACKAGE_OP:
815 switch (Op->Common.AmlOpcode)
818 ExtraOp = Op->Common.Value.Arg;
819 ExtraOp = ExtraOp->Common.Next;
820 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
823 case AML_VAR_PACKAGE_OP:
826 ExtraOp = Op->Common.Value.Arg;
827 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
831 /* Must point all parents to the main tree */
837 if (SearchOp->Common.Parent == ExtraOp)
839 SearchOp->Common.Parent = Op;
841 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
849 return_ACPI_STATUS (AE_OK);
853 /******************************************************************************
855 * FUNCTION: AdParseDeferredOps
857 * PARAMETERS: Root - Root of the parse tree
861 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
863 *****************************************************************************/
867 ACPI_PARSE_OBJECT *Root)
869 ACPI_PARSE_OBJECT *Op = Root;
870 ACPI_STATUS Status = AE_OK;
871 const ACPI_OPCODE_INFO *OpInfo;
874 ACPI_FUNCTION_NAME (AdParseDeferredOps);
875 fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
879 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
880 if (!(OpInfo->Flags & AML_DEFER))
882 Op = AcpiPsGetDepthNext (Root, Op);
886 switch (Op->Common.AmlOpcode)
891 case AML_VAR_PACKAGE_OP:
893 Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
894 if (ACPI_FAILURE (Status))
896 return_ACPI_STATUS (Status);
901 case AML_CREATE_QWORD_FIELD_OP:
902 case AML_CREATE_DWORD_FIELD_OP:
903 case AML_CREATE_WORD_FIELD_OP:
904 case AML_CREATE_BYTE_FIELD_OP:
905 case AML_CREATE_BIT_FIELD_OP:
906 case AML_CREATE_FIELD_OP:
908 /* Nothing to do in these cases */
913 ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
914 Op->Common.AmlOpName));
918 Op = AcpiPsGetDepthNext (Root, Op);
921 fprintf (stderr, "\n");
926 /******************************************************************************
928 * FUNCTION: AdGetLocalTables
930 * PARAMETERS: Filename - Not used
931 * GetAllTables - TRUE if all tables are desired
935 * DESCRIPTION: Get the ACPI tables from either memory or a file
937 *****************************************************************************/
942 BOOLEAN GetAllTables)
945 ACPI_TABLE_HEADER TableHeader;
946 ACPI_TABLE_HEADER *NewTable;
949 ACPI_NATIVE_UINT TableIndex;
954 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
955 AcpiOsTableOverride (&TableHeader, &NewTable);
958 fprintf (stderr, "Could not obtain RSDT\n");
959 return AE_NO_ACPI_TABLES;
962 if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
964 PointerSize = sizeof (UINT32);
968 PointerSize = sizeof (UINT64);
972 * Determine the number of tables pointed to by the RSDT/XSDT.
973 * This is defined by the ACPI Specification to be the number of
974 * pointers contained within the RSDT/XSDT. The size of the pointers
975 * is architecture-dependent.
977 NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
978 AcpiOsPrintf ("There are %d tables defined in the %4.4s\n\n",
979 NumTables, NewTable->Signature);
983 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
984 AcpiOsTableOverride (&TableHeader, &NewTable);
987 AdWriteTable (NewTable, NewTable->Length,
988 ACPI_SIG_FADT, NewTable->OemTableId);
992 /* Don't bother with FACS, it is usually all zeros */
995 /* Always get the DSDT */
997 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
998 AcpiOsTableOverride (&TableHeader, &NewTable);
1001 AdWriteTable (NewTable, NewTable->Length,
1002 ACPI_SIG_DSDT, NewTable->OemTableId);
1004 /* Store DSDT in the Table Manager */
1006 Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
1011 fprintf (stderr, "Could not obtain DSDT\n");
1012 return AE_NO_ACPI_TABLES;
1016 /* TBD: Future implementation */
1018 AcpiOsPrintf ("\n");
1022 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
1026 Status = AcpiOsTableOverride (&TableHeader, &NewTable);
1035 /******************************************************************************
1037 * FUNCTION: AdParseTable
1039 * PARAMETERS: Table - Pointer to the raw table
1043 * DESCRIPTION: Parse the DSDT.
1045 *****************************************************************************/
1049 ACPI_TABLE_HEADER *Table)
1051 ACPI_STATUS Status = AE_OK;
1052 ACPI_WALK_STATE *WalkState;
1055 ACPI_NATIVE_UINT TableIndex;
1060 return AE_NOT_EXIST;
1063 /* Pass 1: Parse everything except control method bodies */
1065 fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
1067 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
1068 AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
1070 /* Create the root object */
1072 AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
1073 if (!AcpiGbl_ParseOpRoot)
1075 return AE_NO_MEMORY;
1078 /* Create and initialize a new walk state */
1080 WalkState = AcpiDsCreateWalkState (0,
1081 AcpiGbl_ParseOpRoot, NULL, NULL);
1084 return (AE_NO_MEMORY);
1087 Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
1088 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
1089 if (ACPI_FAILURE (Status))
1094 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1095 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
1097 Status = AcpiPsParseAml (WalkState);
1098 if (ACPI_FAILURE (Status))
1105 Status = AcpiTbStoreTable ((ACPI_NATIVE_UINT) Table, Table,
1106 Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
1107 if (ACPI_FAILURE (Status))
1112 fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
1114 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, 0);
1115 if (ACPI_FAILURE (Status))
1120 /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
1122 Status = AdParseDeferredOps (AcpiGbl_ParseOpRoot);
1124 /* Process Resource Templates */
1126 AcpiDmFindResources (AcpiGbl_ParseOpRoot);
1128 fprintf (stderr, "Parsing completed\n");