adisasm.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: adisasm - Application-level disassembler routines
4 1.1.1.2.2.2 bouyer *
5 1.1.1.2.2.2 bouyer *****************************************************************************/
6 1.1.1.2.2.2 bouyer
7 1.1.1.2.2.2 bouyer /*
8 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.2.2 bouyer * All rights reserved.
10 1.1.1.2.2.2 bouyer *
11 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.2.2.2 bouyer * are met:
14 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.2.2 bouyer * without modification.
17 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.2.2 bouyer * binary redistribution.
22 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.2.2.2 bouyer *
26 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.2.2 bouyer * Software Foundation.
29 1.1.1.2.2.2 bouyer *
30 1.1.1.2.2.2 bouyer * NO WARRANTY
31 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.2.2 bouyer */
43 1.1.1.2.2.2 bouyer
44 1.1.1.2.2.2 bouyer
45 1.1.1.2.2.2 bouyer #include "acpi.h"
46 1.1.1.2.2.2 bouyer #include "accommon.h"
47 1.1.1.2.2.2 bouyer #include "acparser.h"
48 1.1.1.2.2.2 bouyer #include "amlcode.h"
49 1.1.1.2.2.2 bouyer #include "acdebug.h"
50 1.1.1.2.2.2 bouyer #include "acdisasm.h"
51 1.1.1.2.2.2 bouyer #include "acdispat.h"
52 1.1.1.2.2.2 bouyer #include "acnamesp.h"
53 1.1.1.2.2.2 bouyer #include "actables.h"
54 1.1.1.2.2.2 bouyer #include "acapps.h"
55 1.1.1.2.2.2 bouyer
56 1.1.1.2.2.2 bouyer #include <stdio.h>
57 1.1.1.2.2.2 bouyer #include <time.h>
58 1.1.1.2.2.2 bouyer
59 1.1.1.2.2.2 bouyer
60 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_TOOLS
61 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("adisasm")
62 1.1.1.2.2.2 bouyer
63 1.1.1.2.2.2 bouyer
64 1.1.1.2.2.2 bouyer extern int AslCompilerdebug;
65 1.1.1.2.2.2 bouyer
66 1.1.1.2.2.2 bouyer
67 1.1.1.2.2.2 bouyer ACPI_STATUS
68 1.1.1.2.2.2 bouyer LsDisplayNamespace (
69 1.1.1.2.2.2 bouyer void);
70 1.1.1.2.2.2 bouyer
71 1.1.1.2.2.2 bouyer void
72 1.1.1.2.2.2 bouyer LsSetupNsList (
73 1.1.1.2.2.2 bouyer void *Handle);
74 1.1.1.2.2.2 bouyer
75 1.1.1.2.2.2 bouyer
76 1.1.1.2.2.2 bouyer /* Local prototypes */
77 1.1.1.2.2.2 bouyer
78 1.1.1.2.2.2 bouyer static void
79 1.1.1.2.2.2 bouyer AdCreateTableHeader (
80 1.1.1.2.2.2 bouyer char *Filename,
81 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table);
82 1.1.1.2.2.2 bouyer
83 1.1.1.2.2.2 bouyer static ACPI_STATUS
84 1.1.1.2.2.2 bouyer AdDeferredParse (
85 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
86 1.1.1.2.2.2 bouyer UINT8 *Aml,
87 1.1.1.2.2.2 bouyer UINT32 AmlLength);
88 1.1.1.2.2.2 bouyer
89 1.1.1.2.2.2 bouyer static ACPI_STATUS
90 1.1.1.2.2.2 bouyer AdParseDeferredOps (
91 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Root);
92 1.1.1.2.2.2 bouyer
93 1.1.1.2.2.2 bouyer
94 1.1.1.2.2.2 bouyer /* Stubs for ASL compiler */
95 1.1.1.2.2.2 bouyer
96 1.1.1.2.2.2 bouyer #ifndef ACPI_ASL_COMPILER
97 1.1.1.2.2.2 bouyer BOOLEAN
98 1.1.1.2.2.2 bouyer AcpiDsIsResultUsed (
99 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
100 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
101 1.1.1.2.2.2 bouyer {
102 1.1.1.2.2.2 bouyer return TRUE;
103 1.1.1.2.2.2 bouyer }
104 1.1.1.2.2.2 bouyer
105 1.1.1.2.2.2 bouyer ACPI_STATUS
106 1.1.1.2.2.2 bouyer AcpiDsMethodError (
107 1.1.1.2.2.2 bouyer ACPI_STATUS Status,
108 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
109 1.1.1.2.2.2 bouyer {
110 1.1.1.2.2.2 bouyer return (Status);
111 1.1.1.2.2.2 bouyer }
112 1.1.1.2.2.2 bouyer #endif
113 1.1.1.2.2.2 bouyer
114 1.1.1.2.2.2 bouyer ACPI_STATUS
115 1.1.1.2.2.2 bouyer AcpiNsLoadTable (
116 1.1.1.2.2.2 bouyer UINT32 TableIndex,
117 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *Node)
118 1.1.1.2.2.2 bouyer {
119 1.1.1.2.2.2 bouyer return (AE_NOT_IMPLEMENTED);
120 1.1.1.2.2.2 bouyer }
121 1.1.1.2.2.2 bouyer
122 1.1.1.2.2.2 bouyer ACPI_STATUS
123 1.1.1.2.2.2 bouyer AcpiDsRestartControlMethod (
124 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
125 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ReturnDesc)
126 1.1.1.2.2.2 bouyer {
127 1.1.1.2.2.2 bouyer return (AE_OK);
128 1.1.1.2.2.2 bouyer }
129 1.1.1.2.2.2 bouyer
130 1.1.1.2.2.2 bouyer void
131 1.1.1.2.2.2 bouyer AcpiDsTerminateControlMethod (
132 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *MethodDesc,
133 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
134 1.1.1.2.2.2 bouyer {
135 1.1.1.2.2.2 bouyer return;
136 1.1.1.2.2.2 bouyer }
137 1.1.1.2.2.2 bouyer
138 1.1.1.2.2.2 bouyer ACPI_STATUS
139 1.1.1.2.2.2 bouyer AcpiDsCallControlMethod (
140 1.1.1.2.2.2 bouyer ACPI_THREAD_STATE *Thread,
141 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState,
142 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op)
143 1.1.1.2.2.2 bouyer {
144 1.1.1.2.2.2 bouyer return (AE_OK);
145 1.1.1.2.2.2 bouyer }
146 1.1.1.2.2.2 bouyer
147 1.1.1.2.2.2 bouyer ACPI_STATUS
148 1.1.1.2.2.2 bouyer AcpiDsMethodDataInitArgs (
149 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT **Params,
150 1.1.1.2.2.2 bouyer UINT32 MaxParamCount,
151 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
152 1.1.1.2.2.2 bouyer {
153 1.1.1.2.2.2 bouyer return (AE_OK);
154 1.1.1.2.2.2 bouyer }
155 1.1.1.2.2.2 bouyer
156 1.1.1.2.2.2 bouyer
157 1.1.1.2.2.2 bouyer static ACPI_TABLE_DESC LocalTables[1];
158 1.1.1.2.2.2 bouyer static ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
159 1.1.1.2.2.2 bouyer
160 1.1.1.2.2.2 bouyer
161 1.1.1.2.2.2 bouyer /*******************************************************************************
162 1.1.1.2.2.2 bouyer *
163 1.1.1.2.2.2 bouyer * FUNCTION: AdInitialize
164 1.1.1.2.2.2 bouyer *
165 1.1.1.2.2.2 bouyer * PARAMETERS: None
166 1.1.1.2.2.2 bouyer *
167 1.1.1.2.2.2 bouyer * RETURN: Status
168 1.1.1.2.2.2 bouyer *
169 1.1.1.2.2.2 bouyer * DESCRIPTION: ACPICA and local initialization
170 1.1.1.2.2.2 bouyer *
171 1.1.1.2.2.2 bouyer ******************************************************************************/
172 1.1.1.2.2.2 bouyer
173 1.1.1.2.2.2 bouyer ACPI_STATUS
174 1.1.1.2.2.2 bouyer AdInitialize (
175 1.1.1.2.2.2 bouyer void)
176 1.1.1.2.2.2 bouyer {
177 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
178 1.1.1.2.2.2 bouyer
179 1.1.1.2.2.2 bouyer
180 1.1.1.2.2.2 bouyer /* ACPI CA subsystem initialization */
181 1.1.1.2.2.2 bouyer
182 1.1.1.2.2.2 bouyer Status = AcpiOsInitialize ();
183 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
184 1.1.1.2.2.2 bouyer {
185 1.1.1.2.2.2 bouyer return (Status);
186 1.1.1.2.2.2 bouyer }
187 1.1.1.2.2.2 bouyer
188 1.1.1.2.2.2 bouyer Status = AcpiUtInitGlobals ();
189 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
190 1.1.1.2.2.2 bouyer {
191 1.1.1.2.2.2 bouyer return (Status);
192 1.1.1.2.2.2 bouyer }
193 1.1.1.2.2.2 bouyer
194 1.1.1.2.2.2 bouyer Status = AcpiUtMutexInitialize ();
195 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
196 1.1.1.2.2.2 bouyer {
197 1.1.1.2.2.2 bouyer return (Status);
198 1.1.1.2.2.2 bouyer }
199 1.1.1.2.2.2 bouyer
200 1.1.1.2.2.2 bouyer Status = AcpiNsRootInitialize ();
201 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
202 1.1.1.2.2.2 bouyer {
203 1.1.1.2.2.2 bouyer return (Status);
204 1.1.1.2.2.2 bouyer }
205 1.1.1.2.2.2 bouyer
206 1.1.1.2.2.2 bouyer /* Setup the Table Manager (cheat - there is no RSDT) */
207 1.1.1.2.2.2 bouyer
208 1.1.1.2.2.2 bouyer AcpiGbl_RootTableList.MaxTableCount = 1;
209 1.1.1.2.2.2 bouyer AcpiGbl_RootTableList.CurrentTableCount = 0;
210 1.1.1.2.2.2 bouyer AcpiGbl_RootTableList.Tables = LocalTables;
211 1.1.1.2.2.2 bouyer
212 1.1.1.2.2.2 bouyer return (Status);
213 1.1.1.2.2.2 bouyer }
214 1.1.1.2.2.2 bouyer
215 1.1.1.2.2.2 bouyer
216 1.1.1.2.2.2 bouyer /******************************************************************************
217 1.1.1.2.2.2 bouyer *
218 1.1.1.2.2.2 bouyer * FUNCTION: AdAmlDisassemble
219 1.1.1.2.2.2 bouyer *
220 1.1.1.2.2.2 bouyer * PARAMETERS: Filename - AML input filename
221 1.1.1.2.2.2 bouyer * OutToFile - TRUE if output should go to a file
222 1.1.1.2.2.2 bouyer * Prefix - Path prefix for output
223 1.1.1.2.2.2 bouyer * OutFilename - where the filename is returned
224 1.1.1.2.2.2 bouyer * GetAllTables - TRUE if all tables are desired
225 1.1.1.2.2.2 bouyer *
226 1.1.1.2.2.2 bouyer * RETURN: Status
227 1.1.1.2.2.2 bouyer *
228 1.1.1.2.2.2 bouyer * DESCRIPTION: Disassemble an entire ACPI table
229 1.1.1.2.2.2 bouyer *
230 1.1.1.2.2.2 bouyer *****************************************************************************/
231 1.1.1.2.2.2 bouyer
232 1.1.1.2.2.2 bouyer ACPI_STATUS
233 1.1.1.2.2.2 bouyer AdAmlDisassemble (
234 1.1.1.2.2.2 bouyer BOOLEAN OutToFile,
235 1.1.1.2.2.2 bouyer char *Filename,
236 1.1.1.2.2.2 bouyer char *Prefix,
237 1.1.1.2.2.2 bouyer char **OutFilename,
238 1.1.1.2.2.2 bouyer BOOLEAN GetAllTables)
239 1.1.1.2.2.2 bouyer {
240 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
241 1.1.1.2.2.2 bouyer char *DisasmFilename = NULL;
242 1.1.1.2.2.2 bouyer char *ExternalFilename;
243 1.1.1.2.2.2 bouyer ACPI_EXTERNAL_FILE *ExternalFileList = AcpiGbl_ExternalFileList;
244 1.1.1.2.2.2 bouyer FILE *File = NULL;
245 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table = NULL;
246 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *ExternalTable;
247 1.1.1.2.2.2 bouyer ACPI_OWNER_ID OwnerId;
248 1.1.1.2.2.2 bouyer
249 1.1.1.2.2.2 bouyer
250 1.1.1.2.2.2 bouyer /*
251 1.1.1.2.2.2 bouyer * Input: AML code from either a file or via GetTables (memory or
252 1.1.1.2.2.2 bouyer * registry)
253 1.1.1.2.2.2 bouyer */
254 1.1.1.2.2.2 bouyer if (Filename)
255 1.1.1.2.2.2 bouyer {
256 1.1.1.2.2.2 bouyer Status = AcpiDbGetTableFromFile (Filename, &Table);
257 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
258 1.1.1.2.2.2 bouyer {
259 1.1.1.2.2.2 bouyer return Status;
260 1.1.1.2.2.2 bouyer }
261 1.1.1.2.2.2 bouyer
262 1.1.1.2.2.2 bouyer /*
263 1.1.1.2.2.2 bouyer * External filenames separated by commas
264 1.1.1.2.2.2 bouyer * Example: iasl -e file1,file2,file3 -d xxx.aml
265 1.1.1.2.2.2 bouyer */
266 1.1.1.2.2.2 bouyer while (ExternalFileList)
267 1.1.1.2.2.2 bouyer {
268 1.1.1.2.2.2 bouyer ExternalFilename = ExternalFileList->Path;
269 1.1.1.2.2.2 bouyer if (!ACPI_STRCMP (ExternalFilename, Filename))
270 1.1.1.2.2.2 bouyer {
271 1.1.1.2.2.2 bouyer /* Next external file */
272 1.1.1.2.2.2 bouyer
273 1.1.1.2.2.2 bouyer ExternalFileList = ExternalFileList->Next;
274 1.1.1.2.2.2 bouyer
275 1.1.1.2.2.2 bouyer continue;
276 1.1.1.2.2.2 bouyer }
277 1.1.1.2.2.2 bouyer
278 1.1.1.2.2.2 bouyer Status = AcpiDbGetTableFromFile (ExternalFilename, &ExternalTable);
279 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
280 1.1.1.2.2.2 bouyer {
281 1.1.1.2.2.2 bouyer return Status;
282 1.1.1.2.2.2 bouyer }
283 1.1.1.2.2.2 bouyer
284 1.1.1.2.2.2 bouyer /* Load external table for symbol resolution */
285 1.1.1.2.2.2 bouyer
286 1.1.1.2.2.2 bouyer if (ExternalTable)
287 1.1.1.2.2.2 bouyer {
288 1.1.1.2.2.2 bouyer Status = AdParseTable (ExternalTable, &OwnerId, TRUE, TRUE);
289 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
290 1.1.1.2.2.2 bouyer {
291 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
292 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
293 1.1.1.2.2.2 bouyer return Status;
294 1.1.1.2.2.2 bouyer }
295 1.1.1.2.2.2 bouyer
296 1.1.1.2.2.2 bouyer /*
297 1.1.1.2.2.2 bouyer * Load namespace from names created within control methods
298 1.1.1.2.2.2 bouyer * Set owner id of nodes in external table
299 1.1.1.2.2.2 bouyer */
300 1.1.1.2.2.2 bouyer AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
301 1.1.1.2.2.2 bouyer AcpiGbl_RootNode, OwnerId);
302 1.1.1.2.2.2 bouyer AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
303 1.1.1.2.2.2 bouyer }
304 1.1.1.2.2.2 bouyer
305 1.1.1.2.2.2 bouyer /* Next external file */
306 1.1.1.2.2.2 bouyer
307 1.1.1.2.2.2 bouyer ExternalFileList = ExternalFileList->Next;
308 1.1.1.2.2.2 bouyer }
309 1.1.1.2.2.2 bouyer
310 1.1.1.2.2.2 bouyer /* Clear external list generated by Scope in external tables */
311 1.1.1.2.2.2 bouyer
312 1.1.1.2.2.2 bouyer if (AcpiGbl_ExternalFileList)
313 1.1.1.2.2.2 bouyer {
314 1.1.1.2.2.2 bouyer AcpiDmClearExternalList ();
315 1.1.1.2.2.2 bouyer }
316 1.1.1.2.2.2 bouyer }
317 1.1.1.2.2.2 bouyer else
318 1.1.1.2.2.2 bouyer {
319 1.1.1.2.2.2 bouyer Status = AdGetLocalTables (Filename, GetAllTables);
320 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
321 1.1.1.2.2.2 bouyer {
322 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not get ACPI tables, %s\n",
323 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
324 1.1.1.2.2.2 bouyer return Status;
325 1.1.1.2.2.2 bouyer }
326 1.1.1.2.2.2 bouyer
327 1.1.1.2.2.2 bouyer if (!AcpiGbl_DbOpt_disasm)
328 1.1.1.2.2.2 bouyer {
329 1.1.1.2.2.2 bouyer return AE_OK;
330 1.1.1.2.2.2 bouyer }
331 1.1.1.2.2.2 bouyer
332 1.1.1.2.2.2 bouyer /* Obtained the local tables, just disassemble the DSDT */
333 1.1.1.2.2.2 bouyer
334 1.1.1.2.2.2 bouyer Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
335 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
336 1.1.1.2.2.2 bouyer {
337 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not get DSDT, %s\n",
338 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
339 1.1.1.2.2.2 bouyer return Status;
340 1.1.1.2.2.2 bouyer }
341 1.1.1.2.2.2 bouyer
342 1.1.1.2.2.2 bouyer AcpiOsPrintf ("\nDisassembly of DSDT\n");
343 1.1.1.2.2.2 bouyer Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
344 1.1.1.2.2.2 bouyer }
345 1.1.1.2.2.2 bouyer
346 1.1.1.2.2.2 bouyer /*
347 1.1.1.2.2.2 bouyer * Output: ASL code. Redirect to a file if requested
348 1.1.1.2.2.2 bouyer */
349 1.1.1.2.2.2 bouyer if (OutToFile)
350 1.1.1.2.2.2 bouyer {
351 1.1.1.2.2.2 bouyer /* Create/Open a disassembly output file */
352 1.1.1.2.2.2 bouyer
353 1.1.1.2.2.2 bouyer DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
354 1.1.1.2.2.2 bouyer if (!OutFilename)
355 1.1.1.2.2.2 bouyer {
356 1.1.1.2.2.2 bouyer fprintf (stderr, "Could not generate output filename\n");
357 1.1.1.2.2.2 bouyer Status = AE_ERROR;
358 1.1.1.2.2.2 bouyer goto Cleanup;
359 1.1.1.2.2.2 bouyer }
360 1.1.1.2.2.2 bouyer
361 1.1.1.2.2.2 bouyer File = fopen (DisasmFilename, "w+");
362 1.1.1.2.2.2 bouyer if (!File)
363 1.1.1.2.2.2 bouyer {
364 1.1.1.2.2.2 bouyer fprintf (stderr, "Could not open output file %s\n", DisasmFilename);
365 1.1.1.2.2.2 bouyer Status = AE_ERROR;
366 1.1.1.2.2.2 bouyer goto Cleanup;
367 1.1.1.2.2.2 bouyer }
368 1.1.1.2.2.2 bouyer
369 1.1.1.2.2.2 bouyer AcpiOsRedirectOutput (File);
370 1.1.1.2.2.2 bouyer }
371 1.1.1.2.2.2 bouyer
372 1.1.1.2.2.2 bouyer *OutFilename = DisasmFilename;
373 1.1.1.2.2.2 bouyer
374 1.1.1.2.2.2 bouyer if (!AcpiUtIsAmlTable (Table))
375 1.1.1.2.2.2 bouyer {
376 1.1.1.2.2.2 bouyer AdDisassemblerHeader (Filename);
377 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
378 1.1.1.2.2.2 bouyer Table->Signature);
379 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue\n */\n\n");
380 1.1.1.2.2.2 bouyer
381 1.1.1.2.2.2 bouyer AcpiDmDumpDataTable (Table);
382 1.1.1.2.2.2 bouyer fprintf (stderr, "Acpi Data Table [%4.4s] decoded, written to \"%s\"\n",
383 1.1.1.2.2.2 bouyer Table->Signature, DisasmFilename);
384 1.1.1.2.2.2 bouyer }
385 1.1.1.2.2.2 bouyer else
386 1.1.1.2.2.2 bouyer {
387 1.1.1.2.2.2 bouyer /* Always parse the tables, only option is what to display */
388 1.1.1.2.2.2 bouyer
389 1.1.1.2.2.2 bouyer Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
390 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
391 1.1.1.2.2.2 bouyer {
392 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
393 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
394 1.1.1.2.2.2 bouyer goto Cleanup;
395 1.1.1.2.2.2 bouyer }
396 1.1.1.2.2.2 bouyer
397 1.1.1.2.2.2 bouyer if (AslCompilerdebug)
398 1.1.1.2.2.2 bouyer {
399 1.1.1.2.2.2 bouyer AcpiOsPrintf ("/**** Before second load\n");
400 1.1.1.2.2.2 bouyer
401 1.1.1.2.2.2 bouyer LsSetupNsList (File);
402 1.1.1.2.2.2 bouyer LsDisplayNamespace ();
403 1.1.1.2.2.2 bouyer AcpiOsPrintf ("*****/\n");
404 1.1.1.2.2.2 bouyer }
405 1.1.1.2.2.2 bouyer
406 1.1.1.2.2.2 bouyer /*
407 1.1.1.2.2.2 bouyer * Load namespace from names created within control methods
408 1.1.1.2.2.2 bouyer */
409 1.1.1.2.2.2 bouyer AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
410 1.1.1.2.2.2 bouyer
411 1.1.1.2.2.2 bouyer /*
412 1.1.1.2.2.2 bouyer * Cross reference the namespace here, in order to generate External() statements
413 1.1.1.2.2.2 bouyer */
414 1.1.1.2.2.2 bouyer AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode, OwnerId);
415 1.1.1.2.2.2 bouyer
416 1.1.1.2.2.2 bouyer if (AslCompilerdebug)
417 1.1.1.2.2.2 bouyer {
418 1.1.1.2.2.2 bouyer AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
419 1.1.1.2.2.2 bouyer }
420 1.1.1.2.2.2 bouyer
421 1.1.1.2.2.2 bouyer /* Find possible calls to external control methods */
422 1.1.1.2.2.2 bouyer
423 1.1.1.2.2.2 bouyer AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
424 1.1.1.2.2.2 bouyer
425 1.1.1.2.2.2 bouyer /* Convert fixed-offset references to resource descriptors to symbolic references */
426 1.1.1.2.2.2 bouyer
427 1.1.1.2.2.2 bouyer AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
428 1.1.1.2.2.2 bouyer
429 1.1.1.2.2.2 bouyer /*
430 1.1.1.2.2.2 bouyer * If we found any external control methods, we must reparse the entire
431 1.1.1.2.2.2 bouyer * tree with the new information (namely, the number of arguments per
432 1.1.1.2.2.2 bouyer * method)
433 1.1.1.2.2.2 bouyer */
434 1.1.1.2.2.2 bouyer if (AcpiDmGetExternalMethodCount ())
435 1.1.1.2.2.2 bouyer {
436 1.1.1.2.2.2 bouyer fprintf (stderr,
437 1.1.1.2.2.2 bouyer "\nFound %u external control methods, reparsing with new information\n",
438 1.1.1.2.2.2 bouyer AcpiDmGetExternalMethodCount ());
439 1.1.1.2.2.2 bouyer
440 1.1.1.2.2.2 bouyer /*
441 1.1.1.2.2.2 bouyer * Reparse, rebuild namespace. no need to xref namespace
442 1.1.1.2.2.2 bouyer */
443 1.1.1.2.2.2 bouyer AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
444 1.1.1.2.2.2 bouyer AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
445 1.1.1.2.2.2 bouyer
446 1.1.1.2.2.2 bouyer AcpiGbl_RootNode = NULL;
447 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
448 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
449 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;
450 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.Parent = NULL;
451 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.Child = NULL;
452 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.Peer = NULL;
453 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.Object = NULL;
454 1.1.1.2.2.2 bouyer AcpiGbl_RootNodeStruct.Flags = 0;
455 1.1.1.2.2.2 bouyer
456 1.1.1.2.2.2 bouyer Status = AcpiNsRootInitialize ();
457 1.1.1.2.2.2 bouyer AcpiDmAddExternalsToNamespace ();
458 1.1.1.2.2.2 bouyer
459 1.1.1.2.2.2 bouyer /* Parse table. No need to reload it, however (FALSE) */
460 1.1.1.2.2.2 bouyer
461 1.1.1.2.2.2 bouyer Status = AdParseTable (Table, NULL, FALSE, FALSE);
462 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
463 1.1.1.2.2.2 bouyer {
464 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
465 1.1.1.2.2.2 bouyer AcpiFormatException (Status));
466 1.1.1.2.2.2 bouyer goto Cleanup;
467 1.1.1.2.2.2 bouyer }
468 1.1.1.2.2.2 bouyer
469 1.1.1.2.2.2 bouyer if (AslCompilerdebug)
470 1.1.1.2.2.2 bouyer {
471 1.1.1.2.2.2 bouyer AcpiOsPrintf ("/**** After second load and resource conversion\n");
472 1.1.1.2.2.2 bouyer LsSetupNsList (File);
473 1.1.1.2.2.2 bouyer LsDisplayNamespace ();
474 1.1.1.2.2.2 bouyer AcpiOsPrintf ("*****/\n");
475 1.1.1.2.2.2 bouyer
476 1.1.1.2.2.2 bouyer AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
477 1.1.1.2.2.2 bouyer }
478 1.1.1.2.2.2 bouyer }
479 1.1.1.2.2.2 bouyer
480 1.1.1.2.2.2 bouyer /* Optional displays */
481 1.1.1.2.2.2 bouyer
482 1.1.1.2.2.2 bouyer if (AcpiGbl_DbOpt_disasm)
483 1.1.1.2.2.2 bouyer {
484 1.1.1.2.2.2 bouyer AdDisplayTables (Filename, Table);
485 1.1.1.2.2.2 bouyer fprintf (stderr,
486 1.1.1.2.2.2 bouyer "Disassembly completed, written to \"%s\"\n",
487 1.1.1.2.2.2 bouyer DisasmFilename);
488 1.1.1.2.2.2 bouyer }
489 1.1.1.2.2.2 bouyer }
490 1.1.1.2.2.2 bouyer
491 1.1.1.2.2.2 bouyer Cleanup:
492 1.1.1.2.2.2 bouyer
493 1.1.1.2.2.2 bouyer if (Table && !AcpiUtIsAmlTable (Table))
494 1.1.1.2.2.2 bouyer {
495 1.1.1.2.2.2 bouyer ACPI_FREE (Table);
496 1.1.1.2.2.2 bouyer }
497 1.1.1.2.2.2 bouyer
498 1.1.1.2.2.2 bouyer if (DisasmFilename)
499 1.1.1.2.2.2 bouyer {
500 1.1.1.2.2.2 bouyer ACPI_FREE (DisasmFilename);
501 1.1.1.2.2.2 bouyer }
502 1.1.1.2.2.2 bouyer
503 1.1.1.2.2.2 bouyer if (OutToFile && File)
504 1.1.1.2.2.2 bouyer {
505 1.1.1.2.2.2 bouyer
506 1.1.1.2.2.2 bouyer #ifdef ASL_DISASM_DEBUG
507 1.1.1.2.2.2 bouyer LsSetupNsList (File);
508 1.1.1.2.2.2 bouyer LsDisplayNamespace ();
509 1.1.1.2.2.2 bouyer #endif
510 1.1.1.2.2.2 bouyer fclose (File);
511 1.1.1.2.2.2 bouyer AcpiOsRedirectOutput (stdout);
512 1.1.1.2.2.2 bouyer }
513 1.1.1.2.2.2 bouyer
514 1.1.1.2.2.2 bouyer AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
515 1.1.1.2.2.2 bouyer AcpiGbl_ParseOpRoot = NULL;
516 1.1.1.2.2.2 bouyer return (Status);
517 1.1.1.2.2.2 bouyer }
518 1.1.1.2.2.2 bouyer
519 1.1.1.2.2.2 bouyer
520 1.1.1.2.2.2 bouyer /******************************************************************************
521 1.1.1.2.2.2 bouyer *
522 1.1.1.2.2.2 bouyer * FUNCTION: AdDisassemblerHeader
523 1.1.1.2.2.2 bouyer *
524 1.1.1.2.2.2 bouyer * PARAMETERS: Filename - Input file for the table
525 1.1.1.2.2.2 bouyer *
526 1.1.1.2.2.2 bouyer * RETURN: None
527 1.1.1.2.2.2 bouyer *
528 1.1.1.2.2.2 bouyer * DESCRIPTION: Create the disassembler header, including ACPI CA signon with
529 1.1.1.2.2.2 bouyer * current time and date.
530 1.1.1.2.2.2 bouyer *
531 1.1.1.2.2.2 bouyer *****************************************************************************/
532 1.1.1.2.2.2 bouyer
533 1.1.1.2.2.2 bouyer void
534 1.1.1.2.2.2 bouyer AdDisassemblerHeader (
535 1.1.1.2.2.2 bouyer char *Filename)
536 1.1.1.2.2.2 bouyer {
537 1.1.1.2.2.2 bouyer time_t Timer;
538 1.1.1.2.2.2 bouyer
539 1.1.1.2.2.2 bouyer time (&Timer);
540 1.1.1.2.2.2 bouyer
541 1.1.1.2.2.2 bouyer /* Header and input table info */
542 1.1.1.2.2.2 bouyer
543 1.1.1.2.2.2 bouyer AcpiOsPrintf ("/*\n");
544 1.1.1.2.2.2 bouyer AcpiOsPrintf (ACPI_COMMON_HEADER ("AML Disassembler", " * "));
545 1.1.1.2.2.2 bouyer
546 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
547 1.1.1.2.2.2 bouyer AcpiOsPrintf (" *\n");
548 1.1.1.2.2.2 bouyer }
549 1.1.1.2.2.2 bouyer
550 1.1.1.2.2.2 bouyer
551 1.1.1.2.2.2 bouyer /******************************************************************************
552 1.1.1.2.2.2 bouyer *
553 1.1.1.2.2.2 bouyer * FUNCTION: AdCreateTableHeader
554 1.1.1.2.2.2 bouyer *
555 1.1.1.2.2.2 bouyer * PARAMETERS: Filename - Input file for the table
556 1.1.1.2.2.2 bouyer * Table - Pointer to the raw table
557 1.1.1.2.2.2 bouyer *
558 1.1.1.2.2.2 bouyer * RETURN: None
559 1.1.1.2.2.2 bouyer *
560 1.1.1.2.2.2 bouyer * DESCRIPTION: Create the ASL table header, including ACPI CA signon with
561 1.1.1.2.2.2 bouyer * current time and date.
562 1.1.1.2.2.2 bouyer *
563 1.1.1.2.2.2 bouyer *****************************************************************************/
564 1.1.1.2.2.2 bouyer
565 1.1.1.2.2.2 bouyer static void
566 1.1.1.2.2.2 bouyer AdCreateTableHeader (
567 1.1.1.2.2.2 bouyer char *Filename,
568 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table)
569 1.1.1.2.2.2 bouyer {
570 1.1.1.2.2.2 bouyer char *NewFilename;
571 1.1.1.2.2.2 bouyer UINT8 Checksum;
572 1.1.1.2.2.2 bouyer
573 1.1.1.2.2.2 bouyer
574 1.1.1.2.2.2 bouyer /*
575 1.1.1.2.2.2 bouyer * Print file header and dump original table header
576 1.1.1.2.2.2 bouyer */
577 1.1.1.2.2.2 bouyer AdDisassemblerHeader (Filename);
578 1.1.1.2.2.2 bouyer
579 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Original Table Header:\n");
580 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
581 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
582 1.1.1.2.2.2 bouyer
583 1.1.1.2.2.2 bouyer /* Print and validate the revision */
584 1.1.1.2.2.2 bouyer
585 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
586 1.1.1.2.2.2 bouyer
587 1.1.1.2.2.2 bouyer switch (Table->Revision)
588 1.1.1.2.2.2 bouyer {
589 1.1.1.2.2.2 bouyer case 0:
590 1.1.1.2.2.2 bouyer AcpiOsPrintf (" **** Invalid Revision");
591 1.1.1.2.2.2 bouyer break;
592 1.1.1.2.2.2 bouyer
593 1.1.1.2.2.2 bouyer case 1:
594 1.1.1.2.2.2 bouyer /* Revision of DSDT controls the ACPI integer width */
595 1.1.1.2.2.2 bouyer
596 1.1.1.2.2.2 bouyer if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
597 1.1.1.2.2.2 bouyer {
598 1.1.1.2.2.2 bouyer AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
599 1.1.1.2.2.2 bouyer }
600 1.1.1.2.2.2 bouyer break;
601 1.1.1.2.2.2 bouyer
602 1.1.1.2.2.2 bouyer default:
603 1.1.1.2.2.2 bouyer break;
604 1.1.1.2.2.2 bouyer }
605 1.1.1.2.2.2 bouyer AcpiOsPrintf ("\n");
606 1.1.1.2.2.2 bouyer
607 1.1.1.2.2.2 bouyer /* Print and validate the table checksum */
608 1.1.1.2.2.2 bouyer
609 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Checksum 0x%2.2X", Table->Checksum);
610 1.1.1.2.2.2 bouyer
611 1.1.1.2.2.2 bouyer Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
612 1.1.1.2.2.2 bouyer if (Checksum)
613 1.1.1.2.2.2 bouyer {
614 1.1.1.2.2.2 bouyer AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
615 1.1.1.2.2.2 bouyer (UINT8) (Table->Checksum - Checksum));
616 1.1.1.2.2.2 bouyer }
617 1.1.1.2.2.2 bouyer AcpiOsPrintf ("\n");
618 1.1.1.2.2.2 bouyer
619 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
620 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
621 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
622 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
623 1.1.1.2.2.2 bouyer AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
624 1.1.1.2.2.2 bouyer AcpiOsPrintf (" */\n\n");
625 1.1.1.2.2.2 bouyer
626 1.1.1.2.2.2 bouyer /* Create AML output filename based on input filename */
627 1.1.1.2.2.2 bouyer
628 1.1.1.2.2.2 bouyer if (Filename)
629 1.1.1.2.2.2 bouyer {
630 1.1.1.2.2.2 bouyer NewFilename = FlGenerateFilename (Filename, "aml");
631 1.1.1.2.2.2 bouyer }
632 1.1.1.2.2.2 bouyer else
633 1.1.1.2.2.2 bouyer {
634 1.1.1.2.2.2 bouyer NewFilename = ACPI_ALLOCATE_ZEROED (9);
635 1.1.1.2.2.2 bouyer strncat (NewFilename, Table->Signature, 4);
636 1.1.1.2.2.2 bouyer strcat (NewFilename, ".aml");
637 1.1.1.2.2.2 bouyer }
638 1.1.1.2.2.2 bouyer
639 1.1.1.2.2.2 bouyer /* Open the ASL definition block */
640 1.1.1.2.2.2 bouyer
641 1.1.1.2.2.2 bouyer AcpiOsPrintf (
642 1.1.1.2.2.2 bouyer "DefinitionBlock (\"%s\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
643 1.1.1.2.2.2 bouyer NewFilename, Table->Signature, Table->Revision,
644 1.1.1.2.2.2 bouyer Table->OemId, Table->OemTableId, Table->OemRevision);
645 1.1.1.2.2.2 bouyer
646 1.1.1.2.2.2 bouyer ACPI_FREE (NewFilename);
647 1.1.1.2.2.2 bouyer }
648 1.1.1.2.2.2 bouyer
649 1.1.1.2.2.2 bouyer
650 1.1.1.2.2.2 bouyer /******************************************************************************
651 1.1.1.2.2.2 bouyer *
652 1.1.1.2.2.2 bouyer * FUNCTION: AdDisplayTables
653 1.1.1.2.2.2 bouyer *
654 1.1.1.2.2.2 bouyer * PARAMETERS: Filename - Input file for the table
655 1.1.1.2.2.2 bouyer * Table - Pointer to the raw table
656 1.1.1.2.2.2 bouyer *
657 1.1.1.2.2.2 bouyer * RETURN: Status
658 1.1.1.2.2.2 bouyer *
659 1.1.1.2.2.2 bouyer * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
660 1.1.1.2.2.2 bouyer *
661 1.1.1.2.2.2 bouyer *****************************************************************************/
662 1.1.1.2.2.2 bouyer
663 1.1.1.2.2.2 bouyer ACPI_STATUS
664 1.1.1.2.2.2 bouyer AdDisplayTables (
665 1.1.1.2.2.2 bouyer char *Filename,
666 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table)
667 1.1.1.2.2.2 bouyer {
668 1.1.1.2.2.2 bouyer
669 1.1.1.2.2.2 bouyer
670 1.1.1.2.2.2 bouyer if (!AcpiGbl_ParseOpRoot)
671 1.1.1.2.2.2 bouyer {
672 1.1.1.2.2.2 bouyer return AE_NOT_EXIST;
673 1.1.1.2.2.2 bouyer }
674 1.1.1.2.2.2 bouyer
675 1.1.1.2.2.2 bouyer if (!AcpiGbl_DbOpt_verbose)
676 1.1.1.2.2.2 bouyer {
677 1.1.1.2.2.2 bouyer AdCreateTableHeader (Filename, Table);
678 1.1.1.2.2.2 bouyer }
679 1.1.1.2.2.2 bouyer
680 1.1.1.2.2.2 bouyer AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
681 1.1.1.2.2.2 bouyer
682 1.1.1.2.2.2 bouyer if (AcpiGbl_DbOpt_verbose)
683 1.1.1.2.2.2 bouyer {
684 1.1.1.2.2.2 bouyer AcpiOsPrintf ("\n\nTable Header:\n");
685 1.1.1.2.2.2 bouyer AcpiUtDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
686 1.1.1.2.2.2 bouyer DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
687 1.1.1.2.2.2 bouyer
688 1.1.1.2.2.2 bouyer AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
689 1.1.1.2.2.2 bouyer AcpiUtDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)), Table->Length,
690 1.1.1.2.2.2 bouyer DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
691 1.1.1.2.2.2 bouyer }
692 1.1.1.2.2.2 bouyer
693 1.1.1.2.2.2 bouyer return AE_OK;
694 1.1.1.2.2.2 bouyer }
695 1.1.1.2.2.2 bouyer
696 1.1.1.2.2.2 bouyer
697 1.1.1.2.2.2 bouyer /******************************************************************************
698 1.1.1.2.2.2 bouyer *
699 1.1.1.2.2.2 bouyer * FUNCTION: AdDeferredParse
700 1.1.1.2.2.2 bouyer *
701 1.1.1.2.2.2 bouyer * PARAMETERS: Op - Root Op of the deferred opcode
702 1.1.1.2.2.2 bouyer * Aml - Pointer to the raw AML
703 1.1.1.2.2.2 bouyer * AmlLength - Length of the AML
704 1.1.1.2.2.2 bouyer *
705 1.1.1.2.2.2 bouyer * RETURN: Status
706 1.1.1.2.2.2 bouyer *
707 1.1.1.2.2.2 bouyer * DESCRIPTION: Parse one deferred opcode
708 1.1.1.2.2.2 bouyer * (Methods, operation regions, etc.)
709 1.1.1.2.2.2 bouyer *
710 1.1.1.2.2.2 bouyer *****************************************************************************/
711 1.1.1.2.2.2 bouyer
712 1.1.1.2.2.2 bouyer static ACPI_STATUS
713 1.1.1.2.2.2 bouyer AdDeferredParse (
714 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op,
715 1.1.1.2.2.2 bouyer UINT8 *Aml,
716 1.1.1.2.2.2 bouyer UINT32 AmlLength)
717 1.1.1.2.2.2 bouyer {
718 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState;
719 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
720 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *SearchOp;
721 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *StartOp;
722 1.1.1.2.2.2 bouyer UINT32 BaseAmlOffset;
723 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *ExtraOp;
724 1.1.1.2.2.2 bouyer
725 1.1.1.2.2.2 bouyer
726 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (AdDeferredParse);
727 1.1.1.2.2.2 bouyer
728 1.1.1.2.2.2 bouyer
729 1.1.1.2.2.2 bouyer fprintf (stderr, ".");
730 1.1.1.2.2.2 bouyer
731 1.1.1.2.2.2 bouyer if (!Aml || !AmlLength)
732 1.1.1.2.2.2 bouyer {
733 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
734 1.1.1.2.2.2 bouyer }
735 1.1.1.2.2.2 bouyer
736 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Parsing %s [%4.4s]\n",
737 1.1.1.2.2.2 bouyer Op->Common.AmlOpName, (char *) &Op->Named.Name));
738 1.1.1.2.2.2 bouyer
739 1.1.1.2.2.2 bouyer WalkState = AcpiDsCreateWalkState (0, Op, NULL, NULL);
740 1.1.1.2.2.2 bouyer if (!WalkState)
741 1.1.1.2.2.2 bouyer {
742 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
743 1.1.1.2.2.2 bouyer }
744 1.1.1.2.2.2 bouyer
745 1.1.1.2.2.2 bouyer Status = AcpiDsInitAmlWalk (WalkState, Op, NULL, Aml,
746 1.1.1.2.2.2 bouyer AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
747 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
748 1.1.1.2.2.2 bouyer {
749 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
750 1.1.1.2.2.2 bouyer }
751 1.1.1.2.2.2 bouyer
752 1.1.1.2.2.2 bouyer /* Parse the method */
753 1.1.1.2.2.2 bouyer
754 1.1.1.2.2.2 bouyer WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
755 1.1.1.2.2.2 bouyer WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
756 1.1.1.2.2.2 bouyer Status = AcpiPsParseAml (WalkState);
757 1.1.1.2.2.2 bouyer
758 1.1.1.2.2.2 bouyer /*
759 1.1.1.2.2.2 bouyer * We need to update all of the Aml offsets, since the parser thought
760 1.1.1.2.2.2 bouyer * that the method began at offset zero. In reality, it began somewhere
761 1.1.1.2.2.2 bouyer * within the ACPI table, at the BaseAmlOffset. Walk the entire tree that
762 1.1.1.2.2.2 bouyer * was just created and update the AmlOffset in each Op
763 1.1.1.2.2.2 bouyer */
764 1.1.1.2.2.2 bouyer BaseAmlOffset = (Op->Common.Value.Arg)->Common.AmlOffset + 1;
765 1.1.1.2.2.2 bouyer StartOp = (Op->Common.Value.Arg)->Common.Next;
766 1.1.1.2.2.2 bouyer SearchOp = StartOp;
767 1.1.1.2.2.2 bouyer
768 1.1.1.2.2.2 bouyer /* Walk the parse tree */
769 1.1.1.2.2.2 bouyer
770 1.1.1.2.2.2 bouyer while (SearchOp)
771 1.1.1.2.2.2 bouyer {
772 1.1.1.2.2.2 bouyer SearchOp->Common.AmlOffset += BaseAmlOffset;
773 1.1.1.2.2.2 bouyer SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
774 1.1.1.2.2.2 bouyer }
775 1.1.1.2.2.2 bouyer
776 1.1.1.2.2.2 bouyer /*
777 1.1.1.2.2.2 bouyer * Link the newly parsed subtree into the main parse tree
778 1.1.1.2.2.2 bouyer */
779 1.1.1.2.2.2 bouyer switch (Op->Common.AmlOpcode)
780 1.1.1.2.2.2 bouyer {
781 1.1.1.2.2.2 bouyer case AML_BUFFER_OP:
782 1.1.1.2.2.2 bouyer case AML_PACKAGE_OP:
783 1.1.1.2.2.2 bouyer case AML_VAR_PACKAGE_OP:
784 1.1.1.2.2.2 bouyer
785 1.1.1.2.2.2 bouyer switch (Op->Common.AmlOpcode)
786 1.1.1.2.2.2 bouyer {
787 1.1.1.2.2.2 bouyer case AML_PACKAGE_OP:
788 1.1.1.2.2.2 bouyer ExtraOp = Op->Common.Value.Arg;
789 1.1.1.2.2.2 bouyer ExtraOp = ExtraOp->Common.Next;
790 1.1.1.2.2.2 bouyer Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
791 1.1.1.2.2.2 bouyer break;
792 1.1.1.2.2.2 bouyer
793 1.1.1.2.2.2 bouyer case AML_VAR_PACKAGE_OP:
794 1.1.1.2.2.2 bouyer case AML_BUFFER_OP:
795 1.1.1.2.2.2 bouyer default:
796 1.1.1.2.2.2 bouyer ExtraOp = Op->Common.Value.Arg;
797 1.1.1.2.2.2 bouyer Op->Common.Value.Arg = ExtraOp->Common.Value.Arg;
798 1.1.1.2.2.2 bouyer break;
799 1.1.1.2.2.2 bouyer }
800 1.1.1.2.2.2 bouyer
801 1.1.1.2.2.2 bouyer /* Must point all parents to the main tree */
802 1.1.1.2.2.2 bouyer
803 1.1.1.2.2.2 bouyer StartOp = Op;
804 1.1.1.2.2.2 bouyer SearchOp = StartOp;
805 1.1.1.2.2.2 bouyer while (SearchOp)
806 1.1.1.2.2.2 bouyer {
807 1.1.1.2.2.2 bouyer if (SearchOp->Common.Parent == ExtraOp)
808 1.1.1.2.2.2 bouyer {
809 1.1.1.2.2.2 bouyer SearchOp->Common.Parent = Op;
810 1.1.1.2.2.2 bouyer }
811 1.1.1.2.2.2 bouyer SearchOp = AcpiPsGetDepthNext (StartOp, SearchOp);
812 1.1.1.2.2.2 bouyer }
813 1.1.1.2.2.2 bouyer break;
814 1.1.1.2.2.2 bouyer
815 1.1.1.2.2.2 bouyer default:
816 1.1.1.2.2.2 bouyer break;
817 1.1.1.2.2.2 bouyer }
818 1.1.1.2.2.2 bouyer
819 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
820 1.1.1.2.2.2 bouyer }
821 1.1.1.2.2.2 bouyer
822 1.1.1.2.2.2 bouyer
823 1.1.1.2.2.2 bouyer /******************************************************************************
824 1.1.1.2.2.2 bouyer *
825 1.1.1.2.2.2 bouyer * FUNCTION: AdParseDeferredOps
826 1.1.1.2.2.2 bouyer *
827 1.1.1.2.2.2 bouyer * PARAMETERS: Root - Root of the parse tree
828 1.1.1.2.2.2 bouyer *
829 1.1.1.2.2.2 bouyer * RETURN: Status
830 1.1.1.2.2.2 bouyer *
831 1.1.1.2.2.2 bouyer * DESCRIPTION: Parse the deferred opcodes (Methods, regions, etc.)
832 1.1.1.2.2.2 bouyer *
833 1.1.1.2.2.2 bouyer *****************************************************************************/
834 1.1.1.2.2.2 bouyer
835 1.1.1.2.2.2 bouyer static ACPI_STATUS
836 1.1.1.2.2.2 bouyer AdParseDeferredOps (
837 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Root)
838 1.1.1.2.2.2 bouyer {
839 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *Op = Root;
840 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
841 1.1.1.2.2.2 bouyer const ACPI_OPCODE_INFO *OpInfo;
842 1.1.1.2.2.2 bouyer
843 1.1.1.2.2.2 bouyer
844 1.1.1.2.2.2 bouyer ACPI_FUNCTION_NAME (AdParseDeferredOps);
845 1.1.1.2.2.2 bouyer fprintf (stderr, "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
846 1.1.1.2.2.2 bouyer
847 1.1.1.2.2.2 bouyer while (Op)
848 1.1.1.2.2.2 bouyer {
849 1.1.1.2.2.2 bouyer OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
850 1.1.1.2.2.2 bouyer if (!(OpInfo->Flags & AML_DEFER))
851 1.1.1.2.2.2 bouyer {
852 1.1.1.2.2.2 bouyer Op = AcpiPsGetDepthNext (Root, Op);
853 1.1.1.2.2.2 bouyer continue;
854 1.1.1.2.2.2 bouyer }
855 1.1.1.2.2.2 bouyer
856 1.1.1.2.2.2 bouyer switch (Op->Common.AmlOpcode)
857 1.1.1.2.2.2 bouyer {
858 1.1.1.2.2.2 bouyer case AML_METHOD_OP:
859 1.1.1.2.2.2 bouyer case AML_BUFFER_OP:
860 1.1.1.2.2.2 bouyer case AML_PACKAGE_OP:
861 1.1.1.2.2.2 bouyer case AML_VAR_PACKAGE_OP:
862 1.1.1.2.2.2 bouyer
863 1.1.1.2.2.2 bouyer Status = AdDeferredParse (Op, Op->Named.Data, Op->Named.Length);
864 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
865 1.1.1.2.2.2 bouyer {
866 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
867 1.1.1.2.2.2 bouyer }
868 1.1.1.2.2.2 bouyer break;
869 1.1.1.2.2.2 bouyer
870 1.1.1.2.2.2 bouyer case AML_REGION_OP:
871 1.1.1.2.2.2 bouyer case AML_CREATE_QWORD_FIELD_OP:
872 1.1.1.2.2.2 bouyer case AML_CREATE_DWORD_FIELD_OP:
873 1.1.1.2.2.2 bouyer case AML_CREATE_WORD_FIELD_OP:
874 1.1.1.2.2.2 bouyer case AML_CREATE_BYTE_FIELD_OP:
875 1.1.1.2.2.2 bouyer case AML_CREATE_BIT_FIELD_OP:
876 1.1.1.2.2.2 bouyer case AML_CREATE_FIELD_OP:
877 1.1.1.2.2.2 bouyer case AML_BANK_FIELD_OP:
878 1.1.1.2.2.2 bouyer
879 1.1.1.2.2.2 bouyer /* Nothing to do in these cases */
880 1.1.1.2.2.2 bouyer
881 1.1.1.2.2.2 bouyer break;
882 1.1.1.2.2.2 bouyer
883 1.1.1.2.2.2 bouyer default:
884 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO, "Unhandled deferred opcode [%s]",
885 1.1.1.2.2.2 bouyer Op->Common.AmlOpName));
886 1.1.1.2.2.2 bouyer break;
887 1.1.1.2.2.2 bouyer }
888 1.1.1.2.2.2 bouyer
889 1.1.1.2.2.2 bouyer Op = AcpiPsGetDepthNext (Root, Op);
890 1.1.1.2.2.2 bouyer }
891 1.1.1.2.2.2 bouyer
892 1.1.1.2.2.2 bouyer fprintf (stderr, "\n");
893 1.1.1.2.2.2 bouyer return Status;
894 1.1.1.2.2.2 bouyer }
895 1.1.1.2.2.2 bouyer
896 1.1.1.2.2.2 bouyer
897 1.1.1.2.2.2 bouyer /******************************************************************************
898 1.1.1.2.2.2 bouyer *
899 1.1.1.2.2.2 bouyer * FUNCTION: AdGetLocalTables
900 1.1.1.2.2.2 bouyer *
901 1.1.1.2.2.2 bouyer * PARAMETERS: Filename - Not used
902 1.1.1.2.2.2 bouyer * GetAllTables - TRUE if all tables are desired
903 1.1.1.2.2.2 bouyer *
904 1.1.1.2.2.2 bouyer * RETURN: Status
905 1.1.1.2.2.2 bouyer *
906 1.1.1.2.2.2 bouyer * DESCRIPTION: Get the ACPI tables from either memory or a file
907 1.1.1.2.2.2 bouyer *
908 1.1.1.2.2.2 bouyer *****************************************************************************/
909 1.1.1.2.2.2 bouyer
910 1.1.1.2.2.2 bouyer ACPI_STATUS
911 1.1.1.2.2.2 bouyer AdGetLocalTables (
912 1.1.1.2.2.2 bouyer char *Filename,
913 1.1.1.2.2.2 bouyer BOOLEAN GetAllTables)
914 1.1.1.2.2.2 bouyer {
915 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
916 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER TableHeader;
917 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *NewTable;
918 1.1.1.2.2.2 bouyer UINT32 NumTables;
919 1.1.1.2.2.2 bouyer UINT32 PointerSize;
920 1.1.1.2.2.2 bouyer UINT32 TableIndex;
921 1.1.1.2.2.2 bouyer
922 1.1.1.2.2.2 bouyer
923 1.1.1.2.2.2 bouyer if (GetAllTables)
924 1.1.1.2.2.2 bouyer {
925 1.1.1.2.2.2 bouyer ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_RSDT);
926 1.1.1.2.2.2 bouyer AcpiOsTableOverride (&TableHeader, &NewTable);
927 1.1.1.2.2.2 bouyer if (!NewTable)
928 1.1.1.2.2.2 bouyer {
929 1.1.1.2.2.2 bouyer fprintf (stderr, "Could not obtain RSDT\n");
930 1.1.1.2.2.2 bouyer return AE_NO_ACPI_TABLES;
931 1.1.1.2.2.2 bouyer }
932 1.1.1.2.2.2 bouyer else
933 1.1.1.2.2.2 bouyer {
934 1.1.1.2.2.2 bouyer AdWriteTable (NewTable, NewTable->Length,
935 1.1.1.2.2.2 bouyer ACPI_SIG_RSDT, NewTable->OemTableId);
936 1.1.1.2.2.2 bouyer }
937 1.1.1.2.2.2 bouyer
938 1.1.1.2.2.2 bouyer if (ACPI_COMPARE_NAME (NewTable->Signature, ACPI_SIG_RSDT))
939 1.1.1.2.2.2 bouyer {
940 1.1.1.2.2.2 bouyer PointerSize = sizeof (UINT32);
941 1.1.1.2.2.2 bouyer }
942 1.1.1.2.2.2 bouyer else
943 1.1.1.2.2.2 bouyer {
944 1.1.1.2.2.2 bouyer PointerSize = sizeof (UINT64);
945 1.1.1.2.2.2 bouyer }
946 1.1.1.2.2.2 bouyer
947 1.1.1.2.2.2 bouyer /*
948 1.1.1.2.2.2 bouyer * Determine the number of tables pointed to by the RSDT/XSDT.
949 1.1.1.2.2.2 bouyer * This is defined by the ACPI Specification to be the number of
950 1.1.1.2.2.2 bouyer * pointers contained within the RSDT/XSDT. The size of the pointers
951 1.1.1.2.2.2 bouyer * is architecture-dependent.
952 1.1.1.2.2.2 bouyer */
953 1.1.1.2.2.2 bouyer NumTables = (NewTable->Length - sizeof (ACPI_TABLE_HEADER)) / PointerSize;
954 1.1.1.2.2.2 bouyer AcpiOsPrintf ("There are %u tables defined in the %4.4s\n\n",
955 1.1.1.2.2.2 bouyer NumTables, NewTable->Signature);
956 1.1.1.2.2.2 bouyer
957 1.1.1.2.2.2 bouyer /* Get the FADT */
958 1.1.1.2.2.2 bouyer
959 1.1.1.2.2.2 bouyer ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_FADT);
960 1.1.1.2.2.2 bouyer AcpiOsTableOverride (&TableHeader, &NewTable);
961 1.1.1.2.2.2 bouyer if (NewTable)
962 1.1.1.2.2.2 bouyer {
963 1.1.1.2.2.2 bouyer AdWriteTable (NewTable, NewTable->Length,
964 1.1.1.2.2.2 bouyer ACPI_SIG_FADT, NewTable->OemTableId);
965 1.1.1.2.2.2 bouyer }
966 1.1.1.2.2.2 bouyer AcpiOsPrintf ("\n");
967 1.1.1.2.2.2 bouyer
968 1.1.1.2.2.2 bouyer /* Don't bother with FACS, it is usually all zeros */
969 1.1.1.2.2.2 bouyer }
970 1.1.1.2.2.2 bouyer
971 1.1.1.2.2.2 bouyer /* Always get the DSDT */
972 1.1.1.2.2.2 bouyer
973 1.1.1.2.2.2 bouyer ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
974 1.1.1.2.2.2 bouyer AcpiOsTableOverride (&TableHeader, &NewTable);
975 1.1.1.2.2.2 bouyer if (NewTable)
976 1.1.1.2.2.2 bouyer {
977 1.1.1.2.2.2 bouyer AdWriteTable (NewTable, NewTable->Length,
978 1.1.1.2.2.2 bouyer ACPI_SIG_DSDT, NewTable->OemTableId);
979 1.1.1.2.2.2 bouyer
980 1.1.1.2.2.2 bouyer /* Store DSDT in the Table Manager */
981 1.1.1.2.2.2 bouyer
982 1.1.1.2.2.2 bouyer Status = AcpiTbStoreTable (0, NewTable, NewTable->Length,
983 1.1.1.2.2.2 bouyer 0, &TableIndex);
984 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
985 1.1.1.2.2.2 bouyer {
986 1.1.1.2.2.2 bouyer fprintf (stderr, "Could not store DSDT\n");
987 1.1.1.2.2.2 bouyer return AE_NO_ACPI_TABLES;
988 1.1.1.2.2.2 bouyer }
989 1.1.1.2.2.2 bouyer }
990 1.1.1.2.2.2 bouyer else
991 1.1.1.2.2.2 bouyer {
992 1.1.1.2.2.2 bouyer fprintf (stderr, "Could not obtain DSDT\n");
993 1.1.1.2.2.2 bouyer return AE_NO_ACPI_TABLES;
994 1.1.1.2.2.2 bouyer }
995 1.1.1.2.2.2 bouyer
996 1.1.1.2.2.2 bouyer #if 0
997 1.1.1.2.2.2 bouyer /* TBD: Future implementation */
998 1.1.1.2.2.2 bouyer
999 1.1.1.2.2.2 bouyer AcpiOsPrintf ("\n");
1000 1.1.1.2.2.2 bouyer
1001 1.1.1.2.2.2 bouyer /* Get all SSDTs */
1002 1.1.1.2.2.2 bouyer
1003 1.1.1.2.2.2 bouyer ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_SSDT);
1004 1.1.1.2.2.2 bouyer do
1005 1.1.1.2.2.2 bouyer {
1006 1.1.1.2.2.2 bouyer NewTable = NULL;
1007 1.1.1.2.2.2 bouyer Status = AcpiOsTableOverride (&TableHeader, &NewTable);
1008 1.1.1.2.2.2 bouyer
1009 1.1.1.2.2.2 bouyer } while (NewTable);
1010 1.1.1.2.2.2 bouyer #endif
1011 1.1.1.2.2.2 bouyer
1012 1.1.1.2.2.2 bouyer return AE_OK;
1013 1.1.1.2.2.2 bouyer }
1014 1.1.1.2.2.2 bouyer
1015 1.1.1.2.2.2 bouyer
1016 1.1.1.2.2.2 bouyer /******************************************************************************
1017 1.1.1.2.2.2 bouyer *
1018 1.1.1.2.2.2 bouyer * FUNCTION: AdParseTable
1019 1.1.1.2.2.2 bouyer *
1020 1.1.1.2.2.2 bouyer * PARAMETERS: Table - Pointer to the raw table
1021 1.1.1.2.2.2 bouyer * OwnerId - Returned OwnerId of the table
1022 1.1.1.2.2.2 bouyer * LoadTable - If add table to the global table list
1023 1.1.1.2.2.2 bouyer * External - If this is an external table
1024 1.1.1.2.2.2 bouyer *
1025 1.1.1.2.2.2 bouyer * RETURN: Status
1026 1.1.1.2.2.2 bouyer *
1027 1.1.1.2.2.2 bouyer * DESCRIPTION: Parse the DSDT.
1028 1.1.1.2.2.2 bouyer *
1029 1.1.1.2.2.2 bouyer *****************************************************************************/
1030 1.1.1.2.2.2 bouyer
1031 1.1.1.2.2.2 bouyer ACPI_STATUS
1032 1.1.1.2.2.2 bouyer AdParseTable (
1033 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table,
1034 1.1.1.2.2.2 bouyer ACPI_OWNER_ID *OwnerId,
1035 1.1.1.2.2.2 bouyer BOOLEAN LoadTable,
1036 1.1.1.2.2.2 bouyer BOOLEAN External)
1037 1.1.1.2.2.2 bouyer {
1038 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
1039 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState;
1040 1.1.1.2.2.2 bouyer UINT8 *AmlStart;
1041 1.1.1.2.2.2 bouyer UINT32 AmlLength;
1042 1.1.1.2.2.2 bouyer UINT32 TableIndex;
1043 1.1.1.2.2.2 bouyer
1044 1.1.1.2.2.2 bouyer
1045 1.1.1.2.2.2 bouyer if (!Table)
1046 1.1.1.2.2.2 bouyer {
1047 1.1.1.2.2.2 bouyer return AE_NOT_EXIST;
1048 1.1.1.2.2.2 bouyer }
1049 1.1.1.2.2.2 bouyer
1050 1.1.1.2.2.2 bouyer /* Pass 1: Parse everything except control method bodies */
1051 1.1.1.2.2.2 bouyer
1052 1.1.1.2.2.2 bouyer fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
1053 1.1.1.2.2.2 bouyer
1054 1.1.1.2.2.2 bouyer AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
1055 1.1.1.2.2.2 bouyer AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
1056 1.1.1.2.2.2 bouyer
1057 1.1.1.2.2.2 bouyer /* Create the root object */
1058 1.1.1.2.2.2 bouyer
1059 1.1.1.2.2.2 bouyer AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp ();
1060 1.1.1.2.2.2 bouyer if (!AcpiGbl_ParseOpRoot)
1061 1.1.1.2.2.2 bouyer {
1062 1.1.1.2.2.2 bouyer return AE_NO_MEMORY;
1063 1.1.1.2.2.2 bouyer }
1064 1.1.1.2.2.2 bouyer
1065 1.1.1.2.2.2 bouyer /* Create and initialize a new walk state */
1066 1.1.1.2.2.2 bouyer
1067 1.1.1.2.2.2 bouyer WalkState = AcpiDsCreateWalkState (0,
1068 1.1.1.2.2.2 bouyer AcpiGbl_ParseOpRoot, NULL, NULL);
1069 1.1.1.2.2.2 bouyer if (!WalkState)
1070 1.1.1.2.2.2 bouyer {
1071 1.1.1.2.2.2 bouyer return (AE_NO_MEMORY);
1072 1.1.1.2.2.2 bouyer }
1073 1.1.1.2.2.2 bouyer
1074 1.1.1.2.2.2 bouyer Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
1075 1.1.1.2.2.2 bouyer NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
1076 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1077 1.1.1.2.2.2 bouyer {
1078 1.1.1.2.2.2 bouyer return (Status);
1079 1.1.1.2.2.2 bouyer }
1080 1.1.1.2.2.2 bouyer
1081 1.1.1.2.2.2 bouyer WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
1082 1.1.1.2.2.2 bouyer WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
1083 1.1.1.2.2.2 bouyer
1084 1.1.1.2.2.2 bouyer Status = AcpiPsParseAml (WalkState);
1085 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1086 1.1.1.2.2.2 bouyer {
1087 1.1.1.2.2.2 bouyer return Status;
1088 1.1.1.2.2.2 bouyer }
1089 1.1.1.2.2.2 bouyer
1090 1.1.1.2.2.2 bouyer /* If LoadTable is FALSE, we are parsing the last loaded table */
1091 1.1.1.2.2.2 bouyer
1092 1.1.1.2.2.2 bouyer TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
1093 1.1.1.2.2.2 bouyer
1094 1.1.1.2.2.2 bouyer /* Pass 2 */
1095 1.1.1.2.2.2 bouyer
1096 1.1.1.2.2.2 bouyer if (LoadTable)
1097 1.1.1.2.2.2 bouyer {
1098 1.1.1.2.2.2 bouyer Status = AcpiTbStoreTable ((ACPI_PHYSICAL_ADDRESS) Table, Table,
1099 1.1.1.2.2.2 bouyer Table->Length, ACPI_TABLE_ORIGIN_ALLOCATED, &TableIndex);
1100 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1101 1.1.1.2.2.2 bouyer {
1102 1.1.1.2.2.2 bouyer return Status;
1103 1.1.1.2.2.2 bouyer }
1104 1.1.1.2.2.2 bouyer Status = AcpiTbAllocateOwnerId (TableIndex);
1105 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1106 1.1.1.2.2.2 bouyer {
1107 1.1.1.2.2.2 bouyer return Status;
1108 1.1.1.2.2.2 bouyer }
1109 1.1.1.2.2.2 bouyer if (OwnerId)
1110 1.1.1.2.2.2 bouyer {
1111 1.1.1.2.2.2 bouyer Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
1112 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1113 1.1.1.2.2.2 bouyer {
1114 1.1.1.2.2.2 bouyer return Status;
1115 1.1.1.2.2.2 bouyer }
1116 1.1.1.2.2.2 bouyer }
1117 1.1.1.2.2.2 bouyer }
1118 1.1.1.2.2.2 bouyer
1119 1.1.1.2.2.2 bouyer fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
1120 1.1.1.2.2.2 bouyer
1121 1.1.1.2.2.2 bouyer Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
1122 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
1123 1.1.1.2.2.2 bouyer {
1124 1.1.1.2.2.2 bouyer return (Status);
1125 1.1.1.2.2.2 bouyer }
1126 1.1.1.2.2.2 bouyer
1127 1.1.1.2.2.2 bouyer /* No need to parse control methods of external table */
1128 1.1.1.2.2.2 bouyer
1129 1.1.1.2.2.2 bouyer if (External)
1130 1.1.1.2.2.2 bouyer {
1131 1.1.1.2.2.2 bouyer return AE_OK;
1132 1.1.1.2.2.2 bouyer }
1133 1.1.1.2.2.2 bouyer
1134 1.1.1.2.2.2 bouyer /* Pass 3: Parse control methods and link their parse trees into the main parse tree */
1135 1.1.1.2.2.2 bouyer
1136 1.1.1.2.2.2 bouyer Status = AdParseDeferredOps (AcpiGbl_ParseOpRoot);
1137 1.1.1.2.2.2 bouyer
1138 1.1.1.2.2.2 bouyer /* Process Resource Templates */
1139 1.1.1.2.2.2 bouyer
1140 1.1.1.2.2.2 bouyer AcpiDmFindResources (AcpiGbl_ParseOpRoot);
1141 1.1.1.2.2.2 bouyer
1142 1.1.1.2.2.2 bouyer fprintf (stderr, "Parsing completed\n");
1143 1.1.1.2.2.2 bouyer return AE_OK;
1144 1.1.1.2.2.2 bouyer }
1145 1.1.1.2.2.2 bouyer
1146 1.1.1.2.2.2 bouyer
1147