1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
12 * All rights reserved.
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
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
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 *****************************************************************************/
118 #include "accommon.h"
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")
136 extern int AslCompilerdebug;
148 /* Local prototypes */
151 AdCreateTableHeader (
153 ACPI_TABLE_HEADER *Table);
157 ACPI_PARSE_OBJECT *Op,
163 ACPI_PARSE_OBJECT *Root);
166 /* Stubs for ASL compiler */
168 #ifndef ACPI_ASL_COMPILER
171 ACPI_PARSE_OBJECT *Op,
172 ACPI_WALK_STATE *WalkState)
180 ACPI_WALK_STATE *WalkState)
189 ACPI_NAMESPACE_NODE *Node)
191 return (AE_NOT_IMPLEMENTED);
195 AcpiDsRestartControlMethod (
196 ACPI_WALK_STATE *WalkState,
197 ACPI_OPERAND_OBJECT *ReturnDesc)
203 AcpiDsTerminateControlMethod (
204 ACPI_OPERAND_OBJECT *MethodDesc,
205 ACPI_WALK_STATE *WalkState)
211 AcpiDsCallControlMethod (
212 ACPI_THREAD_STATE *Thread,
213 ACPI_WALK_STATE *WalkState,
214 ACPI_PARSE_OBJECT *Op)
220 AcpiDsMethodDataInitArgs (
221 ACPI_OPERAND_OBJECT **Params,
222 UINT32 MaxParamCount,
223 ACPI_WALK_STATE *WalkState)
229 static ACPI_TABLE_DESC LocalTables[1];
230 static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
233 /*******************************************************************************
235 * FUNCTION: AdInitialize
241 * DESCRIPTION: ACPICA and local initialization
243 ******************************************************************************/
252 /* ACPI CA subsystem initialization */
254 Status = AcpiOsInitialize ();
255 if (ACPI_FAILURE (Status))
260 Status = AcpiUtInitGlobals ();
261 if (ACPI_FAILURE (Status))
266 Status = AcpiUtMutexInitialize ();
267 if (ACPI_FAILURE (Status))
272 Status = AcpiNsRootInitialize ();
273 if (ACPI_FAILURE (Status))
278 /* Setup the Table Manager (cheat - there is no RSDT) */
280 AcpiGbl_RootTableList.MaxTableCount = 1;
281 AcpiGbl_RootTableList.CurrentTableCount = 0;
282 AcpiGbl_RootTableList.Tables = LocalTables;
288 /******************************************************************************
290 * FUNCTION: AdAmlDisassemble
292 * PARAMETERS: Filename - AML input filename
293 * OutToFile - TRUE if output should go to a file
294 * Prefix - Path prefix for output
295 * OutFilename - where the filename is returned
296 * GetAllTables - TRUE if all tables are desired
300 * DESCRIPTION: Disassemble an entire ACPI table
302 *****************************************************************************/
310 BOOLEAN GetAllTables)
313 char *DisasmFilename = NULL;
314 char *ExternalFilename;
315 ACPI_EXTERNAL_FILE *ExternalFileList = AcpiGbl_ExternalFileList;
317 ACPI_TABLE_HEADER *Table = NULL;
318 ACPI_TABLE_HEADER *ExternalTable;
319 ACPI_OWNER_ID OwnerId;
323 * Input: AML code from either a file or via GetTables (memory or
328 Status = AcpiDbGetTableFromFile (Filename, &Table);
329 if (ACPI_FAILURE (Status))
335 * External filenames separated by commas
336 * Example: iasl -e file1,file2,file3 -d xxx.aml
338 while (ExternalFileList)
340 ExternalFilename = ExternalFileList->Path;
341 if (!ACPI_STRCMP (ExternalFilename, Filename))
343 /* Next external file */
345 ExternalFileList = ExternalFileList->Next;
350 Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
351 if (ACPI_FAILURE (Status))
356 /* Load external table for symbol resolution */
360 Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
361 if (ACPI_FAILURE (Status))
363 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
364 AcpiFormatException (Status));
369 * Load namespace from names created within control methods
370 * Set owner id of nodes in external table
372 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
373 AcpiGbl_RootNode, OwnerId);
374 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
377 /* Next external file */
379 ExternalFileList = ExternalFileList->Next;
382 /* Clear external list generated by Scope in external tables */
384 if (AcpiGbl_ExternalFileList)
386 AcpiDmClearExternalList ();
391 Status = AdGetLocalTables (Filename, GetAllTables);
392 if (ACPI_FAILURE (Status))
394 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
395 AcpiFormatException (Status));
399 if (!AcpiGbl_DbOpt_disasm)
404 /* Obtained the local tables, just disassemble the DSDT */
406 Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
407 if (ACPI_FAILURE (Status))
409 AcpiOsPrintf ("Could not get DSDT, %s\n",
410 AcpiFormatException (Status));
414 AcpiOsPrintf ("\nDisassembly of DSDT\n");
415 Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
419 * Output: ASL code. Redirect to a file if requested
423 /* Create/Open a disassembly output file */
425 DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
428 fprintf (stderr, "Could not generate output filename\n");
433 File = fopen (DisasmFilename, "w+");
436 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
441 AcpiOsRedirectOutput (File);
444 *OutFilename = DisasmFilename;
446 if (!AcpiUtIsAmlTable (Table))
448 AdDisassemblerHeader (Filename);
449 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
451 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue\n */\n\n");
453 AcpiDmDumpDataTable (Table);
454 fprintf (stderr, "Acpi Data Table [%4.4s] decoded, written to \"%s\"\n",
455 Table->Signature, DisasmFilename);
459 /* Always parse the tables, only option is what to display */
461 Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
462 if (ACPI_FAILURE (Status))
464 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
465 AcpiFormatException (Status));
469 if (AslCompilerdebug)
471 AcpiOsPrintf ("/**** Before second load\n");
473 LsSetupNsList (File);
474 LsDisplayNamespace ();
475 AcpiOsPrintf ("*****/\n");
479 * Load namespace from names created within control methods
481 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
484 * Cross reference the namespace here, in order to generate External() statements
486 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
488 if (AslCompilerdebug)
490 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
493 /* Find possible calls to external control methods */
495 AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
497 /* Convert fixed-offset references to resource descriptors to symbolic references */
499 AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
502 * If we found any external control methods, we must reparse the entire
503 * tree with the new information (namely, the number of arguments per
506 if (AcpiDmGetExternalMethodCount ())
509 "\nFound %u external control methods, reparsing with new information\n",
510 AcpiDmGetExternalMethodCount ());
513 * Reparse, rebuild namespace. no need to xref namespace
515 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
516 AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
518 AcpiGbl_RootNode = NULL;
519 AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
520 AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
521 AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;
522 AcpiGbl_RootNodeStruct.Parent = NULL;
523 AcpiGbl_RootNodeStruct.Child = NULL;
524 AcpiGbl_RootNodeStruct.Peer = NULL;
525 AcpiGbl_RootNodeStruct.Object = NULL;
526 AcpiGbl_RootNodeStruct.Flags = 0;
528 Status = AcpiNsRootInitialize ();
529 AcpiDmAddExternalsToNamespace ();
531 /* Parse table. No need to reload it, however (FALSE) */
533 Status = AdParseTable (Table, NULL, FALSE, FALSE);
534 if (ACPI_FAILURE (Status))
536 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
537 AcpiFormatException (Status));
541 if (AslCompilerdebug)
543 AcpiOsPrintf ("/**** After second load and resource conversion\n");
544 LsSetupNsList (File);
545 LsDisplayNamespace ();
546 AcpiOsPrintf ("*****/\n");
548 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
552 /* Optional displays */
554 if (AcpiGbl_DbOpt_disasm)
556 AdDisplayTables (Filename, Table);
558 "Disassembly completed, written to \"%s\"\n",
565 if (Table && !AcpiUtIsAmlTable (Table))
572 ACPI_FREE (DisasmFilename);
575 if (OutToFile && File)
578 #ifdef ASL_DISASM_DEBUG
579 LsSetupNsList (File);
580 LsDisplayNamespace ();
583 AcpiOsRedirectOutput (stdout);
586 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
587 AcpiGbl_ParseOpRoot = NULL;
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");
616 AcpiOsPrintf (ACPI_COMMON_HEADER ("AML Disassembler", " * "));
618 AcpiOsPrintf (" * 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)
647 * Print file header and dump original table header
649 AdDisassemblerHeader (Filename);
651 AcpiOsPrintf (" * Original Table Header:\n");
652 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
653 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
655 /* Print and validate the revision */
657 AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
659 switch (Table->Revision)
662 AcpiOsPrintf (" **** Invalid Revision");
666 /* Revision of DSDT controls the ACPI integer width */
668 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
670 AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
679 /* Print and validate the table checksum */
681 AcpiOsPrintf (" * Checksum 0x%2.2X", Table->Checksum);
683 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
686 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
687 (UINT8) (Table->Checksum - Checksum));
691 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
692 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
693 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
694 AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
695 AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
696 AcpiOsPrintf (" */\n\n");
698 /* Create AML output filename based on input filename */
702 NewFilename = FlGenerateFilename (Filename, "aml");
706 NewFilename = ACPI_ALLOCATE_ZEROED (9);
707 strncat (NewFilename, Table->Signature, 4);
708 strcat (NewFilename, ".aml");
711 /* Open the ASL definition block */
714 "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
715 NewFilename, Table->Signature, Table->Revision,
716 Table->OemId, Table->OemTableId, Table->OemRevision);
718 ACPI_FREE (NewFilename);
722 /******************************************************************************
724 * FUNCTION: AdDisplayTables
726 * PARAMETERS: Filename - Input file for the table
727 * Table - Pointer to the raw table
731 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
733 *****************************************************************************/
738 ACPI_TABLE_HEADER *Table)
742 if (!AcpiGbl_ParseOpRoot)
747 if (!AcpiGbl_DbOpt_verbose)
749 AdCreateTableHeader (Filename, Table);
752 AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
754 if (AcpiGbl_DbOpt_verbose)
756 AcpiOsPrintf ("\n\nTable Header:\n");
757 AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
758 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
760 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
761 AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
762 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
769 /******************************************************************************
771 * FUNCTION: AdDeferredParse
773 * PARAMETERS: Op - Root Op of the deferred opcode
774 * Aml - Pointer to the raw AML
775 * AmlLength - Length of the AML
779 * DESCRIPTION: Parse one deferred opcode
780 * (Methods, operation regions, etc.)
782 *****************************************************************************/
786 ACPI_PARSE_OBJECT *Op,
790 ACPI_WALK_STATE *WalkState;
792 ACPI_PARSE_OBJECT *SearchOp;
793 ACPI_PARSE_OBJECT *StartOp;
794 UINT32 BaseAmlOffset;
795 ACPI_PARSE_OBJECT *ExtraOp;
798 ACPI_FUNCTION_TRACE (AdDeferredParse);
801 fprintf (stderr, ".");
803 if (!Aml || !AmlLength)
805 return_ACPI_STATUS (AE_OK);
808 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
809 Op->Common.AmlOpName, (char *) &Op->Named.Name));
811 WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
814 return_ACPI_STATUS (AE_NO_MEMORY);
817 Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
818 AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
819 if (ACPI_FAILURE (Status))
821 return_ACPI_STATUS (Status);
824 /* Parse the method */
826 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
827 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
828 Status = AcpiPsParseAml (WalkState);
831 * We need to update all of the Aml offsets, since the parser thought
832 * that the method began at offset zero. In reality, it began somewhere
833 * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
834 * was just created and update the AmlOffset in each Op
836 BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
837 StartOp = (Op->Common.Value.Arg)->Common.Next;
840 /* Walk the parse tree */
844 SearchOp->Common.AmlOffset += BaseAmlOffset;
845 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
849 * Link the newly parsed subtree into the main parse tree
851 switch (Op->Common.AmlOpcode)
855 case AML_VAR_PACKAGE_OP:
857 switch (Op->Common.AmlOpcode)
860 ExtraOp = Op->Common.Value.Arg;
861 ExtraOp = ExtraOp->Common.Next;
862 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
865 case AML_VAR_PACKAGE_OP:
868 ExtraOp = Op->Common.Value.Arg;
869 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
873 /* Must point all parents to the main tree */
879 if (SearchOp->Common.Parent == ExtraOp)
881 SearchOp->Common.Parent = Op;
883 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
891 return_ACPI_STATUS (AE_OK);
895 /******************************************************************************
897 * FUNCTION: AdParseDeferredOps
899 * PARAMETERS: Root - Root of the parse tree
903 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
905 *****************************************************************************/
909 ACPI_PARSE_OBJECT *Root)
911 ACPI_PARSE_OBJECT *Op = Root;
912 ACPI_STATUS Status = AE_OK;
913 const ACPI_OPCODE_INFO *OpInfo;
916 ACPI_FUNCTION_NAME (AdParseDeferredOps);
917 fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
921 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
922 if (!(OpInfo->Flags & AML_DEFER))
924 Op = AcpiPsGetDepthNext (Root, Op);
928 switch (Op->Common.AmlOpcode)
933 case AML_VAR_PACKAGE_OP:
935 Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
936 if (ACPI_FAILURE (Status))
938 return_ACPI_STATUS (Status);
943 case AML_CREATE_QWORD_FIELD_OP:
944 case AML_CREATE_DWORD_FIELD_OP:
945 case AML_CREATE_WORD_FIELD_OP:
946 case AML_CREATE_BYTE_FIELD_OP:
947 case AML_CREATE_BIT_FIELD_OP:
948 case AML_CREATE_FIELD_OP:
949 case AML_BANK_FIELD_OP:
951 /* Nothing to do in these cases */
956 ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
957 Op->Common.AmlOpName));
961 Op = AcpiPsGetDepthNext (Root, Op);
964 fprintf (stderr, "\n");
969 /******************************************************************************
971 * FUNCTION: AdGetLocalTables
973 * PARAMETERS: Filename - Not used
974 * GetAllTables - TRUE if all tables are desired
978 * DESCRIPTION: Get the ACPI tables from either memory or a file
980 *****************************************************************************/
985 BOOLEAN GetAllTables)
988 ACPI_TABLE_HEADER TableHeader;
989 ACPI_TABLE_HEADER *NewTable;
997 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
998 AcpiOsTableOverride (&TableHeader, &NewTable);
1001 fprintf (stderr, "Could not obtain RSDT\n");
1002 return AE_NO_ACPI_TABLES;
1006 AdWriteTable (NewTable, NewTable->Length,
1007 ACPI_SIG_RSDT, NewTable->OemTableId);
1010 if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
1012 PointerSize = sizeof (UINT32);
1016 PointerSize = sizeof (UINT64);
1020 * Determine the number of tables pointed to by the RSDT/XSDT.
1021 * This is defined by the ACPI Specification to be the number of
1022 * pointers contained within the RSDT/XSDT. The size of the pointers
1023 * is architecture-dependent.
1025 NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
1026 AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n",
1027 NumTables, NewTable->Signature);
1031 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
1032 AcpiOsTableOverride (&TableHeader, &NewTable);
1035 AdWriteTable (NewTable, NewTable->Length,
1036 ACPI_SIG_FADT, NewTable->OemTableId);
1038 AcpiOsPrintf ("\n");
1040 /* Don't bother with FACS, it is usually all zeros */
1043 /* Always get the DSDT */
1045 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
1046 AcpiOsTableOverride (&TableHeader, &NewTable);
1049 AdWriteTable (NewTable, NewTable->Length,
1050 ACPI_SIG_DSDT, NewTable->OemTableId);
1052 /* Store DSDT in the Table Manager */
1054 Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
1056 if (ACPI_FAILURE (Status))
1058 fprintf (stderr, "Could not store DSDT\n");
1059 return AE_NO_ACPI_TABLES;
1064 fprintf (stderr, "Could not obtain DSDT\n");
1065 return AE_NO_ACPI_TABLES;
1069 /* TBD: Future implementation */
1071 AcpiOsPrintf ("\n");
1075 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
1079 Status = AcpiOsTableOverride (&TableHeader, &NewTable);
1088 /******************************************************************************
1090 * FUNCTION: AdParseTable
1092 * PARAMETERS: Table - Pointer to the raw table
1093 * OwnerId - Returned OwnerId of the table
1094 * LoadTable - If add table to the global table list
1095 * External - If this is an external table
1099 * DESCRIPTION: Parse the DSDT.
1101 *****************************************************************************/
1105 ACPI_TABLE_HEADER *Table,
1106 ACPI_OWNER_ID *OwnerId,
1110 ACPI_STATUS Status = AE_OK;
1111 ACPI_WALK_STATE *WalkState;
1119 return AE_NOT_EXIST;
1122 /* Pass 1: Parse everything except control method bodies */
1124 fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
1126 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
1127 AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
1129 /* Create the root object */
1131 AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
1132 if (!AcpiGbl_ParseOpRoot)
1134 return AE_NO_MEMORY;
1137 /* Create and initialize a new walk state */
1139 WalkState = AcpiDsCreateWalkState (0,
1140 AcpiGbl_ParseOpRoot, NULL, NULL);
1143 return (AE_NO_MEMORY);
1146 Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
1147 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
1148 if (ACPI_FAILURE (Status))
1153 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1154 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
1156 Status = AcpiPsParseAml (WalkState);
1157 if (ACPI_FAILURE (Status))
1162 /* If LoadTable is FALSE, we are parsing the last loaded table */
1164 TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
1170 Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
1171 Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
1172 if (ACPI_FAILURE (Status))
1176 Status = AcpiTbAllocateOwnerId (TableIndex);
1177 if (ACPI_FAILURE (Status))
1183 Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
1184 if (ACPI_FAILURE (Status))
1191 fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
1193 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
1194 if (ACPI_FAILURE (Status))
1199 /* No need to parse control methods of external table */
1206 /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
1208 Status = AdParseDeferredOps (AcpiGbl_ParseOpRoot);
1210 /* Process Resource Templates */
1212 AcpiDmFindResources (AcpiGbl_ParseOpRoot);
1214 fprintf (stderr, "Parsing completed\n");