adisasm.c revision 1.1.1.7 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: adisasm - Application-level disassembler routines
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.7 christos * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1.1.4 christos #include "aslcompiler.h"
45 1.1 jruoho #include "amlcode.h"
46 1.1 jruoho #include "acdisasm.h"
47 1.1 jruoho #include "acdispat.h"
48 1.1 jruoho #include "acnamesp.h"
49 1.1.1.7 christos #include "acparser.h"
50 1.1 jruoho #include "acapps.h"
51 1.1 jruoho
52 1.1 jruoho #include <stdio.h>
53 1.1 jruoho
54 1.1 jruoho
55 1.1 jruoho #define _COMPONENT ACPI_TOOLS
56 1.1 jruoho ACPI_MODULE_NAME ("adisasm")
57 1.1 jruoho
58 1.1 jruoho /* Local prototypes */
59 1.1 jruoho
60 1.1.1.7 christos static ACPI_STATUS
61 1.1.1.7 christos AdDoExternalFileList (
62 1.1.1.7 christos char *Filename);
63 1.1.1.7 christos
64 1.1.1.7 christos static ACPI_STATUS
65 1.1.1.7 christos AdDisassembleOneTable (
66 1.1.1.7 christos ACPI_TABLE_HEADER *Table,
67 1.1.1.7 christos FILE *File,
68 1.1 jruoho char *Filename,
69 1.1.1.7 christos char *DisasmFilename);
70 1.1 jruoho
71 1.1.1.5 christos static ACPI_STATUS
72 1.1.1.7 christos AdReparseOneTable (
73 1.1.1.5 christos ACPI_TABLE_HEADER *Table,
74 1.1.1.7 christos FILE *File,
75 1.1.1.7 christos ACPI_OWNER_ID OwnerId);
76 1.1.1.5 christos
77 1.1.1.7 christos
78 1.1.1.7 christos ACPI_TABLE_DESC LocalTables[1];
79 1.1.1.7 christos ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
80 1.1.1.7 christos
81 1.1.1.7 christos
82 1.1.1.7 christos /* Stubs for everything except ASL compiler */
83 1.1 jruoho
84 1.1 jruoho #ifndef ACPI_ASL_COMPILER
85 1.1 jruoho BOOLEAN
86 1.1 jruoho AcpiDsIsResultUsed (
87 1.1 jruoho ACPI_PARSE_OBJECT *Op,
88 1.1 jruoho ACPI_WALK_STATE *WalkState)
89 1.1 jruoho {
90 1.1.1.7 christos return (TRUE);
91 1.1 jruoho }
92 1.1 jruoho
93 1.1 jruoho ACPI_STATUS
94 1.1 jruoho AcpiDsMethodError (
95 1.1 jruoho ACPI_STATUS Status,
96 1.1 jruoho ACPI_WALK_STATE *WalkState)
97 1.1 jruoho {
98 1.1 jruoho return (Status);
99 1.1 jruoho }
100 1.1 jruoho #endif
101 1.1 jruoho
102 1.1.1.3 christos
103 1.1.1.3 christos /*******************************************************************************
104 1.1.1.3 christos *
105 1.1 jruoho * FUNCTION: AdInitialize
106 1.1 jruoho *
107 1.1 jruoho * PARAMETERS: None
108 1.1 jruoho *
109 1.1 jruoho * RETURN: Status
110 1.1 jruoho *
111 1.1 jruoho * DESCRIPTION: ACPICA and local initialization
112 1.1 jruoho *
113 1.1 jruoho ******************************************************************************/
114 1.1 jruoho
115 1.1 jruoho ACPI_STATUS
116 1.1 jruoho AdInitialize (
117 1.1 jruoho void)
118 1.1 jruoho {
119 1.1 jruoho ACPI_STATUS Status;
120 1.1 jruoho
121 1.1 jruoho
122 1.1.1.4 christos /* ACPICA subsystem initialization */
123 1.1 jruoho
124 1.1 jruoho Status = AcpiOsInitialize ();
125 1.1 jruoho if (ACPI_FAILURE (Status))
126 1.1 jruoho {
127 1.1 jruoho return (Status);
128 1.1 jruoho }
129 1.1 jruoho
130 1.1 jruoho Status = AcpiUtInitGlobals ();
131 1.1 jruoho if (ACPI_FAILURE (Status))
132 1.1 jruoho {
133 1.1 jruoho return (Status);
134 1.1 jruoho }
135 1.1 jruoho
136 1.1 jruoho Status = AcpiUtMutexInitialize ();
137 1.1 jruoho if (ACPI_FAILURE (Status))
138 1.1 jruoho {
139 1.1 jruoho return (Status);
140 1.1 jruoho }
141 1.1 jruoho
142 1.1 jruoho Status = AcpiNsRootInitialize ();
143 1.1 jruoho if (ACPI_FAILURE (Status))
144 1.1 jruoho {
145 1.1 jruoho return (Status);
146 1.1 jruoho }
147 1.1 jruoho
148 1.1 jruoho /* Setup the Table Manager (cheat - there is no RSDT) */
149 1.1 jruoho
150 1.1 jruoho AcpiGbl_RootTableList.MaxTableCount = 1;
151 1.1 jruoho AcpiGbl_RootTableList.CurrentTableCount = 0;
152 1.1 jruoho AcpiGbl_RootTableList.Tables = LocalTables;
153 1.1 jruoho
154 1.1 jruoho return (Status);
155 1.1 jruoho }
156 1.1 jruoho
157 1.1 jruoho
158 1.1 jruoho /******************************************************************************
159 1.1 jruoho *
160 1.1 jruoho * FUNCTION: AdAmlDisassemble
161 1.1 jruoho *
162 1.1 jruoho * PARAMETERS: Filename - AML input filename
163 1.1 jruoho * OutToFile - TRUE if output should go to a file
164 1.1 jruoho * Prefix - Path prefix for output
165 1.1 jruoho * OutFilename - where the filename is returned
166 1.1 jruoho *
167 1.1 jruoho * RETURN: Status
168 1.1 jruoho *
169 1.1.1.7 christos * DESCRIPTION: Disassembler entry point. Disassemble an entire ACPI table.
170 1.1 jruoho *
171 1.1 jruoho *****************************************************************************/
172 1.1 jruoho
173 1.1 jruoho ACPI_STATUS
174 1.1 jruoho AdAmlDisassemble (
175 1.1 jruoho BOOLEAN OutToFile,
176 1.1 jruoho char *Filename,
177 1.1 jruoho char *Prefix,
178 1.1.1.4 christos char **OutFilename)
179 1.1 jruoho {
180 1.1 jruoho ACPI_STATUS Status;
181 1.1 jruoho char *DisasmFilename = NULL;
182 1.1 jruoho FILE *File = NULL;
183 1.1 jruoho ACPI_TABLE_HEADER *Table = NULL;
184 1.1.1.7 christos ACPI_NEW_TABLE_DESC *ListHead = NULL;
185 1.1 jruoho
186 1.1 jruoho
187 1.1 jruoho /*
188 1.1 jruoho * Input: AML code from either a file or via GetTables (memory or
189 1.1 jruoho * registry)
190 1.1 jruoho */
191 1.1 jruoho if (Filename)
192 1.1 jruoho {
193 1.1.1.7 christos /* Get the list of all AML tables in the file */
194 1.1.1.7 christos
195 1.1.1.7 christos Status = AcGetAllTablesFromFile (Filename,
196 1.1.1.7 christos ACPI_GET_ALL_TABLES, &ListHead);
197 1.1 jruoho if (ACPI_FAILURE (Status))
198 1.1 jruoho {
199 1.1.1.7 christos AcpiOsPrintf ("Could not get ACPI tables from %s, %s\n",
200 1.1.1.7 christos Filename, AcpiFormatException (Status));
201 1.1.1.3 christos return (Status);
202 1.1 jruoho }
203 1.1 jruoho
204 1.1.1.7 christos /* Process any user-specified files for external objects */
205 1.1 jruoho
206 1.1.1.7 christos Status = AdDoExternalFileList (Filename);
207 1.1.1.7 christos if (ACPI_FAILURE (Status))
208 1.1.1.2 jruoho {
209 1.1.1.7 christos return (Status);
210 1.1 jruoho }
211 1.1 jruoho }
212 1.1 jruoho else
213 1.1 jruoho {
214 1.1.1.4 christos Status = AdGetLocalTables ();
215 1.1 jruoho if (ACPI_FAILURE (Status))
216 1.1 jruoho {
217 1.1 jruoho AcpiOsPrintf ("Could not get ACPI tables, %s\n",
218 1.1 jruoho AcpiFormatException (Status));
219 1.1.1.3 christos return (Status);
220 1.1 jruoho }
221 1.1 jruoho
222 1.1.1.7 christos if (!AcpiGbl_DmOpt_Disasm)
223 1.1 jruoho {
224 1.1.1.3 christos return (AE_OK);
225 1.1 jruoho }
226 1.1 jruoho
227 1.1 jruoho /* Obtained the local tables, just disassemble the DSDT */
228 1.1 jruoho
229 1.1 jruoho Status = AcpiGetTable (ACPI_SIG_DSDT, 0, &Table);
230 1.1 jruoho if (ACPI_FAILURE (Status))
231 1.1 jruoho {
232 1.1 jruoho AcpiOsPrintf ("Could not get DSDT, %s\n",
233 1.1 jruoho AcpiFormatException (Status));
234 1.1.1.3 christos return (Status);
235 1.1 jruoho }
236 1.1 jruoho
237 1.1 jruoho AcpiOsPrintf ("\nDisassembly of DSDT\n");
238 1.1 jruoho Prefix = AdGenerateFilename ("dsdt", Table->OemTableId);
239 1.1 jruoho }
240 1.1 jruoho
241 1.1 jruoho /*
242 1.1.1.3 christos * Output: ASL code. Redirect to a file if requested
243 1.1 jruoho */
244 1.1 jruoho if (OutToFile)
245 1.1 jruoho {
246 1.1 jruoho /* Create/Open a disassembly output file */
247 1.1 jruoho
248 1.1 jruoho DisasmFilename = FlGenerateFilename (Prefix, FILE_SUFFIX_DISASSEMBLY);
249 1.1.1.4 christos if (!DisasmFilename)
250 1.1 jruoho {
251 1.1 jruoho fprintf (stderr, "Could not generate output filename\n");
252 1.1 jruoho Status = AE_ERROR;
253 1.1 jruoho goto Cleanup;
254 1.1 jruoho }
255 1.1 jruoho
256 1.1 jruoho File = fopen (DisasmFilename, "w+");
257 1.1 jruoho if (!File)
258 1.1 jruoho {
259 1.1.1.7 christos fprintf (stderr, "Could not open output file %s\n",
260 1.1.1.7 christos DisasmFilename);
261 1.1 jruoho Status = AE_ERROR;
262 1.1 jruoho goto Cleanup;
263 1.1 jruoho }
264 1.1 jruoho
265 1.1 jruoho AcpiOsRedirectOutput (File);
266 1.1 jruoho }
267 1.1 jruoho
268 1.1 jruoho *OutFilename = DisasmFilename;
269 1.1 jruoho
270 1.1.1.7 christos /* Disassemble all AML tables within the file */
271 1.1.1.5 christos
272 1.1.1.7 christos while (ListHead)
273 1.1 jruoho {
274 1.1.1.7 christos Status = AdDisassembleOneTable (ListHead->Table,
275 1.1.1.7 christos File, Filename, DisasmFilename);
276 1.1 jruoho if (ACPI_FAILURE (Status))
277 1.1 jruoho {
278 1.1.1.7 christos break;
279 1.1 jruoho }
280 1.1 jruoho
281 1.1.1.7 christos ListHead = ListHead->Next;
282 1.1 jruoho }
283 1.1 jruoho
284 1.1 jruoho Cleanup:
285 1.1 jruoho
286 1.1.1.7 christos if (Table &&
287 1.1.1.7 christos !AcpiGbl_ForceAmlDisassembly &&
288 1.1.1.7 christos !AcpiUtIsAmlTable (Table))
289 1.1 jruoho {
290 1.1 jruoho ACPI_FREE (Table);
291 1.1 jruoho }
292 1.1 jruoho
293 1.1.1.5 christos if (File)
294 1.1 jruoho {
295 1.1 jruoho fclose (File);
296 1.1 jruoho AcpiOsRedirectOutput (stdout);
297 1.1 jruoho }
298 1.1 jruoho
299 1.1 jruoho AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
300 1.1 jruoho AcpiGbl_ParseOpRoot = NULL;
301 1.1 jruoho return (Status);
302 1.1 jruoho }
303 1.1 jruoho
304 1.1 jruoho
305 1.1 jruoho /******************************************************************************
306 1.1 jruoho *
307 1.1.1.7 christos * FUNCTION: AdDisassembleOneTable
308 1.1 jruoho *
309 1.1.1.7 christos * PARAMETERS: Table - Raw AML table
310 1.1.1.7 christos * File - Pointer for the input file
311 1.1.1.7 christos * Filename - AML input filename
312 1.1.1.7 christos * DisasmFilename - Output filename
313 1.1 jruoho *
314 1.1.1.7 christos * RETURN: Status
315 1.1 jruoho *
316 1.1.1.7 christos * DESCRIPTION: Disassemble a single ACPI table. AML or data table.
317 1.1 jruoho *
318 1.1 jruoho *****************************************************************************/
319 1.1 jruoho
320 1.1.1.7 christos static ACPI_STATUS
321 1.1.1.7 christos AdDisassembleOneTable (
322 1.1.1.7 christos ACPI_TABLE_HEADER *Table,
323 1.1.1.7 christos FILE *File,
324 1.1.1.5 christos char *Filename,
325 1.1.1.7 christos char *DisasmFilename)
326 1.1 jruoho {
327 1.1.1.7 christos ACPI_STATUS Status;
328 1.1.1.7 christos ACPI_OWNER_ID OwnerId;
329 1.1 jruoho
330 1.1 jruoho
331 1.1.1.7 christos /* ForceAmlDisassembly means to assume the table contains valid AML */
332 1.1.1.5 christos
333 1.1.1.7 christos if (!AcpiGbl_ForceAmlDisassembly && !AcpiUtIsAmlTable (Table))
334 1.1.1.5 christos {
335 1.1.1.7 christos AdDisassemblerHeader (Filename, ACPI_IS_DATA_TABLE);
336 1.1 jruoho
337 1.1.1.7 christos /* This is a "Data Table" (non-AML table) */
338 1.1 jruoho
339 1.1.1.7 christos AcpiOsPrintf (" * ACPI Data Table [%4.4s]\n *\n",
340 1.1.1.7 christos Table->Signature);
341 1.1.1.7 christos AcpiOsPrintf (" * Format: [HexOffset DecimalOffset ByteLength] "
342 1.1.1.7 christos "FieldName : FieldValue\n */\n\n");
343 1.1 jruoho
344 1.1.1.7 christos AcpiDmDumpDataTable (Table);
345 1.1.1.7 christos fprintf (stderr, "Acpi Data Table [%4.4s] decoded\n",
346 1.1.1.7 christos Table->Signature);
347 1.1 jruoho
348 1.1.1.7 christos if (File)
349 1.1.1.7 christos {
350 1.1.1.7 christos fprintf (stderr, "Formatted output: %s - %u bytes\n",
351 1.1.1.7 christos DisasmFilename, CmGetFileSize (File));
352 1.1.1.7 christos }
353 1.1 jruoho
354 1.1.1.7 christos return (AE_OK);
355 1.1.1.7 christos }
356 1.1 jruoho
357 1.1 jruoho /*
358 1.1.1.7 christos * This is an AML table (DSDT or SSDT).
359 1.1.1.7 christos * Always parse the tables, only option is what to display
360 1.1 jruoho */
361 1.1.1.7 christos Status = AdParseTable (Table, &OwnerId, TRUE, FALSE);
362 1.1.1.7 christos if (ACPI_FAILURE (Status))
363 1.1.1.7 christos {
364 1.1.1.7 christos AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
365 1.1.1.7 christos AcpiFormatException (Status));
366 1.1.1.7 christos return (Status);
367 1.1.1.7 christos }
368 1.1 jruoho
369 1.1.1.7 christos /* Debug output, namespace and parse tree */
370 1.1 jruoho
371 1.1.1.7 christos if (AslCompilerdebug && File)
372 1.1 jruoho {
373 1.1.1.7 christos AcpiOsPrintf ("/**** Before second load\n");
374 1.1.1.3 christos
375 1.1.1.7 christos NsSetupNamespaceListing (File);
376 1.1.1.7 christos NsDisplayNamespace ();
377 1.1 jruoho
378 1.1.1.7 christos AcpiOsPrintf ("*****/\n");
379 1.1.1.7 christos }
380 1.1.1.3 christos
381 1.1.1.7 christos /* Load namespace from names created within control methods */
382 1.1 jruoho
383 1.1.1.7 christos AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
384 1.1.1.7 christos AcpiGbl_RootNode, OwnerId);
385 1.1 jruoho
386 1.1.1.7 christos /*
387 1.1.1.7 christos * Cross reference the namespace here, in order to
388 1.1.1.7 christos * generate External() statements
389 1.1.1.7 christos */
390 1.1.1.7 christos AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
391 1.1.1.7 christos AcpiGbl_RootNode, OwnerId);
392 1.1.1.3 christos
393 1.1.1.7 christos if (AslCompilerdebug)
394 1.1.1.7 christos {
395 1.1.1.7 christos AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
396 1.1 jruoho }
397 1.1 jruoho
398 1.1.1.7 christos /* Find possible calls to external control methods */
399 1.1 jruoho
400 1.1.1.7 christos AcpiDmFindOrphanMethods (AcpiGbl_ParseOpRoot);
401 1.1 jruoho
402 1.1.1.7 christos /*
403 1.1.1.7 christos * If we found any external control methods, we must reparse
404 1.1.1.7 christos * the entire tree with the new information (namely, the
405 1.1.1.7 christos * number of arguments per method)
406 1.1.1.7 christos */
407 1.1.1.7 christos if (AcpiDmGetExternalMethodCount ())
408 1.1 jruoho {
409 1.1.1.7 christos Status = AdReparseOneTable (Table, File, OwnerId);
410 1.1.1.7 christos if (ACPI_FAILURE (Status))
411 1.1.1.7 christos {
412 1.1.1.7 christos return (Status);
413 1.1.1.7 christos }
414 1.1 jruoho }
415 1.1 jruoho
416 1.1.1.7 christos /*
417 1.1.1.7 christos * Now that the namespace is finalized, we can perform namespace
418 1.1.1.7 christos * transforms.
419 1.1.1.7 christos *
420 1.1.1.7 christos * 1) Convert fixed-offset references to resource descriptors
421 1.1.1.7 christos * to symbolic references (Note: modifies namespace)
422 1.1.1.7 christos */
423 1.1.1.7 christos AcpiDmConvertResourceIndexes (AcpiGbl_ParseOpRoot, AcpiGbl_RootNode);
424 1.1 jruoho
425 1.1.1.7 christos /* Optional displays */
426 1.1 jruoho
427 1.1.1.7 christos if (AcpiGbl_DmOpt_Disasm)
428 1.1 jruoho {
429 1.1.1.7 christos /* This is the real disassembly */
430 1.1.1.7 christos
431 1.1.1.7 christos AdDisplayTables (Filename, Table);
432 1.1.1.7 christos
433 1.1.1.7 christos /* Dump hex table if requested (-vt) */
434 1.1.1.7 christos
435 1.1.1.7 christos AcpiDmDumpDataTable (Table);
436 1.1.1.7 christos
437 1.1.1.7 christos fprintf (stderr, "Disassembly completed\n");
438 1.1.1.7 christos if (File)
439 1.1.1.4 christos {
440 1.1.1.7 christos fprintf (stderr, "ASL Output: %s - %u bytes\n",
441 1.1.1.7 christos DisasmFilename, CmGetFileSize (File));
442 1.1.1.4 christos }
443 1.1.1.4 christos
444 1.1.1.7 christos if (Gbl_MapfileFlag)
445 1.1.1.7 christos {
446 1.1.1.7 christos fprintf (stderr, "%14s %s - %u bytes\n",
447 1.1.1.7 christos Gbl_Files[ASL_FILE_MAP_OUTPUT].ShortDescription,
448 1.1.1.7 christos Gbl_Files[ASL_FILE_MAP_OUTPUT].Filename,
449 1.1.1.7 christos FlGetFileSize (ASL_FILE_MAP_OUTPUT));
450 1.1.1.7 christos }
451 1.1 jruoho }
452 1.1 jruoho
453 1.1.1.7 christos return (AE_OK);
454 1.1 jruoho }
455 1.1 jruoho
456 1.1 jruoho
457 1.1 jruoho /******************************************************************************
458 1.1 jruoho *
459 1.1.1.7 christos * FUNCTION: AdReparseOneTable
460 1.1 jruoho *
461 1.1.1.7 christos * PARAMETERS: Table - Raw AML table
462 1.1.1.7 christos * File - Pointer for the input file
463 1.1.1.7 christos * OwnerId - ID for this table
464 1.1 jruoho *
465 1.1 jruoho * RETURN: Status
466 1.1 jruoho *
467 1.1.1.7 christos * DESCRIPTION: Reparse a table that has already been loaded. Used to
468 1.1.1.7 christos * integrate information about external control methods.
469 1.1.1.7 christos * These methods may have been previously parsed incorrectly.
470 1.1 jruoho *
471 1.1 jruoho *****************************************************************************/
472 1.1 jruoho
473 1.1.1.7 christos static ACPI_STATUS
474 1.1.1.7 christos AdReparseOneTable (
475 1.1.1.7 christos ACPI_TABLE_HEADER *Table,
476 1.1.1.7 christos FILE *File,
477 1.1.1.7 christos ACPI_OWNER_ID OwnerId)
478 1.1 jruoho {
479 1.1.1.7 christos ACPI_STATUS Status;
480 1.1 jruoho
481 1.1 jruoho
482 1.1.1.7 christos fprintf (stderr,
483 1.1.1.7 christos "\nFound %u external control methods, "
484 1.1.1.7 christos "reparsing with new information\n",
485 1.1.1.7 christos AcpiDmGetExternalMethodCount ());
486 1.1 jruoho
487 1.1.1.7 christos /* Reparse, rebuild namespace */
488 1.1 jruoho
489 1.1.1.7 christos AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
490 1.1.1.7 christos AcpiGbl_ParseOpRoot = NULL;
491 1.1.1.7 christos AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
492 1.1 jruoho
493 1.1.1.7 christos AcpiGbl_RootNode = NULL;
494 1.1.1.7 christos AcpiGbl_RootNodeStruct.Name.Integer = ACPI_ROOT_NAME;
495 1.1.1.7 christos AcpiGbl_RootNodeStruct.DescriptorType = ACPI_DESC_TYPE_NAMED;
496 1.1.1.7 christos AcpiGbl_RootNodeStruct.Type = ACPI_TYPE_DEVICE;
497 1.1.1.7 christos AcpiGbl_RootNodeStruct.Parent = NULL;
498 1.1.1.7 christos AcpiGbl_RootNodeStruct.Child = NULL;
499 1.1.1.7 christos AcpiGbl_RootNodeStruct.Peer = NULL;
500 1.1.1.7 christos AcpiGbl_RootNodeStruct.Object = NULL;
501 1.1.1.7 christos AcpiGbl_RootNodeStruct.Flags = 0;
502 1.1 jruoho
503 1.1.1.7 christos Status = AcpiNsRootInitialize ();
504 1.1.1.7 christos if (ACPI_FAILURE (Status))
505 1.1.1.7 christos {
506 1.1.1.7 christos return (Status);
507 1.1 jruoho }
508 1.1 jruoho
509 1.1.1.7 christos /* New namespace, add the external definitions first */
510 1.1.1.5 christos
511 1.1.1.7 christos AcpiDmAddExternalsToNamespace ();
512 1.1.1.5 christos
513 1.1.1.7 christos /* Parse the table again. No need to reload it, however */
514 1.1.1.5 christos
515 1.1.1.7 christos Status = AdParseTable (Table, NULL, FALSE, FALSE);
516 1.1.1.5 christos if (ACPI_FAILURE (Status))
517 1.1.1.5 christos {
518 1.1.1.7 christos AcpiOsPrintf ("Could not parse ACPI tables, %s\n",
519 1.1.1.7 christos AcpiFormatException (Status));
520 1.1.1.5 christos return (Status);
521 1.1.1.5 christos }
522 1.1.1.5 christos
523 1.1.1.7 christos /* Cross reference the namespace again */
524 1.1 jruoho
525 1.1.1.7 christos AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
526 1.1.1.7 christos AcpiGbl_RootNode, OwnerId);
527 1.1 jruoho
528 1.1.1.7 christos AcpiDmCrossReferenceNamespace (AcpiGbl_ParseOpRoot,
529 1.1.1.7 christos AcpiGbl_RootNode, OwnerId);
530 1.1 jruoho
531 1.1.1.7 christos /* Debug output - namespace and parse tree */
532 1.1 jruoho
533 1.1.1.7 christos if (AslCompilerdebug)
534 1.1 jruoho {
535 1.1.1.7 christos AcpiOsPrintf ("/**** After second load and resource conversion\n");
536 1.1.1.7 christos if (File)
537 1.1.1.7 christos {
538 1.1.1.7 christos NsSetupNamespaceListing (File);
539 1.1.1.7 christos NsDisplayNamespace ();
540 1.1.1.7 christos }
541 1.1 jruoho
542 1.1.1.7 christos AcpiOsPrintf ("*****/\n");
543 1.1.1.7 christos AcpiDmDumpTree (AcpiGbl_ParseOpRoot);
544 1.1.1.4 christos }
545 1.1 jruoho
546 1.1.1.3 christos return (AE_OK);
547 1.1 jruoho }
548 1.1 jruoho
549 1.1 jruoho
550 1.1 jruoho /******************************************************************************
551 1.1 jruoho *
552 1.1.1.7 christos * FUNCTION: AdDoExternalFileList
553 1.1 jruoho *
554 1.1.1.7 christos * PARAMETERS: Filename - Input file for the table
555 1.1 jruoho *
556 1.1 jruoho * RETURN: Status
557 1.1 jruoho *
558 1.1.1.7 christos * DESCRIPTION: Process all tables found in the -e external files list
559 1.1 jruoho *
560 1.1 jruoho *****************************************************************************/
561 1.1 jruoho
562 1.1.1.7 christos static ACPI_STATUS
563 1.1.1.7 christos AdDoExternalFileList (
564 1.1.1.7 christos char *Filename)
565 1.1 jruoho {
566 1.1.1.7 christos ACPI_EXTERNAL_FILE *ExternalFileList;
567 1.1.1.7 christos char *ExternalFilename;
568 1.1.1.7 christos ACPI_NEW_TABLE_DESC *ExternalListHead = NULL;
569 1.1.1.7 christos ACPI_STATUS Status;
570 1.1.1.7 christos ACPI_STATUS GlobalStatus = AE_OK;
571 1.1.1.7 christos ACPI_OWNER_ID OwnerId;
572 1.1 jruoho
573 1.1 jruoho
574 1.1.1.7 christos /*
575 1.1.1.7 christos * External filenames are specified on the command line like this:
576 1.1.1.7 christos * Example: iasl -e file1,file2,file3 -d xxx.aml
577 1.1.1.7 christos */
578 1.1.1.7 christos ExternalFileList = AcpiGbl_ExternalFileList;
579 1.1 jruoho
580 1.1.1.7 christos /* Process each external file */
581 1.1 jruoho
582 1.1.1.7 christos while (ExternalFileList)
583 1.1 jruoho {
584 1.1.1.7 christos ExternalFilename = ExternalFileList->Path;
585 1.1.1.7 christos if (!strcmp (ExternalFilename, Filename))
586 1.1.1.7 christos {
587 1.1.1.7 christos /* Next external file */
588 1.1 jruoho
589 1.1.1.7 christos ExternalFileList = ExternalFileList->Next;
590 1.1.1.7 christos continue;
591 1.1.1.7 christos }
592 1.1 jruoho
593 1.1.1.7 christos AcpiOsPrintf ("External object resolution file %16s\n",
594 1.1.1.7 christos ExternalFilename);
595 1.1 jruoho
596 1.1.1.7 christos Status = AcGetAllTablesFromFile (
597 1.1.1.7 christos ExternalFilename, ACPI_GET_ONLY_AML_TABLES, &ExternalListHead);
598 1.1 jruoho if (ACPI_FAILURE (Status))
599 1.1 jruoho {
600 1.1.1.7 christos if (Status == AE_TYPE)
601 1.1.1.7 christos {
602 1.1.1.7 christos ExternalFileList = ExternalFileList->Next;
603 1.1.1.7 christos GlobalStatus = AE_TYPE;
604 1.1.1.7 christos Status = AE_OK;
605 1.1.1.7 christos continue;
606 1.1.1.7 christos }
607 1.1.1.7 christos
608 1.1.1.3 christos return (Status);
609 1.1 jruoho }
610 1.1.1.7 christos
611 1.1.1.7 christos /* Load external tables for symbol resolution */
612 1.1.1.7 christos
613 1.1.1.7 christos while (ExternalListHead)
614 1.1 jruoho {
615 1.1.1.7 christos Status = AdParseTable (
616 1.1.1.7 christos ExternalListHead->Table, &OwnerId, TRUE, TRUE);
617 1.1 jruoho if (ACPI_FAILURE (Status))
618 1.1 jruoho {
619 1.1.1.7 christos AcpiOsPrintf ("Could not parse external ACPI tables, %s\n",
620 1.1.1.7 christos AcpiFormatException (Status));
621 1.1.1.3 christos return (Status);
622 1.1 jruoho }
623 1.1.1.7 christos
624 1.1.1.7 christos /*
625 1.1.1.7 christos * Load namespace from names created within control methods
626 1.1.1.7 christos * Set owner id of nodes in external table
627 1.1.1.7 christos */
628 1.1.1.7 christos AcpiDmFinishNamespaceLoad (AcpiGbl_ParseOpRoot,
629 1.1.1.7 christos AcpiGbl_RootNode, OwnerId);
630 1.1.1.7 christos AcpiPsDeleteParseTree (AcpiGbl_ParseOpRoot);
631 1.1.1.7 christos
632 1.1.1.7 christos ExternalListHead = ExternalListHead->Next;
633 1.1 jruoho }
634 1.1 jruoho
635 1.1.1.7 christos /* Next external file */
636 1.1 jruoho
637 1.1.1.7 christos ExternalFileList = ExternalFileList->Next;
638 1.1 jruoho }
639 1.1 jruoho
640 1.1.1.7 christos if (ACPI_FAILURE (GlobalStatus))
641 1.1 jruoho {
642 1.1.1.7 christos return (GlobalStatus);
643 1.1 jruoho }
644 1.1 jruoho
645 1.1.1.7 christos /* Clear external list generated by Scope in external tables */
646 1.1 jruoho
647 1.1.1.7 christos if (AcpiGbl_ExternalFileList)
648 1.1.1.7 christos {
649 1.1.1.7 christos AcpiDmClearExternalList ();
650 1.1.1.7 christos }
651 1.1 jruoho
652 1.1.1.7 christos /* Load any externals defined in the optional external ref file */
653 1.1 jruoho
654 1.1.1.7 christos AcpiDmGetExternalsFromFile ();
655 1.1.1.3 christos return (AE_OK);
656 1.1 jruoho }
657