No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / common / adisasm.c
blob8aaa3b4bb5310546a50fa5a3119a9947654fa291
1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "acpi.h"
118 #include "accommon.h"
119 #include "acparser.h"
120 #include "amlcode.h"
121 #include "acdebug.h"
122 #include "acdisasm.h"
123 #include "acdispat.h"
124 #include "acnamesp.h"
125 #include "actables.h"
126 #include "acapps.h"
128 #include <stdio.h>
129 #include <time.h>
132 #define _COMPONENT ACPI_TOOLS
133 ACPI_MODULE_NAME ("adisasm")
135 extern int AslCompilerdebug;
137 ACPI_STATUS
138 LsDisplayNamespace (
139 void);
141 void
142 LsSetupNsList (void * Handle);
145 /* Local prototypes */
147 void
148 AdCreateTableHeader (
149 char *Filename,
150 ACPI_TABLE_HEADER *Table);
152 void
153 AdDisassemblerHeader (
154 char *Filename);
156 void
157 AdAddExternalsToNamespace (
158 void);
160 UINT32
161 AdMethodExternalCount (
162 void);
164 ACPI_STATUS
165 AdDeferredParse (
166 ACPI_PARSE_OBJECT *Op,
167 UINT8 *Aml,
168 UINT32 AmlLength);
170 ACPI_STATUS
171 AdParseDeferredOps (
172 ACPI_PARSE_OBJECT *Root);
174 ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
177 /* Stubs for ASL compiler */
179 #ifndef ACPI_ASL_COMPILER
180 BOOLEAN
181 AcpiDsIsResultUsed (
182 ACPI_PARSE_OBJECT *Op,
183 ACPI_WALK_STATE *WalkState)
185 return TRUE;
188 ACPI_STATUS
189 AcpiDsMethodError (
190 ACPI_STATUS Status,
191 ACPI_WALK_STATE *WalkState)
193 return (Status);
196 #endif
198 ACPI_STATUS
199 AcpiNsLoadTable (
200 UINT32 TableIndex,
201 ACPI_NAMESPACE_NODE *Node)
203 return (AE_NOT_IMPLEMENTED);
206 ACPI_STATUS
207 AcpiDsRestartControlMethod (
208 ACPI_WALK_STATE *WalkState,
209 ACPI_OPERAND_OBJECT *ReturnDesc)
211 return (AE_OK);
214 void
215 AcpiDsTerminateControlMethod (
216 ACPI_OPERAND_OBJECT *MethodDesc,
217 ACPI_WALK_STATE *WalkState)
219 return;
222 ACPI_STATUS
223 AcpiDsCallControlMethod (
224 ACPI_THREAD_STATE *Thread,
225 ACPI_WALK_STATE *WalkState,
226 ACPI_PARSE_OBJECT *Op)
228 return (AE_OK);
231 ACPI_STATUS
232 AcpiDsMethodDataInitArgs (
233 ACPI_OPERAND_OBJECT **Params,
234 UINT32 MaxParamCount,
235 ACPI_WALK_STATE *WalkState)
237 return (AE_OK);
241 ACPI_TABLE_DESC LocalTables[1];
244 /*******************************************************************************
246 * FUNCTION: AdInitialize
248 * PARAMETERS: None.
250 * RETURN: Status
252 * DESCRIPTION: CA initialization
254 ******************************************************************************/
256 ACPI_STATUS
257 AdInitialize (
258 void)
260 ACPI_STATUS Status;
263 /* ACPI CA subsystem initialization */
265 Status = AcpiOsInitialize ();
266 if (ACPI_FAILURE (Status))
268 return (Status);
271 Status = AcpiUtInitGlobals ();
272 if (ACPI_FAILURE (Status))
274 return (Status);
277 Status = AcpiUtMutexInitialize ();
278 if (ACPI_FAILURE (Status))
280 return (Status);
283 Status = AcpiNsRootInitialize ();
284 if (ACPI_FAILURE (Status))
286 return (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;
295 return (Status);
299 /*******************************************************************************
301 * FUNCTION: AdAddExternalsToNamespace
303 * PARAMETERS:
305 * RETURN: None
307 * DESCRIPTION:
309 ******************************************************************************/
311 void
312 AdAddExternalsToNamespace (
313 void)
315 ACPI_STATUS Status;
316 ACPI_NAMESPACE_NODE *Node;
317 ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
318 ACPI_OPERAND_OBJECT *MethodDesc;
321 while (External)
323 Status = AcpiNsLookup (NULL, External->InternalPath, External->Type,
324 ACPI_IMODE_LOAD_PASS1, ACPI_NS_EXTERNAL | ACPI_NS_DONT_OPEN_SCOPE,
325 NULL, &Node);
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
343 * PARAMETERS: None
345 * RETURN: Status
347 * DESCRIPTION: Return the number of externals that have been generated
349 ******************************************************************************/
351 UINT32
352 AdMethodExternalCount (
353 void)
355 ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
356 UINT32 Count = 0;
359 while (External)
361 if (External->Type == ACPI_TYPE_METHOD)
363 Count++;
366 External = External->Next;
369 return (Count);
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
383 * RETURN: Status
385 * DESCRIPTION: Disassemble an entire ACPI table
387 *****************************************************************************/
389 extern char *Gbl_ExternalFilename;
391 ACPI_STATUS
392 AdAmlDisassemble (
393 BOOLEAN OutToFile,
394 char *Filename,
395 char *Prefix,
396 char **OutFilename,
397 BOOLEAN GetAllTables)
399 ACPI_STATUS Status;
400 char *DisasmFilename = NULL;
401 char *ExternalFilename;
402 FILE *File = NULL;
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)
413 if (Filename)
415 Status = AcpiDbGetTableFromFile (Filename, &Table);
416 if (ACPI_FAILURE (Status))
418 return 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))
434 return Status;
437 /* Load external table for symbol resolution */
439 if (ExternalTable)
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));
446 return 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;
474 else
476 Status = AdGetLocalTables (Filename, GetAllTables);
477 if (ACPI_FAILURE (Status))
479 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
480 AcpiFormatException (Status));
481 return Status;
484 if (!AcpiGbl_DbOpt_disasm)
486 return AE_OK;
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));
496 return Status;
499 AcpiOsPrintf ("\nDisassembly of DSDT\n");
500 Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
504 * Output: ASL code.
505 * Redirect to a file if requested
507 if (OutToFile)
509 /* Create/Open a disassembly output file */
511 DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
512 if (!OutFilename)
514 fprintf (stderr, "Could not generate output filename\n");
515 Status = AE_ERROR;
516 goto Cleanup;
519 File = fopen (DisasmFilename, "w+");
520 if (!File)
522 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
523 Status = AE_ERROR;
524 goto Cleanup;
527 AcpiOsRedirectOutput (File);
530 *OutFilename = DisasmFilename;
532 if (!AcpiUtIsAmlTable (Table))
534 AdDisassemblerHeader (Filename);
535 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
536 Table->Signature);
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);
543 else
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));
552 goto Cleanup;
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
590 * method)
592 if (AdMethodExternalCount ())
594 fprintf (stderr,
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));
623 goto Cleanup;
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);
642 fprintf (stderr,
643 "Disassembly completed, written to \"%s\"\n",
644 DisasmFilename);
648 Cleanup:
650 if (Table && !AcpiUtIsAmlTable (Table))
652 ACPI_FREE (Table);
655 if (DisasmFilename)
657 ACPI_FREE (DisasmFilename);
660 if (OutToFile && File)
663 #ifdef ASL_DISASM_DEBUG
664 LsSetupNsList (File);
665 LsDisplayNamespace ();
666 #endif
667 fclose (File);
668 AcpiOsRedirectOutput (stdout);
671 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
672 AcpiGbl_ParseOpRoot = NULL;
673 return (Status);
677 /******************************************************************************
679 * FUNCTION: AdDisassemblerHeader
681 * PARAMETERS: Filename - Input file for the table
683 * RETURN: None
685 * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
686 * current time and date.
688 *****************************************************************************/
690 void
691 AdDisassemblerHeader (
692 char *Filename)
694 time_t Timer;
696 time (&Timer);
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
715 * RETURN: None
717 * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
718 * current time and date.
720 *****************************************************************************/
722 void
723 AdCreateTableHeader (
724 char *Filename,
725 ACPI_TABLE_HEADER *Table)
727 char *NewFilename;
728 UINT8 Checksum;
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)
746 case 0:
747 AcpiOsPrintf (" **** Invalid Revision");
748 break;
750 case 1:
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");
757 break;
759 default:
760 break;
762 AcpiOsPrintf ("\n");
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);
769 if (Checksum)
771 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
772 (UINT8) (Table->Checksum - Checksum));
774 AcpiOsPrintf ("\n");
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 */
785 if (Filename)
787 NewFilename = FlGenerateFilename (Filename, "aml");
789 else
791 NewFilename = ACPI_ALLOCATE_ZEROED (9);
792 strncat (NewFilename, Table->Signature, 4);
793 strcat (NewFilename, ".aml");
796 /* Open the ASL definition block */
798 AcpiOsPrintf (
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
814 * RETURN: Status
816 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
818 *****************************************************************************/
820 ACPI_STATUS
821 AdDisplayTables (
822 char *Filename,
823 ACPI_TABLE_HEADER *Table)
827 if (!AcpiGbl_ParseOpRoot)
829 return AE_NOT_EXIST;
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);
850 return AE_OK;
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
862 * RETURN: Status
864 * DESCRIPTION: Parse one deferred opcode
865 * (Methods, operation regions, etc.)
867 *****************************************************************************/
869 ACPI_STATUS
870 AdDeferredParse (
871 ACPI_PARSE_OBJECT *Op,
872 UINT8 *Aml,
873 UINT32 AmlLength)
875 ACPI_WALK_STATE *WalkState;
876 ACPI_STATUS Status;
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);
897 if (!WalkState)
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;
923 SearchOp = StartOp;
925 /* Walk the parse tree */
927 while (SearchOp)
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)
938 case AML_BUFFER_OP:
939 case AML_PACKAGE_OP:
940 case AML_VAR_PACKAGE_OP:
942 switch (Op->Common.AmlOpcode)
944 case AML_PACKAGE_OP:
945 ExtraOp = Op->Common.Value.Arg;
946 ExtraOp = ExtraOp->Common.Next;
947 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
948 break;
950 case AML_VAR_PACKAGE_OP:
951 case AML_BUFFER_OP:
952 default:
953 ExtraOp = Op->Common.Value.Arg;
954 Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
955 break;
958 /* Must point all parents to the main tree */
960 StartOp = Op;
961 SearchOp = StartOp;
962 while (SearchOp)
964 if (SearchOp->Common.Parent == ExtraOp)
966 SearchOp->Common.Parent = Op;
968 SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
970 break;
972 default:
973 break;
976 return_ACPI_STATUS (AE_OK);
980 /******************************************************************************
982 * FUNCTION: AdParseDeferredOps
984 * PARAMETERS: Root - Root of the parse tree
986 * RETURN: Status
988 * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
990 *****************************************************************************/
992 ACPI_STATUS
993 AdParseDeferredOps (
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");
1004 while (Op)
1006 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
1007 if (!(OpInfo->Flags & AML_DEFER))
1009 Op = AcpiPsGetDepthNext (Root, Op);
1010 continue;
1013 switch (Op->Common.AmlOpcode)
1015 case AML_METHOD_OP:
1016 case AML_BUFFER_OP:
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);
1025 break;
1027 case AML_REGION_OP:
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 */
1038 break;
1040 default:
1041 ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
1042 Op->Common.AmlOpName));
1043 break;
1046 Op = AcpiPsGetDepthNext (Root, Op);
1049 fprintf (stderr, "\n");
1050 return Status;
1054 /******************************************************************************
1056 * FUNCTION: AdGetLocalTables
1058 * PARAMETERS: Filename - Not used
1059 * GetAllTables - TRUE if all tables are desired
1061 * RETURN: Status
1063 * DESCRIPTION: Get the ACPI tables from either memory or a file
1065 *****************************************************************************/
1067 ACPI_STATUS
1068 AdGetLocalTables (
1069 char *Filename,
1070 BOOLEAN GetAllTables)
1072 ACPI_STATUS Status;
1073 ACPI_TABLE_HEADER TableHeader;
1074 ACPI_TABLE_HEADER *NewTable;
1075 UINT32 NumTables;
1076 UINT32 PointerSize;
1077 UINT32 TableIndex;
1080 if (GetAllTables)
1082 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
1083 AcpiOsTableOverride (&TableHeader, &NewTable);
1084 if (!NewTable)
1086 fprintf (stderr, "Could not obtain RSDT\n");
1087 return AE_NO_ACPI_TABLES;
1089 else
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);
1099 else
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);
1114 /* Get the FADT */
1116 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
1117 AcpiOsTableOverride (&TableHeader, &NewTable);
1118 if (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);
1132 if (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,
1140 0, &TableIndex);
1142 else
1144 fprintf (stderr, "Could not obtain DSDT\n");
1145 return AE_NO_ACPI_TABLES;
1148 #if 0
1149 /* TBD: Future implementation */
1151 AcpiOsPrintf ("\n");
1153 /* Get all SSDTs */
1155 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
1158 NewTable = NULL;
1159 Status = AcpiOsTableOverride (&TableHeader, &NewTable);
1161 } while (NewTable);
1162 #endif
1164 return AE_OK;
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
1177 * RETURN: Status
1179 * DESCRIPTION: Parse the DSDT.
1181 *****************************************************************************/
1183 ACPI_STATUS
1184 AdParseTable (
1185 ACPI_TABLE_HEADER *Table,
1186 ACPI_OWNER_ID *OwnerId,
1187 BOOLEAN LoadTable,
1188 BOOLEAN External)
1190 ACPI_STATUS Status = AE_OK;
1191 ACPI_WALK_STATE *WalkState;
1192 UINT8 *AmlStart;
1193 UINT32 AmlLength;
1194 UINT32 TableIndex;
1197 if (!Table)
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);
1221 if (!WalkState)
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))
1230 return (Status);
1233 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1234 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
1236 Status = AcpiPsParseAml (WalkState);
1237 if (ACPI_FAILURE (Status))
1239 return Status;
1242 /* If LoadTable is FALSE, we are parsing the last loaded table */
1244 TableIndex = AcpiGbl_RootTableList.Count - 1;
1246 /* Pass 2 */
1248 if (LoadTable)
1250 Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
1251 Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
1252 if (ACPI_FAILURE (Status))
1254 return Status;
1256 Status = AcpiTbAllocateOwnerId (TableIndex);
1257 if (ACPI_FAILURE (Status))
1259 return Status;
1261 if (OwnerId)
1263 Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
1264 if (ACPI_FAILURE (Status))
1266 return 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))
1276 return (Status);
1279 /* No need to parse control methods of external table */
1281 if (External)
1283 return AE_OK;
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");
1295 return AE_OK;