1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, 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")
135 extern int AslCompilerdebug
;
142 LsSetupNsList (void * Handle
);
145 /* Local prototypes */
148 AdCreateTableHeader (
150 ACPI_TABLE_HEADER
*Table
);
153 AdDisassemblerHeader (
157 AdAddExternalsToNamespace (
161 AdMethodExternalCount (
166 ACPI_PARSE_OBJECT
*Op
,
172 ACPI_PARSE_OBJECT
*Root
);
174 ACPI_PARSE_OBJECT
*AcpiGbl_ParseOpRoot
;
177 /* Stubs for ASL compiler */
179 #ifndef ACPI_ASL_COMPILER
182 ACPI_PARSE_OBJECT
*Op
,
183 ACPI_WALK_STATE
*WalkState
)
191 ACPI_WALK_STATE
*WalkState
)
201 ACPI_NAMESPACE_NODE
*Node
)
203 return (AE_NOT_IMPLEMENTED
);
207 AcpiDsRestartControlMethod (
208 ACPI_WALK_STATE
*WalkState
,
209 ACPI_OPERAND_OBJECT
*ReturnDesc
)
215 AcpiDsTerminateControlMethod (
216 ACPI_OPERAND_OBJECT
*MethodDesc
,
217 ACPI_WALK_STATE
*WalkState
)
223 AcpiDsCallControlMethod (
224 ACPI_THREAD_STATE
*Thread
,
225 ACPI_WALK_STATE
*WalkState
,
226 ACPI_PARSE_OBJECT
*Op
)
232 AcpiDsMethodDataInitArgs (
233 ACPI_OPERAND_OBJECT
**Params
,
234 UINT32 MaxParamCount
,
235 ACPI_WALK_STATE
*WalkState
)
241 ACPI_TABLE_DESC LocalTables
[1];
244 /*******************************************************************************
246 * FUNCTION: AdInitialize
252 * DESCRIPTION: CA initialization
254 ******************************************************************************/
263 /* ACPI CA subsystem initialization */
265 Status
= AcpiOsInitialize ();
266 if (ACPI_FAILURE (Status
))
271 Status
= AcpiUtInitGlobals ();
272 if (ACPI_FAILURE (Status
))
277 Status
= AcpiUtMutexInitialize ();
278 if (ACPI_FAILURE (Status
))
283 Status
= AcpiNsRootInitialize ();
284 if (ACPI_FAILURE (Status
))
289 /* Setup the Table Manager (cheat - there is no RSDT) */
291 AcpiGbl_RootTableList
.Size
= 1;
292 AcpiGbl_RootTableList
.Count
= 0;
293 AcpiGbl_RootTableList
.Tables
= LocalTables
;
299 /*******************************************************************************
301 * FUNCTION: AdAddExternalsToNamespace
309 ******************************************************************************/
312 AdAddExternalsToNamespace (
316 ACPI_NAMESPACE_NODE
*Node
;
317 ACPI_EXTERNAL_LIST
*External
= AcpiGbl_ExternalList
;
318 ACPI_OPERAND_OBJECT
*MethodDesc
;
323 Status
= AcpiNsLookup (NULL
, External
->InternalPath
, External
->Type
,
324 ACPI_IMODE_LOAD_PASS1
, ACPI_NS_EXTERNAL
| ACPI_NS_DONT_OPEN_SCOPE
,
327 if (External
->Type
== ACPI_TYPE_METHOD
)
329 MethodDesc
= AcpiUtCreateInternalObject (ACPI_TYPE_METHOD
);
330 MethodDesc
->Method
.ParamCount
= (UINT8
) External
->Value
;
331 Node
->Object
= MethodDesc
;
334 External
= External
->Next
;
339 /*******************************************************************************
341 * FUNCTION: AdMethodExternalCount
347 * DESCRIPTION: Return the number of externals that have been generated
349 ******************************************************************************/
352 AdMethodExternalCount (
355 ACPI_EXTERNAL_LIST
*External
= AcpiGbl_ExternalList
;
361 if (External
->Type
== ACPI_TYPE_METHOD
)
366 External
= External
->Next
;
373 /******************************************************************************
375 * FUNCTION: AdAmlDisassemble
377 * PARAMETERS: Filename - AML input filename
378 * OutToFile - TRUE if output should go to a file
379 * Prefix - Path prefix for output
380 * OutFilename - where the filename is returned
381 * GetAllTables - TRUE if all tables are desired
385 * DESCRIPTION: Disassemble an entire ACPI table
387 *****************************************************************************/
389 extern char *Gbl_ExternalFilename
;
397 BOOLEAN GetAllTables
)
400 char *DisasmFilename
= NULL
;
401 char *ExternalFilename
;
403 ACPI_TABLE_HEADER
*Table
= NULL
;
404 ACPI_TABLE_HEADER
*ExternalTable
;
405 ACPI_OWNER_ID OwnerId
;
406 ACPI_EXTERNAL_LIST
*NextExternal
;
410 * Input: AML Code from either a file,
411 * or via GetTables (memory or registry)
415 Status
= AcpiDbGetTableFromFile (Filename
, &Table
);
416 if (ACPI_FAILURE (Status
))
422 * External filenames separated by commas
423 * Example: iasl -e file1,file2,file3 -d xxx.aml
425 if (Gbl_ExternalFilename
)
427 ExternalFilename
= strtok (Gbl_ExternalFilename
, ",");
429 while (ExternalFilename
)
431 Status
= AcpiDbGetTableFromFile (ExternalFilename
, &ExternalTable
);
432 if (ACPI_FAILURE (Status
))
437 /* Load external table for symbol resolution */
441 Status
= AdParseTable (ExternalTable
, &OwnerId
, TRUE
, TRUE
);
442 if (ACPI_FAILURE (Status
))
444 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
445 AcpiFormatException (Status
));
450 * Load namespace from names created within control methods
451 * Set owner id of nodes in external table
453 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot
,
454 AcpiGbl_RootNode
, OwnerId
);
455 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot
);
458 /* Next external file name */
460 ExternalFilename
= strtok (NULL
, ",");
463 /* Clear external list generated by Scope in external tables */
465 while (AcpiGbl_ExternalList
)
467 NextExternal
= AcpiGbl_ExternalList
->Next
;
468 ACPI_FREE (AcpiGbl_ExternalList
->Path
);
469 ACPI_FREE (AcpiGbl_ExternalList
);
470 AcpiGbl_ExternalList
= NextExternal
;
476 Status
= AdGetLocalTables (Filename
, GetAllTables
);
477 if (ACPI_FAILURE (Status
))
479 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
480 AcpiFormatException (Status
));
484 if (!AcpiGbl_DbOpt_disasm
)
489 /* Obtained the local tables, just disassemble the DSDT */
491 Status
= AcpiGetTable (ACPI_SIG_DSDT
, 0, &Table
);
492 if (ACPI_FAILURE (Status
))
494 AcpiOsPrintf ("Could not get DSDT, %s\n",
495 AcpiFormatException (Status
));
499 AcpiOsPrintf ("\nDisassembly of DSDT\n");
500 Prefix
= AdGenerateFilename ("dsdt", Table
->OemTableId
);
505 * Redirect to a file if requested
509 /* Create/Open a disassembly output file */
511 DisasmFilename
= FlGenerateFilename (Prefix
, FILE_SUFFIX_DISASSEMBLY
);
514 fprintf (stderr
, "Could not generate output filename\n");
519 File
= fopen (DisasmFilename
, "w+");
522 fprintf (stderr
, "Could not open output file %s\n", DisasmFilename
);
527 AcpiOsRedirectOutput (File
);
530 *OutFilename
= DisasmFilename
;
532 if (!AcpiUtIsAmlTable (Table
))
534 AdDisassemblerHeader (Filename
);
535 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
537 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue\n */\n\n");
539 AcpiDmDumpDataTable (Table
);
540 fprintf (stderr
, "Acpi Data Table [%4.4s] decoded, written to \"%s\"\n",
541 Table
->Signature
, DisasmFilename
);
545 /* Always parse the tables, only option is what to display */
547 Status
= AdParseTable (Table
, &OwnerId
, TRUE
, FALSE
);
548 if (ACPI_FAILURE (Status
))
550 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
551 AcpiFormatException (Status
));
555 if (AslCompilerdebug
)
557 AcpiOsPrintf ("/**** Before second load\n");
559 LsSetupNsList (File
);
560 LsDisplayNamespace ();
561 AcpiOsPrintf ("*****/\n");
565 * Load namespace from names created within control methods
567 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot
, AcpiGbl_RootNode
, OwnerId
);
570 * Cross reference the namespace here, in order to generate External() statements
572 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot
, AcpiGbl_RootNode
, OwnerId
);
574 if (AslCompilerdebug
)
576 AcpiDmDumpTree (AcpiGbl_ParseOpRoot
);
579 /* Find possible calls to external control methods */
581 AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot
);
583 /* Convert fixed-offset references to resource descriptors to symbolic references */
585 AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot
, AcpiGbl_RootNode
);
588 * If we found any external control methods, we must reparse the entire
589 * tree with the new information (namely, the number of arguments per
592 if (AdMethodExternalCount ())
595 "\nFound %d external control methods, reparsing with new information\n",
596 AdMethodExternalCount());
599 * Reparse, rebuild namespace. no need to xref namespace
601 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot
);
602 AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode
);
604 AcpiGbl_RootNode
= NULL
;
605 AcpiGbl_RootNodeStruct
.Name
.Integer
= ACPI_ROOT_NAME
;
606 AcpiGbl_RootNodeStruct
.DescriptorType
= ACPI_DESC_TYPE_NAMED
;
607 AcpiGbl_RootNodeStruct
.Type
= ACPI_TYPE_DEVICE
;
608 AcpiGbl_RootNodeStruct
.Child
= NULL
;
609 AcpiGbl_RootNodeStruct
.Peer
= NULL
;
610 AcpiGbl_RootNodeStruct
.Object
= NULL
;
611 AcpiGbl_RootNodeStruct
.Flags
= ANOBJ_END_OF_PEER_LIST
;
613 Status
= AcpiNsRootInitialize ();
614 AdAddExternalsToNamespace ();
616 /* Parse table. No need to reload it, however (FALSE) */
618 Status
= AdParseTable (Table
, NULL
, FALSE
, FALSE
);
619 if (ACPI_FAILURE (Status
))
621 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
622 AcpiFormatException (Status
));
626 if (AslCompilerdebug
)
628 AcpiOsPrintf ("/**** After second load and resource conversion\n");
629 LsSetupNsList (File
);
630 LsDisplayNamespace ();
631 AcpiOsPrintf ("*****/\n");
633 AcpiDmDumpTree (AcpiGbl_ParseOpRoot
);
637 /* Optional displays */
639 if (AcpiGbl_DbOpt_disasm
)
641 AdDisplayTables (Filename
, Table
);
643 "Disassembly completed, written to \"%s\"\n",
650 if (Table
&& !AcpiUtIsAmlTable (Table
))
657 ACPI_FREE (DisasmFilename
);
660 if (OutToFile
&& File
)
663 #ifdef ASL_DISASM_DEBUG
664 LsSetupNsList (File
);
665 LsDisplayNamespace ();
668 AcpiOsRedirectOutput (stdout
);
671 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot
);
672 AcpiGbl_ParseOpRoot
= NULL
;
677 /******************************************************************************
679 * FUNCTION: AdDisassemblerHeader
681 * PARAMETERS: Filename - Input file for the table
685 * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
686 * current time and date.
688 *****************************************************************************/
691 AdDisassemblerHeader (
698 /* Header and input table info */
700 AcpiOsPrintf ("/*\n * Intel ACPI Component Architecture\n");
701 AcpiOsPrintf (" * AML Disassembler version %8.8X\n", ACPI_CA_VERSION
);
703 AcpiOsPrintf (" *\n * Disassembly of %s, %s", Filename
, ctime (&Timer
));
704 AcpiOsPrintf (" *\n");
708 /******************************************************************************
710 * FUNCTION: AdCreateTableHeader
712 * PARAMETERS: Filename - Input file for the table
713 * Table - Pointer to the raw table
717 * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
718 * current time and date.
720 *****************************************************************************/
723 AdCreateTableHeader (
725 ACPI_TABLE_HEADER
*Table
)
732 * Print file header and dump original table header
734 AdDisassemblerHeader (Filename
);
736 AcpiOsPrintf (" *\n * Original Table Header:\n");
737 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table
->Signature
);
738 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table
->Length
, Table
->Length
);
740 /* Print and validate the revision */
742 AcpiOsPrintf (" * Revision 0x%2.2X", Table
->Revision
);
744 switch (Table
->Revision
)
747 AcpiOsPrintf (" **** Invalid Revision");
751 /* Revision of DSDT controls the ACPI integer width */
753 if (ACPI_COMPARE_NAME (Table
->Signature
, ACPI_SIG_DSDT
))
755 AcpiOsPrintf (" **** ACPI 1.0, no 64-bit math support");
764 /* Print and validate the table checksum */
766 AcpiOsPrintf (" * Checksum 0x%2.2X", Table
->Checksum
);
768 Checksum
= AcpiTbChecksum (ACPI_CAST_PTR (UINT8
, Table
), Table
->Length
);
771 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
772 (UINT8
) (Table
->Checksum
- Checksum
));
776 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table
->OemId
);
777 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table
->OemTableId
);
778 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table
->OemRevision
, Table
->OemRevision
);
779 AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table
->AslCompilerId
);
780 AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table
->AslCompilerRevision
, Table
->AslCompilerRevision
);
781 AcpiOsPrintf (" */\n");
783 /* Create AML output filename based on input filename */
787 NewFilename
= FlGenerateFilename (Filename
, "aml");
791 NewFilename
= ACPI_ALLOCATE_ZEROED (9);
792 strncat (NewFilename
, Table
->Signature
, 4);
793 strcat (NewFilename
, ".aml");
796 /* Open the ASL definition block */
799 "DefinitionBlock (\"%s\", \"%4.4s\", %hd, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
800 NewFilename
, Table
->Signature
, Table
->Revision
,
801 Table
->OemId
, Table
->OemTableId
, Table
->OemRevision
);
803 ACPI_FREE (NewFilename
);
807 /******************************************************************************
809 * FUNCTION: AdDisplayTables
811 * PARAMETERS: Filename - Input file for the table
812 * Table - Pointer to the raw table
816 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
818 *****************************************************************************/
823 ACPI_TABLE_HEADER
*Table
)
827 if (!AcpiGbl_ParseOpRoot
)
832 if (!AcpiGbl_DbOpt_verbose
)
834 AdCreateTableHeader (Filename
, Table
);
837 AcpiDmDisassemble (NULL
, AcpiGbl_ParseOpRoot
, ACPI_UINT32_MAX
);
839 if (AcpiGbl_DbOpt_verbose
)
841 AcpiOsPrintf ("\n\nTable Header:\n");
842 AcpiUtDumpBuffer ((UINT8
*) Table
, sizeof (ACPI_TABLE_HEADER
),
843 DB_BYTE_DISPLAY
, ACPI_UINT32_MAX
);
845 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table
->Length
);
846 AcpiUtDumpBuffer (((UINT8
*) Table
+ sizeof (ACPI_TABLE_HEADER
)), Table
->Length
,
847 DB_BYTE_DISPLAY
, ACPI_UINT32_MAX
);
854 /******************************************************************************
856 * FUNCTION: AdDeferredParse
858 * PARAMETERS: Op - Root Op of the deferred opcode
859 * Aml - Pointer to the raw AML
860 * AmlLength - Length of the AML
864 * DESCRIPTION: Parse one deferred opcode
865 * (Methods, operation regions, etc.)
867 *****************************************************************************/
871 ACPI_PARSE_OBJECT
*Op
,
875 ACPI_WALK_STATE
*WalkState
;
877 ACPI_PARSE_OBJECT
*SearchOp
;
878 ACPI_PARSE_OBJECT
*StartOp
;
879 UINT32 BaseAmlOffset
;
880 ACPI_PARSE_OBJECT
*ExtraOp
;
883 ACPI_FUNCTION_TRACE (AdDeferredParse
);
886 fprintf (stderr
, ".");
888 if (!Aml
|| !AmlLength
)
890 return_ACPI_STATUS (AE_OK
);
893 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "Parsing %s [%4.4s]\n",
894 Op
->Common
.AmlOpName
, (char *) &Op
->Named
.Name
));
896 WalkState
= AcpiDsCreateWalkState (0, Op
, NULL
, NULL
);
899 return_ACPI_STATUS (AE_NO_MEMORY
);
902 Status
= AcpiDsInitAmlWalk (WalkState
, Op
, NULL
, Aml
,
903 AmlLength
, NULL
, ACPI_IMODE_LOAD_PASS1
);
904 if (ACPI_FAILURE (Status
))
906 return_ACPI_STATUS (Status
);
909 /* Parse the method */
911 WalkState
->ParseFlags
&= ~ACPI_PARSE_DELETE_TREE
;
912 WalkState
->ParseFlags
|= ACPI_PARSE_DISASSEMBLE
;
913 Status
= AcpiPsParseAml (WalkState
);
916 * We need to update all of the Aml offsets, since the parser thought
917 * that the method began at offset zero. In reality, it began somewhere
918 * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
919 * was just created and update the AmlOffset in each Op
921 BaseAmlOffset
= (Op
->Common
.Value
.Arg
)->Common
.AmlOffset
+ 1;
922 StartOp
= (Op
->Common
.Value
.Arg
)->Common
.Next
;
925 /* Walk the parse tree */
929 SearchOp
->Common
.AmlOffset
+= BaseAmlOffset
;
930 SearchOp
= AcpiPsGetDepthNext (StartOp
, SearchOp
);
934 * Link the newly parsed subtree into the main parse tree
936 switch (Op
->Common
.AmlOpcode
)
940 case AML_VAR_PACKAGE_OP
:
942 switch (Op
->Common
.AmlOpcode
)
945 ExtraOp
= Op
->Common
.Value
.Arg
;
946 ExtraOp
= ExtraOp
->Common
.Next
;
947 Op
->Common
.Value
.Arg
= ExtraOp
->Common
.Value
.Arg
;
950 case AML_VAR_PACKAGE_OP
:
953 ExtraOp
= Op
->Common
.Value
.Arg
;
954 Op
->Common
.Value
.Arg
= ExtraOp
->Common
.Value
.Arg
;
958 /* Must point all parents to the main tree */
964 if (SearchOp
->Common
.Parent
== ExtraOp
)
966 SearchOp
->Common
.Parent
= Op
;
968 SearchOp
= AcpiPsGetDepthNext (StartOp
, SearchOp
);
976 return_ACPI_STATUS (AE_OK
);
980 /******************************************************************************
982 * FUNCTION: AdParseDeferredOps
984 * PARAMETERS: Root - Root of the parse tree
988 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
990 *****************************************************************************/
994 ACPI_PARSE_OBJECT
*Root
)
996 ACPI_PARSE_OBJECT
*Op
= Root
;
997 ACPI_STATUS Status
= AE_OK
;
998 const ACPI_OPCODE_INFO
*OpInfo
;
1001 ACPI_FUNCTION_NAME (AdParseDeferredOps
);
1002 fprintf (stderr
, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
1006 OpInfo
= AcpiPsGetOpcodeInfo (Op
->Common
.AmlOpcode
);
1007 if (!(OpInfo
->Flags
& AML_DEFER
))
1009 Op
= AcpiPsGetDepthNext (Root
, Op
);
1013 switch (Op
->Common
.AmlOpcode
)
1017 case AML_PACKAGE_OP
:
1018 case AML_VAR_PACKAGE_OP
:
1020 Status
= AdDeferredParse (Op
, Op
->Named
.Data
, Op
->Named
.Length
);
1021 if (ACPI_FAILURE (Status
))
1023 return_ACPI_STATUS (Status
);
1028 case AML_CREATE_QWORD_FIELD_OP
:
1029 case AML_CREATE_DWORD_FIELD_OP
:
1030 case AML_CREATE_WORD_FIELD_OP
:
1031 case AML_CREATE_BYTE_FIELD_OP
:
1032 case AML_CREATE_BIT_FIELD_OP
:
1033 case AML_CREATE_FIELD_OP
:
1034 case AML_BANK_FIELD_OP
:
1036 /* Nothing to do in these cases */
1041 ACPI_ERROR ((AE_INFO
, "Unhandled deferred opcode [%s]",
1042 Op
->Common
.AmlOpName
));
1046 Op
= AcpiPsGetDepthNext (Root
, Op
);
1049 fprintf (stderr
, "\n");
1054 /******************************************************************************
1056 * FUNCTION: AdGetLocalTables
1058 * PARAMETERS: Filename - Not used
1059 * GetAllTables - TRUE if all tables are desired
1063 * DESCRIPTION: Get the ACPI tables from either memory or a file
1065 *****************************************************************************/
1070 BOOLEAN GetAllTables
)
1073 ACPI_TABLE_HEADER TableHeader
;
1074 ACPI_TABLE_HEADER
*NewTable
;
1082 ACPI_MOVE_32_TO_32 (TableHeader
.Signature
, ACPI_SIG_RSDT
);
1083 AcpiOsTableOverride (&TableHeader
, &NewTable
);
1086 fprintf (stderr
, "Could not obtain RSDT\n");
1087 return AE_NO_ACPI_TABLES
;
1091 AdWriteTable (NewTable
, NewTable
->Length
,
1092 ACPI_SIG_RSDT
, NewTable
->OemTableId
);
1095 if (ACPI_COMPARE_NAME (NewTable
->Signature
, ACPI_SIG_RSDT
))
1097 PointerSize
= sizeof (UINT32
);
1101 PointerSize
= sizeof (UINT64
);
1105 * Determine the number of tables pointed to by the RSDT/XSDT.
1106 * This is defined by the ACPI Specification to be the number of
1107 * pointers contained within the RSDT/XSDT. The size of the pointers
1108 * is architecture-dependent.
1110 NumTables
= (NewTable
->Length
- sizeof (ACPI_TABLE_HEADER
)) / PointerSize
;
1111 AcpiOsPrintf ("There are %d tables defined in the %4.4s\n\n",
1112 NumTables
, NewTable
->Signature
);
1116 ACPI_MOVE_32_TO_32 (TableHeader
.Signature
, ACPI_SIG_FADT
);
1117 AcpiOsTableOverride (&TableHeader
, &NewTable
);
1120 AdWriteTable (NewTable
, NewTable
->Length
,
1121 ACPI_SIG_FADT
, NewTable
->OemTableId
);
1123 AcpiOsPrintf ("\n");
1125 /* Don't bother with FACS, it is usually all zeros */
1128 /* Always get the DSDT */
1130 ACPI_MOVE_32_TO_32 (TableHeader
.Signature
, ACPI_SIG_DSDT
);
1131 AcpiOsTableOverride (&TableHeader
, &NewTable
);
1134 AdWriteTable (NewTable
, NewTable
->Length
,
1135 ACPI_SIG_DSDT
, NewTable
->OemTableId
);
1137 /* Store DSDT in the Table Manager */
1139 Status
= AcpiTbStoreTable (0, NewTable
, NewTable
->Length
,
1144 fprintf (stderr
, "Could not obtain DSDT\n");
1145 return AE_NO_ACPI_TABLES
;
1149 /* TBD: Future implementation */
1151 AcpiOsPrintf ("\n");
1155 ACPI_MOVE_32_TO_32 (TableHeader
.Signature
, ACPI_SIG_SSDT
);
1159 Status
= AcpiOsTableOverride (&TableHeader
, &NewTable
);
1168 /******************************************************************************
1170 * FUNCTION: AdParseTable
1172 * PARAMETERS: Table - Pointer to the raw table
1173 * OwnerId - Returned OwnerId of the table
1174 * LoadTable - If add table to the global table list
1175 * External - If this is an external table
1179 * DESCRIPTION: Parse the DSDT.
1181 *****************************************************************************/
1185 ACPI_TABLE_HEADER
*Table
,
1186 ACPI_OWNER_ID
*OwnerId
,
1190 ACPI_STATUS Status
= AE_OK
;
1191 ACPI_WALK_STATE
*WalkState
;
1199 return AE_NOT_EXIST
;
1202 /* Pass 1: Parse everything except control method bodies */
1204 fprintf (stderr
, "Pass 1 parse of [%4.4s]\n", (char *) Table
->Signature
);
1206 AmlLength
= Table
->Length
- sizeof (ACPI_TABLE_HEADER
);
1207 AmlStart
= ((UINT8
*) Table
+ sizeof (ACPI_TABLE_HEADER
));
1209 /* Create the root object */
1211 AcpiGbl_ParseOpRoot
= AcpiPsCreateScopeOp ();
1212 if (!AcpiGbl_ParseOpRoot
)
1214 return AE_NO_MEMORY
;
1217 /* Create and initialize a new walk state */
1219 WalkState
= AcpiDsCreateWalkState (0,
1220 AcpiGbl_ParseOpRoot
, NULL
, NULL
);
1223 return (AE_NO_MEMORY
);
1226 Status
= AcpiDsInitAmlWalk (WalkState
, AcpiGbl_ParseOpRoot
,
1227 NULL
, AmlStart
, AmlLength
, NULL
, ACPI_IMODE_LOAD_PASS1
);
1228 if (ACPI_FAILURE (Status
))
1233 WalkState
->ParseFlags
&= ~ACPI_PARSE_DELETE_TREE
;
1234 WalkState
->ParseFlags
|= ACPI_PARSE_DISASSEMBLE
;
1236 Status
= AcpiPsParseAml (WalkState
);
1237 if (ACPI_FAILURE (Status
))
1242 /* If LoadTable is FALSE, we are parsing the last loaded table */
1244 TableIndex
= AcpiGbl_RootTableList
.Count
- 1;
1250 Status
= AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS
) Table
, Table
,
1251 Table
->Length
, ACPI_TABLE_ORIGIN_ALLOCATED
, &TableIndex
);
1252 if (ACPI_FAILURE (Status
))
1256 Status
= AcpiTbAllocateOwnerId (TableIndex
);
1257 if (ACPI_FAILURE (Status
))
1263 Status
= AcpiTbGetOwnerId (TableIndex
, OwnerId
);
1264 if (ACPI_FAILURE (Status
))
1271 fprintf (stderr
, "Pass 2 parse of [%4.4s]\n", (char *) Table
->Signature
);
1273 Status
= AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2
, TableIndex
, NULL
);
1274 if (ACPI_FAILURE (Status
))
1279 /* No need to parse control methods of external table */
1286 /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
1288 Status
= AdParseDeferredOps (AcpiGbl_ParseOpRoot
);
1290 /* Process Resource Templates */
1292 AcpiDmFindResources (AcpiGbl_ParseOpRoot
);
1294 fprintf (stderr
, "Parsing completed\n");