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