Indentation fix, cleanup.
[AROS.git] / arch / all-pc / acpica / source / common / adisasm.c
blob582761df3fb5e2c4a9179dc051fb59d6aacd654e
1 /******************************************************************************
3 * Module Name: adisasm - Application-level disassembler routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include "acpi.h"
46 #include "accommon.h"
47 #include "acparser.h"
48 #include "amlcode.h"
49 #include "acdebug.h"
50 #include "acdisasm.h"
51 #include "acdispat.h"
52 #include "acnamesp.h"
53 #include "actables.h"
54 #include "acapps.h"
56 #include <stdio.h>
57 #include <time.h>
60 #define _COMPONENT ACPI_TOOLS
61 ACPI_MODULE_NAME ("adisasm")
64 * Older versions of Bison won't emit this external in the generated header.
65 * Newer versions do emit the external, so we don't need to do it.
67 #ifndef ASLCOMPILER_ASLCOMPILERPARSE_H
68 extern int AslCompilerdebug;
69 #endif
71 ACPI_STATUS
72 NsDisplayNamespace (
73 void);
75 void
76 NsSetupNamespaceListing (
77 void *Handle);
80 /* Local prototypes */
82 static UINT32
83 AdGetFileSize (
84 FILE *File);
86 static void
87 AdCreateTableHeader (
88 char *Filename,
89 ACPI_TABLE_HEADER *Table);
91 /* Stubs for ASL compiler */
93 #ifndef ACPI_ASL_COMPILER
94 BOOLEAN
95 AcpiDsIsResultUsed (
96 ACPI_PARSE_OBJECT *Op,
97 ACPI_WALK_STATE *WalkState)
99 return TRUE;
102 ACPI_STATUS
103 AcpiDsMethodError (
104 ACPI_STATUS Status,
105 ACPI_WALK_STATE *WalkState)
107 return (Status);
109 #endif
111 ACPI_STATUS
112 AcpiNsLoadTable (
113 UINT32 TableIndex,
114 ACPI_NAMESPACE_NODE *Node)
116 return (AE_NOT_IMPLEMENTED);
119 ACPI_STATUS
120 AcpiDsRestartControlMethod (
121 ACPI_WALK_STATE *WalkState,
122 ACPI_OPERAND_OBJECT *ReturnDesc)
124 return (AE_OK);
127 void
128 AcpiDsTerminateControlMethod (
129 ACPI_OPERAND_OBJECT *MethodDesc,
130 ACPI_WALK_STATE *WalkState)
132 return;
135 ACPI_STATUS
136 AcpiDsCallControlMethod (
137 ACPI_THREAD_STATE *Thread,
138 ACPI_WALK_STATE *WalkState,
139 ACPI_PARSE_OBJECT *Op)
141 return (AE_OK);
144 ACPI_STATUS
145 AcpiDsMethodDataInitArgs (
146 ACPI_OPERAND_OBJECT **Params,
147 UINT32 MaxParamCount,
148 ACPI_WALK_STATE *WalkState)
150 return (AE_OK);
154 static ACPI_TABLE_DESC LocalTables[1];
155 static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
158 /*******************************************************************************
160 * FUNCTION: AdGetFileSize
162 * PARAMETERS: File - Open file handle
164 * RETURN: File Size
166 * DESCRIPTION: Get current file size. Uses seek-to-EOF. File must be open.
168 ******************************************************************************/
170 static UINT32
171 AdGetFileSize (
172 FILE *File)
174 UINT32 FileSize;
175 long Offset;
178 Offset = ftell (File);
180 fseek (File, 0, SEEK_END);
181 FileSize = (UINT32) ftell (File);
183 /* Restore file pointer */
185 fseek (File, Offset, SEEK_SET);
186 return (FileSize);
190 /*******************************************************************************
192 * FUNCTION: AdInitialize
194 * PARAMETERS: None
196 * RETURN: Status
198 * DESCRIPTION: ACPICA and local initialization
200 ******************************************************************************/
202 ACPI_STATUS
203 AdInitialize (
204 void)
206 ACPI_STATUS Status;
209 /* ACPI CA subsystem initialization */
211 Status = AcpiOsInitialize ();
212 if (ACPI_FAILURE (Status))
214 return (Status);
217 Status = AcpiUtInitGlobals ();
218 if (ACPI_FAILURE (Status))
220 return (Status);
223 Status = AcpiUtMutexInitialize ();
224 if (ACPI_FAILURE (Status))
226 return (Status);
229 Status = AcpiNsRootInitialize ();
230 if (ACPI_FAILURE (Status))
232 return (Status);
235 /* Setup the Table Manager (cheat - there is no RSDT) */
237 AcpiGbl_RootTableList.MaxTableCount = 1;
238 AcpiGbl_RootTableList.CurrentTableCount = 0;
239 AcpiGbl_RootTableList.Tables = LocalTables;
241 return (Status);
245 /******************************************************************************
247 * FUNCTION: AdAmlDisassemble
249 * PARAMETERS: Filename - AML input filename
250 * OutToFile - TRUE if output should go to a file
251 * Prefix - Path prefix for output
252 * OutFilename - where the filename is returned
253 * GetAllTables - TRUE if all tables are desired
255 * RETURN: Status
257 * DESCRIPTION: Disassemble an entire ACPI table
259 *****************************************************************************/
261 ACPI_STATUS
262 AdAmlDisassemble (
263 BOOLEAN OutToFile,
264 char *Filename,
265 char *Prefix,
266 char **OutFilename,
267 BOOLEAN GetAllTables)
269 ACPI_STATUS Status;
270 char *DisasmFilename = NULL;
271 char *ExternalFilename;
272 ACPI_EXTERNAL_FILE *ExternalFileList = AcpiGbl_ExternalFileList;
273 FILE *File = NULL;
274 ACPI_TABLE_HEADER *Table = NULL;
275 ACPI_TABLE_HEADER *ExternalTable;
276 ACPI_OWNER_ID OwnerId;
280 * Input: AML code from either a file or via GetTables (memory or
281 * registry)
283 if (Filename)
285 Status = AcpiDbGetTableFromFile (Filename, &Table);
286 if (ACPI_FAILURE (Status))
288 return (Status);
292 * External filenames separated by commas
293 * Example: iasl -e file1,file2,file3 -d xxx.aml
295 while (ExternalFileList)
297 ExternalFilename = ExternalFileList->Path;
298 if (!ACPI_STRCMP (ExternalFilename, Filename))
300 /* Next external file */
302 ExternalFileList = ExternalFileList->Next;
303 continue;
306 Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
307 if (ACPI_FAILURE (Status))
309 return (Status);
312 /* Load external table for symbol resolution */
314 if (ExternalTable)
316 Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
317 if (ACPI_FAILURE (Status))
319 AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
320 AcpiFormatException (Status));
321 return (Status);
325 * Load namespace from names created within control methods
326 * Set owner id of nodes in external table
328 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
329 AcpiGbl_RootNode, OwnerId);
330 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
333 /* Next external file */
335 ExternalFileList = ExternalFileList->Next;
338 /* Clear external list generated by Scope in external tables */
340 if (AcpiGbl_ExternalFileList)
342 AcpiDmClearExternalList ();
345 /* Load any externals defined in the optional external ref file */
347 AcpiDmGetExternalsFromFile ();
349 else
351 Status = AdGetLocalTables (Filename, GetAllTables);
352 if (ACPI_FAILURE (Status))
354 AcpiOsPrintf ("Could not get ACPI tables, %s\n",
355 AcpiFormatException (Status));
356 return (Status);
359 if (!AcpiGbl_DbOpt_disasm)
361 return (AE_OK);
364 /* Obtained the local tables, just disassemble the DSDT */
366 Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
367 if (ACPI_FAILURE (Status))
369 AcpiOsPrintf ("Could not get DSDT, %s\n",
370 AcpiFormatException (Status));
371 return (Status);
374 AcpiOsPrintf ("\nDisassembly of DSDT\n");
375 Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
379 * Output: ASL code. Redirect to a file if requested
381 if (OutToFile)
383 /* Create/Open a disassembly output file */
385 DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
386 if (!OutFilename)
388 fprintf (stderr, "Could not generate output filename\n");
389 Status = AE_ERROR;
390 goto Cleanup;
393 File = fopen (DisasmFilename, "w+");
394 if (!File)
396 fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
397 Status = AE_ERROR;
398 goto Cleanup;
401 AcpiOsRedirectOutput (File);
404 *OutFilename = DisasmFilename;
406 if (!AcpiUtIsAmlTable (Table))
408 AdDisassemblerHeader (Filename);
409 AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
410 Table->Signature);
411 AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] "
412 "FieldName : FieldValue\n */\n\n");
414 AcpiDmDumpDataTable (Table);
415 fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
416 Table->Signature);
417 fprintf (stderr, "Formatted output: %s - %u bytes\n",
418 DisasmFilename, AdGetFileSize (File));
420 else
422 /* Always parse the tables, only option is what to display */
424 Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
425 if (ACPI_FAILURE (Status))
427 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
428 AcpiFormatException (Status));
429 goto Cleanup;
432 if (AslCompilerdebug)
434 AcpiOsPrintf ("/**** Before second load\n");
436 NsSetupNamespaceListing (File);
437 NsDisplayNamespace ();
438 AcpiOsPrintf ("*****/\n");
441 /* Load namespace from names created within control methods */
443 AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
444 AcpiGbl_RootNode, OwnerId);
447 * Cross reference the namespace here, in order to
448 * generate External() statements
450 AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
451 AcpiGbl_RootNode, OwnerId);
453 if (AslCompilerdebug)
455 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
458 /* Find possible calls to external control methods */
460 AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
463 * If we found any external control methods, we must reparse
464 * the entire tree with the new information (namely, the
465 * number of arguments per method)
467 if (AcpiDmGetExternalMethodCount ())
469 fprintf (stderr,
470 "\nFound %u external control methods, "
471 "reparsing with new information\n",
472 AcpiDmGetExternalMethodCount ());
474 /* Reparse, rebuild namespace. no need to xref namespace */
476 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
477 AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
479 AcpiGbl_RootNode = NULL;
480 AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
481 AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
482 AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;
483 AcpiGbl_RootNodeStruct.Parent = NULL;
484 AcpiGbl_RootNodeStruct.Child = NULL;
485 AcpiGbl_RootNodeStruct.Peer = NULL;
486 AcpiGbl_RootNodeStruct.Object = NULL;
487 AcpiGbl_RootNodeStruct.Flags = 0;
489 Status = AcpiNsRootInitialize ();
490 AcpiDmAddExternalsToNamespace ();
492 /* Parse the table again. No need to reload it, however */
494 Status = AdParseTable (Table, NULL, FALSE, FALSE);
495 if (ACPI_FAILURE (Status))
497 AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
498 AcpiFormatException (Status));
499 goto Cleanup;
502 if (AslCompilerdebug)
504 AcpiOsPrintf ("/**** After second load and resource conversion\n");
505 NsSetupNamespaceListing (File);
506 NsDisplayNamespace ();
507 AcpiOsPrintf ("*****/\n");
509 AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
514 * Now that the namespace is finalized, we can perform namespace
515 * transforms.
517 * 1) Convert fixed-offset references to resource descriptors
518 * to symbolic references (Note: modifies namespace)
520 AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
522 /* Optional displays */
524 if (AcpiGbl_DbOpt_disasm)
526 /* This is the real disassembly */
528 AdDisplayTables (Filename, Table);
530 /* Dump hex table if requested (-vt) */
532 AcpiDmDumpDataTable (Table);
534 fprintf (stderr, "Disassembly completed\n");
535 fprintf (stderr, "ASL Output: %s - %u bytes\n",
536 DisasmFilename, AdGetFileSize (File));
540 Cleanup:
542 if (Table && !AcpiUtIsAmlTable (Table))
544 ACPI_FREE (Table);
547 if (OutToFile && File)
549 if (AslCompilerdebug) /* Display final namespace, with transforms */
551 NsSetupNamespaceListing (File);
552 NsDisplayNamespace ();
555 fclose (File);
556 AcpiOsRedirectOutput (stdout);
559 AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
560 AcpiGbl_ParseOpRoot = NULL;
561 return (Status);
565 /******************************************************************************
567 * FUNCTION: AdDisassemblerHeader
569 * PARAMETERS: Filename - Input file for the table
571 * RETURN: None
573 * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
574 * current time and date.
576 *****************************************************************************/
578 void
579 AdDisassemblerHeader (
580 char *Filename)
582 time_t Timer;
584 time (&Timer);
586 /* Header and input table info */
588 AcpiOsPrintf ("/*\n");
589 AcpiOsPrintf (ACPI_COMMON_HEADER ("AML Disassembler", " * "));
591 AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
592 AcpiOsPrintf (" *\n");
596 /******************************************************************************
598 * FUNCTION: AdCreateTableHeader
600 * PARAMETERS: Filename - Input file for the table
601 * Table - Pointer to the raw table
603 * RETURN: None
605 * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
606 * current time and date.
608 *****************************************************************************/
610 static void
611 AdCreateTableHeader (
612 char *Filename,
613 ACPI_TABLE_HEADER *Table)
615 char *NewFilename;
616 UINT8 Checksum;
620 * Print file header and dump original table header
622 AdDisassemblerHeader (Filename);
624 AcpiOsPrintf (" * Original Table Header:\n");
625 AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
626 AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
628 /* Print and validate the revision */
630 AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
632 switch (Table->Revision)
634 case 0:
636 AcpiOsPrintf (" **** Invalid Revision");
637 break;
639 case 1:
641 /* Revision of DSDT controls the ACPI integer width */
643 if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
645 AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
647 break;
649 default:
651 break;
653 AcpiOsPrintf ("\n");
655 /* Print and validate the table checksum */
657 AcpiOsPrintf (" * Checksum 0x%2.2X", Table->Checksum);
659 Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
660 if (Checksum)
662 AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
663 (UINT8) (Table->Checksum - Checksum));
665 AcpiOsPrintf ("\n");
667 AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
668 AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
669 AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
670 AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
671 AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
672 AcpiOsPrintf (" */\n");
674 /* Create AML output filename based on input filename */
676 if (Filename)
678 NewFilename = FlGenerateFilename (Filename, "aml");
680 else
682 NewFilename = ACPI_ALLOCATE_ZEROED (9);
683 strncat (NewFilename, Table->Signature, 4);
684 strcat (NewFilename, ".aml");
687 /* Open the ASL definition block */
689 AcpiOsPrintf (
690 "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
691 NewFilename, Table->Signature, Table->Revision,
692 Table->OemId, Table->OemTableId, Table->OemRevision);
694 ACPI_FREE (NewFilename);
698 /******************************************************************************
700 * FUNCTION: AdDisplayTables
702 * PARAMETERS: Filename - Input file for the table
703 * Table - Pointer to the raw table
705 * RETURN: Status
707 * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
709 *****************************************************************************/
711 ACPI_STATUS
712 AdDisplayTables (
713 char *Filename,
714 ACPI_TABLE_HEADER *Table)
718 if (!AcpiGbl_ParseOpRoot)
720 return (AE_NOT_EXIST);
723 if (!AcpiGbl_DbOpt_verbose)
725 AdCreateTableHeader (Filename, Table);
728 AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
730 if (AcpiGbl_DbOpt_verbose)
732 AcpiOsPrintf ("\n\nTable Header:\n");
733 AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
734 DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
736 AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
737 AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
738 Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
741 return (AE_OK);
745 /******************************************************************************
747 * FUNCTION: AdGetLocalTables
749 * PARAMETERS: Filename - Not used
750 * GetAllTables - TRUE if all tables are desired
752 * RETURN: Status
754 * DESCRIPTION: Get the ACPI tables from either memory or a file
756 *****************************************************************************/
758 ACPI_STATUS
759 AdGetLocalTables (
760 char *Filename,
761 BOOLEAN GetAllTables)
763 ACPI_STATUS Status;
764 ACPI_TABLE_HEADER TableHeader;
765 ACPI_TABLE_HEADER *NewTable;
766 UINT32 NumTables;
767 UINT32 PointerSize;
768 UINT32 TableIndex;
771 if (GetAllTables)
773 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
774 AcpiOsTableOverride (&TableHeader, &NewTable);
775 if (!NewTable)
777 fprintf (stderr, "Could not obtain RSDT\n");
778 return (AE_NO_ACPI_TABLES);
780 else
782 AdWriteTable (NewTable, NewTable->Length,
783 ACPI_SIG_RSDT, NewTable->OemTableId);
786 if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
788 PointerSize = sizeof (UINT32);
790 else
792 PointerSize = sizeof (UINT64);
796 * Determine the number of tables pointed to by the RSDT/XSDT.
797 * This is defined by the ACPI Specification to be the number of
798 * pointers contained within the RSDT/XSDT. The size of the pointers
799 * is architecture-dependent.
801 NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
802 AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n",
803 NumTables, NewTable->Signature);
805 /* Get the FADT */
807 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
808 AcpiOsTableOverride (&TableHeader, &NewTable);
809 if (NewTable)
811 AdWriteTable (NewTable, NewTable->Length,
812 ACPI_SIG_FADT, NewTable->OemTableId);
814 AcpiOsPrintf ("\n");
816 /* Don't bother with FACS, it is usually all zeros */
819 /* Always get the DSDT */
821 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
822 AcpiOsTableOverride (&TableHeader, &NewTable);
823 if (NewTable)
825 AdWriteTable (NewTable, NewTable->Length,
826 ACPI_SIG_DSDT, NewTable->OemTableId);
828 /* Store DSDT in the Table Manager */
830 Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
831 0, &TableIndex);
832 if (ACPI_FAILURE (Status))
834 fprintf (stderr, "Could not store DSDT\n");
835 return (AE_NO_ACPI_TABLES);
838 else
840 fprintf (stderr, "Could not obtain DSDT\n");
841 return (AE_NO_ACPI_TABLES);
844 #if 0
845 /* TBD: Future implementation */
847 AcpiOsPrintf ("\n");
849 /* Get all SSDTs */
851 ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
854 NewTable = NULL;
855 Status = AcpiOsTableOverride (&TableHeader, &NewTable);
857 } while (NewTable);
858 #endif
860 return (AE_OK);
864 /******************************************************************************
866 * FUNCTION: AdParseTable
868 * PARAMETERS: Table - Pointer to the raw table
869 * OwnerId - Returned OwnerId of the table
870 * LoadTable - If add table to the global table list
871 * External - If this is an external table
873 * RETURN: Status
875 * DESCRIPTION: Parse the DSDT.
877 *****************************************************************************/
879 ACPI_STATUS
880 AdParseTable (
881 ACPI_TABLE_HEADER *Table,
882 ACPI_OWNER_ID *OwnerId,
883 BOOLEAN LoadTable,
884 BOOLEAN External)
886 ACPI_STATUS Status = AE_OK;
887 ACPI_WALK_STATE *WalkState;
888 UINT8 *AmlStart;
889 UINT32 AmlLength;
890 UINT32 TableIndex;
893 if (!Table)
895 return (AE_NOT_EXIST);
898 /* Pass 1: Parse everything except control method bodies */
900 fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
902 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
903 AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
905 /* Create the root object */
907 AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
908 if (!AcpiGbl_ParseOpRoot)
910 return (AE_NO_MEMORY);
913 /* Create and initialize a new walk state */
915 WalkState = AcpiDsCreateWalkState (0,
916 AcpiGbl_ParseOpRoot, NULL, NULL);
917 if (!WalkState)
919 return (AE_NO_MEMORY);
922 Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
923 NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
924 if (ACPI_FAILURE (Status))
926 return (Status);
929 WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
930 WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
932 Status = AcpiPsParseAml (WalkState);
933 if (ACPI_FAILURE (Status))
935 return (Status);
938 /* If LoadTable is FALSE, we are parsing the last loaded table */
940 TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
942 /* Pass 2 */
944 if (LoadTable)
946 Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
947 Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
948 if (ACPI_FAILURE (Status))
950 return (Status);
952 Status = AcpiTbAllocateOwnerId (TableIndex);
953 if (ACPI_FAILURE (Status))
955 return (Status);
957 if (OwnerId)
959 Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
960 if (ACPI_FAILURE (Status))
962 return (Status);
967 fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
969 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
970 if (ACPI_FAILURE (Status))
972 return (Status);
975 /* No need to parse control methods of external table */
977 if (External)
979 return (AE_OK);
982 /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
984 fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
985 Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
986 fprintf (stderr, "\n");
988 /* Process Resource Templates */
990 AcpiDmFindResources (AcpiGbl_ParseOpRoot);
992 fprintf (stderr, "Parsing completed\n");
993 return (AE_OK);