1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acparser.h>
48 #include <contrib/dev/acpica/include/amlcode.h>
49 #include <contrib/dev/acpica/include/acdebug.h>
50 #include <contrib/dev/acpica/include/acdisasm.h>
51 #include <contrib/dev/acpica/include/acdispat.h>
52 #include <contrib/dev/acpica/include/acnamesp.h>
53 #include <contrib/dev/acpica/include/actables.h>
54 #include <contrib/dev/acpica/include/acapps.h>
60 #define _COMPONENT ACPI_TOOLS
61 ACPI_MODULE_NAME ("adisasm")
64 extern int AslCompilerdebug;
76 /* Local prototypes */
81 ACPI_TABLE_HEADER *Table);
85 ACPI_PARSE_OBJECT *Op,
91 ACPI_PARSE_OBJECT *Root);
94 /* Stubs for ASL compiler */
96 #ifndef ACPI_ASL_COMPILER
99 ACPI_PARSE_OBJECT *Op,
100 ACPI_WALK_STATE *WalkState)
108 ACPI_WALK_STATE *WalkState)
117 ACPI_NAMESPACE_NODE *Node)
119 return (AE_NOT_IMPLEMENTED);
123 AcpiDsRestartControlMethod (
124 ACPI_WALK_STATE *WalkState,
125 ACPI_OPERAND_OBJECT *ReturnDesc)
131 AcpiDsTerminateControlMethod (
132 ACPI_OPERAND_OBJECT *MethodDesc,
133 ACPI_WALK_STATE *WalkState)
139 AcpiDsCallControlMethod (
140 ACPI_THREAD_STATE *Thread,
141 ACPI_WALK_STATE *WalkState,
142 ACPI_PARSE_OBJECT *Op)
148 AcpiDsMethodDataInitArgs (
149 ACPI_OPERAND_OBJECT **Params,
150 UINT32 MaxParamCount,
151 ACPI_WALK_STATE *WalkState)
157 static ACPI_TABLE_DESC LocalTables[1];
158 static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
161 /*******************************************************************************
163 * FUNCTION: AdInitialize
169 * DESCRIPTION: ACPICA and local initialization
171 ******************************************************************************/
180 /* ACPI CA subsystem initialization */
182 Status = AcpiOsInitialize ();
183 if (ACPI_FAILURE (Status))
188 Status = AcpiUtInitGlobals ();
189 if (ACPI_FAILURE (Status))
194 Status = AcpiUtMutexInitialize ();
195 if (ACPI_FAILURE (Status))
200 Status = AcpiNsRootInitialize ();
201 if (ACPI_FAILURE (Status))
206 /* Setup the Table Manager (cheat - there is no RSDT) */
208 AcpiGbl_RootTableList.MaxTableCount = 1;
209 AcpiGbl_RootTableList.CurrentTableCount = 0;
210 AcpiGbl_RootTableList.Tables = LocalTables;
216 /******************************************************************************
218 * FUNCTION: AdAmlDisassemble
220 * PARAMETERS: Filename - AML input filename
221 * OutToFile - TRUE if output should go to a file
222 * Prefix - Path prefix for output
223 * OutFilename - where the filename is returned
224 * GetAllTables - TRUE if all tables are desired
228 * DESCRIPTION: Disassemble an entire ACPI table
230 *****************************************************************************/
238 BOOLEAN GetAllTables)
241 char *DisasmFilename = NULL;
242 char *ExternalFilename;
243 ACPI_EXTERNAL_FILE *ExternalFileList = AcpiGbl_ExternalFileList;
245 ACPI_TABLE_HEADER *Table = NULL;
246 ACPI_TABLE_HEADER *ExternalTable;
247 ACPI_OWNER_ID OwnerId;
251 * Input: AML code from either a file or via GetTables (memory or
256 Status = AcpiDbGetTableFromFile (Filename, &Table);
257 if (ACPI_FAILURE (Status))
263 * External filenames separated by commas
264 * Example: iasl -e file1,file2,file3 -d xxx.aml
266 while (ExternalFileList)
268 ExternalFilename = ExternalFileList->Path;
269 if (!ACPI_STRCMP (ExternalFilename, Filename))
271 /* Next external file */
273 ExternalFileList = ExternalFileList->Next;
278 Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
279 if (ACPI_FAILURE (Status))
284 /* Load external table for symbol resolution */
288 Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
289 if (ACPI_FAILURE (Status))
291 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
292 AcpiFormatException (Status));
297 * Load namespace from names created within control methods
298 * Set owner id of nodes in external table
300 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
301 AcpiGbl_RootNode, OwnerId);
302 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
305 /* Next external file */
307 ExternalFileList = ExternalFileList->Next;
310 /* Clear external list generated by Scope in external tables */
312 if (AcpiGbl_ExternalFileList)
314 AcpiDmClearExternalList ();
319 Status = AdGetLocalTables (Filename, GetAllTables);
320 if (ACPI_FAILURE (Status))
322 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
323 AcpiFormatException (Status));
327 if (!AcpiGbl_DbOpt_disasm)
332 /* Obtained the local tables, just disassemble the DSDT */
334 Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
335 if (ACPI_FAILURE (Status))
337 AcpiOsPrintf ("Could not get DSDT, %s\n",
338 AcpiFormatException (Status));
342 AcpiOsPrintf ("\nDisassembly of DSDT\n");
343 Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
347 * Output: ASL code. Redirect to a file if requested
351 /* Create/Open a disassembly output file */
353 DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
356 fprintf (stderr, "Could not generate output filename\n");
361 File = fopen (DisasmFilename, "w+");
364 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
369 AcpiOsRedirectOutput (File);
372 *OutFilename = DisasmFilename;
374 if (!AcpiUtIsAmlTable (Table))
376 AdDisassemblerHeader (Filename);
377 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
379 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue\n */\n\n");
381 AcpiDmDumpDataTable (Table);
382 fprintf (stderr, "Acpi Data Table [%4.4s] decoded, written to \"%s\"\n",
383 Table->Signature, DisasmFilename);
387 /* Always parse the tables, only option is what to display */
389 Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
390 if (ACPI_FAILURE (Status))
392 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
393 AcpiFormatException (Status));
397 if (AslCompilerdebug)
399 AcpiOsPrintf ("/**** Before second load\n");
401 LsSetupNsList (File);
402 LsDisplayNamespace ();
403 AcpiOsPrintf ("*****/\n");
407 * Load namespace from names created within control methods
409 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
412 * Cross reference the namespace here, in order to generate External() statements
414 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
416 if (AslCompilerdebug)
418 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
421 /* Find possible calls to external control methods */
423 AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
425 /* Convert fixed-offset references to resource descriptors to symbolic references */
427 AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
430 * If we found any external control methods, we must reparse the entire
431 * tree with the new information (namely, the number of arguments per
434 if (AcpiDmGetExternalMethodCount ())
437 "\nFound %u external control methods, reparsing with new information\n",
438 AcpiDmGetExternalMethodCount ());
441 * Reparse, rebuild namespace. no need to xref namespace
443 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
444 AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
446 AcpiGbl_RootNode = NULL;
447 AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
448 AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
449 AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;
450 AcpiGbl_RootNodeStruct.Parent = NULL;
451 AcpiGbl_RootNodeStruct.Child = NULL;
452 AcpiGbl_RootNodeStruct.Peer = NULL;
453 AcpiGbl_RootNodeStruct.Object = NULL;
454 AcpiGbl_RootNodeStruct.Flags = 0;
456 Status = AcpiNsRootInitialize ();
457 AcpiDmAddExternalsToNamespace ();
459 /* Parse table. No need to reload it, however (FALSE) */
461 Status = AdParseTable (Table, NULL, FALSE, FALSE);
462 if (ACPI_FAILURE (Status))
464 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
465 AcpiFormatException (Status));
469 if (AslCompilerdebug)
471 AcpiOsPrintf ("/**** After second load and resource conversion\n");
472 LsSetupNsList (File);
473 LsDisplayNamespace ();
474 AcpiOsPrintf ("*****/\n");
476 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
480 /* Optional displays */
482 if (AcpiGbl_DbOpt_disasm)
484 AdDisplayTables (Filename, Table);
486 "Disassembly completed, written to \"%s\"\n",
493 if (Table && !AcpiUtIsAmlTable (Table))
500 ACPI_FREE (DisasmFilename);
503 if (OutToFile && File)
506 #ifdef ASL_DISASM_DEBUG
507 LsSetupNsList (File);
508 LsDisplayNamespace ();
511 AcpiOsRedirectOutput (stdout);
514 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
515 AcpiGbl_ParseOpRoot = NULL;
520 /******************************************************************************
522 * FUNCTION: AdDisassemblerHeader
524 * PARAMETERS: Filename - Input file for the table
528 * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
529 * current time and date.
531 *****************************************************************************/
534 AdDisassemblerHeader (
541 /* Header and input table info */
543 AcpiOsPrintf ("/*\n");
544 AcpiOsPrintf (ACPI_COMMON_HEADER ("AML Disassembler", " * "));
546 AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
547 AcpiOsPrintf (" *\n");
551 /******************************************************************************
553 * FUNCTION: AdCreateTableHeader
555 * PARAMETERS: Filename - Input file for the table
556 * Table - Pointer to the raw table
560 * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
561 * current time and date.
563 *****************************************************************************/
566 AdCreateTableHeader (
568 ACPI_TABLE_HEADER *Table)
575 * Print file header and dump original table header
577 AdDisassemblerHeader (Filename);
579 AcpiOsPrintf (" * Original Table Header:\n");
580 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
581 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
583 /* Print and validate the revision */
585 AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
587 switch (Table->Revision)
590 AcpiOsPrintf (" **** Invalid Revision");
594 /* Revision of DSDT controls the ACPI integer width */
596 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
598 AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
607 /* Print and validate the table checksum */
609 AcpiOsPrintf (" * Checksum 0x%2.2X", Table->Checksum);
611 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
614 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
615 (UINT8) (Table->Checksum - Checksum));
619 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
620 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
621 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
622 AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
623 AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
624 AcpiOsPrintf (" */\n\n");
626 /* Create AML output filename based on input filename */
630 NewFilename = FlGenerateFilename (Filename, "aml");
634 NewFilename = ACPI_ALLOCATE_ZEROED (9);
635 strncat (NewFilename, Table->Signature, 4);
636 strcat (NewFilename, ".aml");
639 /* Open the ASL definition block */
642 "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
643 NewFilename, Table->Signature, Table->Revision,
644 Table->OemId, Table->OemTableId, Table->OemRevision);
646 ACPI_FREE (NewFilename);
650 /******************************************************************************
652 * FUNCTION: AdDisplayTables
654 * PARAMETERS: Filename - Input file for the table
655 * Table - Pointer to the raw table
659 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
661 *****************************************************************************/
666 ACPI_TABLE_HEADER *Table)
670 if (!AcpiGbl_ParseOpRoot)
675 if (!AcpiGbl_DbOpt_verbose)
677 AdCreateTableHeader (Filename, Table);
680 AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
682 if (AcpiGbl_DbOpt_verbose)
684 AcpiOsPrintf ("\n\nTable Header:\n");
685 AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
686 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
688 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
689 AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
690 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
697 /******************************************************************************
699 * FUNCTION: AdDeferredParse
701 * PARAMETERS: Op - Root Op of the deferred opcode
702 * Aml - Pointer to the raw AML
703 * AmlLength - Length of the AML
707 * DESCRIPTION: Parse one deferred opcode
708 * (Methods, operation regions, etc.)
710 *****************************************************************************/
714 ACPI_PARSE_OBJECT *Op,
718 ACPI_WALK_STATE *WalkState;
720 ACPI_PARSE_OBJECT *SearchOp;
721 ACPI_PARSE_OBJECT *StartOp;
722 UINT32 BaseAmlOffset;
723 ACPI_PARSE_OBJECT *ExtraOp;
726 ACPI_FUNCTION_TRACE (AdDeferredParse);
729 fprintf (stderr, ".");
731 if (!Aml || !AmlLength)
733 return_ACPI_STATUS (AE_OK);
736 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
737 Op->Common.AmlOpName, (char *) &Op->Named.Name));
739 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
742 return_ACPI_STATUS (AE_NO_MEMORY);
745 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
746 AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
747 if (ACPI_FAILURE (Status))
749 return_ACPI_STATUS (Status);
752 /* Parse the method */
754 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
755 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
756 Status = AcpiPsParseAml (WalkState);
759 * We need to update all of the Aml offsets, since the parser thought
760 * that the method began at offset zero. In reality, it began somewhere
761 * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
762 * was just created and update the AmlOffset in each Op
764 BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
765 StartOp = (Op->Common.Value.Arg)->Common.Next;
768 /* Walk the parse tree */
772 SearchOp->Common.AmlOffset += BaseAmlOffset;
773 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
777 * Link the newly parsed subtree into the main parse tree
779 switch (Op->Common.AmlOpcode)
783 case AML_VAR_PACKAGE_OP:
785 switch (Op->Common.AmlOpcode)
788 ExtraOp = Op->Common.Value.Arg;
789 ExtraOp = ExtraOp->Common.Next;
790 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
793 case AML_VAR_PACKAGE_OP:
796 ExtraOp = Op->Common.Value.Arg;
797 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
801 /* Must point all parents to the main tree */
807 if (SearchOp->Common.Parent == ExtraOp)
809 SearchOp->Common.Parent = Op;
811 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
819 return_ACPI_STATUS (AE_OK);
823 /******************************************************************************
825 * FUNCTION: AdParseDeferredOps
827 * PARAMETERS: Root - Root of the parse tree
831 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
833 *****************************************************************************/
837 ACPI_PARSE_OBJECT *Root)
839 ACPI_PARSE_OBJECT *Op = Root;
840 ACPI_STATUS Status = AE_OK;
841 const ACPI_OPCODE_INFO *OpInfo;
844 ACPI_FUNCTION_NAME (AdParseDeferredOps);
845 fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
849 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
850 if (!(OpInfo->Flags & AML_DEFER))
852 Op = AcpiPsGetDepthNext (Root, Op);
856 switch (Op->Common.AmlOpcode)
861 case AML_VAR_PACKAGE_OP:
863 Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
864 if (ACPI_FAILURE (Status))
866 return_ACPI_STATUS (Status);
871 case AML_CREATE_QWORD_FIELD_OP:
872 case AML_CREATE_DWORD_FIELD_OP:
873 case AML_CREATE_WORD_FIELD_OP:
874 case AML_CREATE_BYTE_FIELD_OP:
875 case AML_CREATE_BIT_FIELD_OP:
876 case AML_CREATE_FIELD_OP:
877 case AML_BANK_FIELD_OP:
879 /* Nothing to do in these cases */
884 ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
885 Op->Common.AmlOpName));
889 Op = AcpiPsGetDepthNext (Root, Op);
892 fprintf (stderr, "\n");
897 /******************************************************************************
899 * FUNCTION: AdGetLocalTables
901 * PARAMETERS: Filename - Not used
902 * GetAllTables - TRUE if all tables are desired
906 * DESCRIPTION: Get the ACPI tables from either memory or a file
908 *****************************************************************************/
913 BOOLEAN GetAllTables)
916 ACPI_TABLE_HEADER TableHeader;
917 ACPI_TABLE_HEADER *NewTable;
925 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
926 AcpiOsTableOverride (&TableHeader, &NewTable);
929 fprintf (stderr, "Could not obtain RSDT\n");
930 return AE_NO_ACPI_TABLES;
934 AdWriteTable (NewTable, NewTable->Length,
935 ACPI_SIG_RSDT, NewTable->OemTableId);
938 if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
940 PointerSize = sizeof (UINT32);
944 PointerSize = sizeof (UINT64);
948 * Determine the number of tables pointed to by the RSDT/XSDT.
949 * This is defined by the ACPI Specification to be the number of
950 * pointers contained within the RSDT/XSDT. The size of the pointers
951 * is architecture-dependent.
953 NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
954 AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n",
955 NumTables, NewTable->Signature);
959 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
960 AcpiOsTableOverride (&TableHeader, &NewTable);
963 AdWriteTable (NewTable, NewTable->Length,
964 ACPI_SIG_FADT, NewTable->OemTableId);
968 /* Don't bother with FACS, it is usually all zeros */
971 /* Always get the DSDT */
973 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
974 AcpiOsTableOverride (&TableHeader, &NewTable);
977 AdWriteTable (NewTable, NewTable->Length,
978 ACPI_SIG_DSDT, NewTable->OemTableId);
980 /* Store DSDT in the Table Manager */
982 Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
984 if (ACPI_FAILURE (Status))
986 fprintf (stderr, "Could not store DSDT\n");
987 return AE_NO_ACPI_TABLES;
992 fprintf (stderr, "Could not obtain DSDT\n");
993 return AE_NO_ACPI_TABLES;
997 /* TBD: Future implementation */
1003 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
1007 Status = AcpiOsTableOverride (&TableHeader, &NewTable);
1016 /******************************************************************************
1018 * FUNCTION: AdParseTable
1020 * PARAMETERS: Table - Pointer to the raw table
1021 * OwnerId - Returned OwnerId of the table
1022 * LoadTable - If add table to the global table list
1023 * External - If this is an external table
1027 * DESCRIPTION: Parse the DSDT.
1029 *****************************************************************************/
1033 ACPI_TABLE_HEADER *Table,
1034 ACPI_OWNER_ID *OwnerId,
1038 ACPI_STATUS Status = AE_OK;
1039 ACPI_WALK_STATE *WalkState;
1047 return AE_NOT_EXIST;
1050 /* Pass 1: Parse everything except control method bodies */
1052 fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
1054 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
1055 AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
1057 /* Create the root object */
1059 AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
1060 if (!AcpiGbl_ParseOpRoot)
1062 return AE_NO_MEMORY;
1065 /* Create and initialize a new walk state */
1067 WalkState = AcpiDsCreateWalkState (0,
1068 AcpiGbl_ParseOpRoot, NULL, NULL);
1071 return (AE_NO_MEMORY);
1074 Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
1075 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
1076 if (ACPI_FAILURE (Status))
1081 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1082 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
1084 Status = AcpiPsParseAml (WalkState);
1085 if (ACPI_FAILURE (Status))
1090 /* If LoadTable is FALSE, we are parsing the last loaded table */
1092 TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
1098 Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
1099 Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
1100 if (ACPI_FAILURE (Status))
1104 Status = AcpiTbAllocateOwnerId (TableIndex);
1105 if (ACPI_FAILURE (Status))
1111 Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
1112 if (ACPI_FAILURE (Status))
1119 fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
1121 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
1122 if (ACPI_FAILURE (Status))
1127 /* No need to parse control methods of external table */
1134 /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
1136 Status = AdParseDeferredOps (AcpiGbl_ParseOpRoot);
1138 /* Process Resource Templates */
1140 AcpiDmFindResources (AcpiGbl_ParseOpRoot);
1142 fprintf (stderr, "Parsing completed\n");