dmtables.c revision 1.1.1.2.2.1 1 1.1 christos /******************************************************************************
2 1.1 christos *
3 1.1 christos * Module Name: dmtables - disassembler ACPI table support
4 1.1 christos *
5 1.1 christos *****************************************************************************/
6 1.1 christos
7 1.1 christos /*
8 1.1 christos * Copyright (C) 2000 - 2016, Intel Corp.
9 1.1 christos * All rights reserved.
10 1.1 christos *
11 1.1 christos * Redistribution and use in source and binary forms, with or without
12 1.1 christos * modification, are permitted provided that the following conditions
13 1.1 christos * are met:
14 1.1 christos * 1. Redistributions of source code must retain the above copyright
15 1.1 christos * notice, this list of conditions, and the following disclaimer,
16 1.1 christos * without modification.
17 1.1 christos * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1 christos * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1 christos * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1 christos * including a substantially similar Disclaimer requirement for further
21 1.1 christos * binary redistribution.
22 1.1 christos * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1 christos * of any contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * Alternatively, this software may be distributed under the terms of the
27 1.1 christos * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1 christos * Software Foundation.
29 1.1 christos *
30 1.1 christos * NO WARRANTY
31 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1 christos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1 christos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1 christos * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1 christos * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1 christos * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1 christos * POSSIBILITY OF SUCH DAMAGES.
42 1.1 christos */
43 1.1 christos
44 1.1 christos #include "aslcompiler.h"
45 1.1 christos #include "acdispat.h"
46 1.1 christos #include "acnamesp.h"
47 1.1 christos #include "actables.h"
48 1.1 christos #include "acparser.h"
49 1.1.1.2.2.1 pgoyette #include "acapps.h"
50 1.1 christos
51 1.1 christos
52 1.1 christos #define _COMPONENT ACPI_TOOLS
53 1.1 christos ACPI_MODULE_NAME ("dmtables")
54 1.1 christos
55 1.1 christos
56 1.1 christos /* Local prototypes */
57 1.1 christos
58 1.1 christos static void
59 1.1 christos AdCreateTableHeader (
60 1.1 christos char *Filename,
61 1.1 christos ACPI_TABLE_HEADER *Table);
62 1.1 christos
63 1.1 christos static ACPI_STATUS
64 1.1 christos AdStoreTable (
65 1.1 christos ACPI_TABLE_HEADER *Table,
66 1.1 christos UINT32 *TableIndex);
67 1.1 christos
68 1.1 christos
69 1.1 christos extern ACPI_TABLE_DESC LocalTables[1];
70 1.1 christos extern ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
71 1.1 christos
72 1.1 christos
73 1.1 christos /******************************************************************************
74 1.1 christos *
75 1.1 christos * FUNCTION: AdDisassemblerHeader
76 1.1 christos *
77 1.1 christos * PARAMETERS: Filename - Input file for the table
78 1.1 christos * TableType - Either AML or DataTable
79 1.1 christos *
80 1.1 christos * RETURN: None
81 1.1 christos *
82 1.1 christos * DESCRIPTION: Create the disassembler header, including ACPICA signon with
83 1.1 christos * current time and date.
84 1.1 christos *
85 1.1 christos *****************************************************************************/
86 1.1 christos
87 1.1 christos void
88 1.1 christos AdDisassemblerHeader (
89 1.1 christos char *Filename,
90 1.1 christos UINT8 TableType)
91 1.1 christos {
92 1.1 christos time_t Timer;
93 1.1 christos
94 1.1 christos
95 1.1 christos time (&Timer);
96 1.1 christos
97 1.1 christos /* Header and input table info */
98 1.1 christos
99 1.1 christos AcpiOsPrintf ("/*\n");
100 1.1 christos AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
101 1.1 christos
102 1.1 christos if (TableType == ACPI_IS_AML_TABLE)
103 1.1 christos {
104 1.1 christos if (AcpiGbl_CstyleDisassembly)
105 1.1 christos {
106 1.1 christos AcpiOsPrintf (
107 1.1 christos " * Disassembling to symbolic ASL+ operators\n"
108 1.1 christos " *\n");
109 1.1 christos }
110 1.1 christos else
111 1.1 christos {
112 1.1 christos AcpiOsPrintf (
113 1.1 christos " * Disassembling to non-symbolic legacy ASL operators\n"
114 1.1 christos " *\n");
115 1.1 christos }
116 1.1 christos }
117 1.1 christos
118 1.1 christos AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
119 1.1 christos AcpiOsPrintf (" *\n");
120 1.1 christos }
121 1.1 christos
122 1.1 christos
123 1.1 christos /******************************************************************************
124 1.1 christos *
125 1.1 christos * FUNCTION: AdCreateTableHeader
126 1.1 christos *
127 1.1 christos * PARAMETERS: Filename - Input file for the table
128 1.1 christos * Table - Pointer to the raw table
129 1.1 christos *
130 1.1 christos * RETURN: None
131 1.1 christos *
132 1.1 christos * DESCRIPTION: Create the ASL table header, including ACPICA signon with
133 1.1 christos * current time and date.
134 1.1 christos *
135 1.1 christos *****************************************************************************/
136 1.1 christos
137 1.1 christos static void
138 1.1 christos AdCreateTableHeader (
139 1.1 christos char *Filename,
140 1.1 christos ACPI_TABLE_HEADER *Table)
141 1.1 christos {
142 1.1 christos UINT8 Checksum;
143 1.1 christos
144 1.1 christos
145 1.1.1.2 christos /* Reset globals for External statements */
146 1.1.1.2 christos
147 1.1.1.2 christos AcpiGbl_NumExternalMethods = 0;
148 1.1.1.2 christos AcpiGbl_ResolvedExternalMethods = 0;
149 1.1.1.2 christos
150 1.1 christos /*
151 1.1 christos * Print file header and dump original table header
152 1.1 christos */
153 1.1 christos AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
154 1.1 christos
155 1.1 christos AcpiOsPrintf (" * Original Table Header:\n");
156 1.1 christos AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
157 1.1 christos AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
158 1.1 christos
159 1.1 christos /* Print and validate the revision */
160 1.1 christos
161 1.1 christos AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
162 1.1 christos
163 1.1 christos switch (Table->Revision)
164 1.1 christos {
165 1.1 christos case 0:
166 1.1 christos
167 1.1 christos AcpiOsPrintf (" **** Invalid Revision");
168 1.1 christos break;
169 1.1 christos
170 1.1 christos case 1:
171 1.1 christos
172 1.1 christos /* Revision of DSDT controls the ACPI integer width */
173 1.1 christos
174 1.1 christos if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
175 1.1 christos {
176 1.1 christos AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
177 1.1 christos }
178 1.1 christos break;
179 1.1 christos
180 1.1 christos default:
181 1.1 christos
182 1.1 christos break;
183 1.1 christos }
184 1.1 christos
185 1.1 christos /* Print and validate the table checksum */
186 1.1 christos
187 1.1.1.2 christos AcpiOsPrintf ("\n * Checksum 0x%2.2X", Table->Checksum);
188 1.1 christos
189 1.1 christos Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
190 1.1 christos if (Checksum)
191 1.1 christos {
192 1.1 christos AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
193 1.1 christos (UINT8) (Table->Checksum - Checksum));
194 1.1 christos }
195 1.1 christos
196 1.1 christos AcpiOsPrintf ("\n");
197 1.1 christos AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
198 1.1 christos AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
199 1.1 christos AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
200 1.1 christos AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
201 1.1 christos AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
202 1.1 christos AcpiOsPrintf (" */\n");
203 1.1 christos
204 1.1.1.2 christos /*
205 1.1.1.2 christos * Open the ASL definition block.
206 1.1.1.2 christos *
207 1.1.1.2 christos * Note: the AMLFilename string is left zero-length in order to just let
208 1.1.1.2 christos * the compiler create it when the disassembled file is compiled. This
209 1.1.1.2 christos * makes it easier to rename the disassembled ASL file if needed.
210 1.1.1.2 christos */
211 1.1 christos AcpiOsPrintf (
212 1.1.1.2 christos "DefinitionBlock (\"\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
213 1.1.1.2 christos Table->Signature, Table->Revision,
214 1.1 christos Table->OemId, Table->OemTableId, Table->OemRevision);
215 1.1 christos }
216 1.1 christos
217 1.1 christos
218 1.1 christos /******************************************************************************
219 1.1 christos *
220 1.1 christos * FUNCTION: AdDisplayTables
221 1.1 christos *
222 1.1 christos * PARAMETERS: Filename - Input file for the table
223 1.1 christos * Table - Pointer to the raw table
224 1.1 christos *
225 1.1 christos * RETURN: Status
226 1.1 christos *
227 1.1 christos * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
228 1.1 christos *
229 1.1 christos *****************************************************************************/
230 1.1 christos
231 1.1 christos ACPI_STATUS
232 1.1 christos AdDisplayTables (
233 1.1 christos char *Filename,
234 1.1 christos ACPI_TABLE_HEADER *Table)
235 1.1 christos {
236 1.1 christos
237 1.1 christos
238 1.1 christos if (!AcpiGbl_ParseOpRoot)
239 1.1 christos {
240 1.1 christos return (AE_NOT_EXIST);
241 1.1 christos }
242 1.1 christos
243 1.1 christos if (!AcpiGbl_DmOpt_Listing)
244 1.1 christos {
245 1.1 christos AdCreateTableHeader (Filename, Table);
246 1.1 christos }
247 1.1 christos
248 1.1 christos AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
249 1.1 christos MpEmitMappingInfo ();
250 1.1 christos
251 1.1 christos if (AcpiGbl_DmOpt_Listing)
252 1.1 christos {
253 1.1 christos AcpiOsPrintf ("\n\nTable Header:\n");
254 1.1 christos AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
255 1.1 christos DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
256 1.1 christos
257 1.1 christos AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
258 1.1 christos AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
259 1.1 christos Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
260 1.1 christos }
261 1.1 christos
262 1.1 christos return (AE_OK);
263 1.1 christos }
264 1.1 christos
265 1.1 christos
266 1.1 christos /*******************************************************************************
267 1.1 christos *
268 1.1 christos * FUNCTION: AdStoreTable
269 1.1 christos *
270 1.1 christos * PARAMETERS: Table - Table header
271 1.1 christos * TableIndex - Where the table index is returned
272 1.1 christos *
273 1.1 christos * RETURN: Status and table index.
274 1.1 christos *
275 1.1 christos * DESCRIPTION: Add an ACPI table to the global table list
276 1.1 christos *
277 1.1 christos ******************************************************************************/
278 1.1 christos
279 1.1 christos static ACPI_STATUS
280 1.1 christos AdStoreTable (
281 1.1 christos ACPI_TABLE_HEADER *Table,
282 1.1 christos UINT32 *TableIndex)
283 1.1 christos {
284 1.1 christos ACPI_STATUS Status;
285 1.1 christos ACPI_TABLE_DESC *TableDesc;
286 1.1 christos
287 1.1 christos
288 1.1 christos Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
289 1.1 christos if (ACPI_FAILURE (Status))
290 1.1 christos {
291 1.1 christos return (Status);
292 1.1 christos }
293 1.1 christos
294 1.1 christos /* Initialize added table */
295 1.1 christos
296 1.1 christos AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
297 1.1 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
298 1.1 christos Status = AcpiTbValidateTable (TableDesc);
299 1.1 christos return (Status);
300 1.1 christos }
301 1.1 christos
302 1.1 christos
303 1.1 christos /******************************************************************************
304 1.1 christos *
305 1.1 christos * FUNCTION: AdGetLocalTables
306 1.1 christos *
307 1.1 christos * PARAMETERS: None
308 1.1 christos *
309 1.1 christos * RETURN: Status
310 1.1 christos *
311 1.1 christos * DESCRIPTION: Get the ACPI tables from either memory or a file
312 1.1 christos *
313 1.1 christos *****************************************************************************/
314 1.1 christos
315 1.1 christos ACPI_STATUS
316 1.1 christos AdGetLocalTables (
317 1.1 christos void)
318 1.1 christos {
319 1.1 christos ACPI_STATUS Status;
320 1.1 christos ACPI_TABLE_HEADER TableHeader;
321 1.1 christos ACPI_TABLE_HEADER *NewTable;
322 1.1 christos UINT32 TableIndex;
323 1.1 christos
324 1.1 christos
325 1.1 christos /* Get the DSDT via table override */
326 1.1 christos
327 1.1 christos ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
328 1.1 christos AcpiOsTableOverride (&TableHeader, &NewTable);
329 1.1 christos if (!NewTable)
330 1.1 christos {
331 1.1 christos fprintf (stderr, "Could not obtain DSDT\n");
332 1.1 christos return (AE_NO_ACPI_TABLES);
333 1.1 christos }
334 1.1 christos
335 1.1 christos AdWriteTable (NewTable, NewTable->Length,
336 1.1 christos ACPI_SIG_DSDT, NewTable->OemTableId);
337 1.1 christos
338 1.1 christos /* Store DSDT in the Table Manager */
339 1.1 christos
340 1.1 christos Status = AdStoreTable (NewTable, &TableIndex);
341 1.1 christos if (ACPI_FAILURE (Status))
342 1.1 christos {
343 1.1 christos fprintf (stderr, "Could not store DSDT\n");
344 1.1 christos return (AE_NO_ACPI_TABLES);
345 1.1 christos }
346 1.1 christos
347 1.1 christos return (AE_OK);
348 1.1 christos }
349 1.1 christos
350 1.1 christos
351 1.1 christos /******************************************************************************
352 1.1 christos *
353 1.1 christos * FUNCTION: AdParseTable
354 1.1 christos *
355 1.1 christos * PARAMETERS: Table - Pointer to the raw table
356 1.1 christos * OwnerId - Returned OwnerId of the table
357 1.1 christos * LoadTable - If add table to the global table list
358 1.1 christos * External - If this is an external table
359 1.1 christos *
360 1.1 christos * RETURN: Status
361 1.1 christos *
362 1.1 christos * DESCRIPTION: Parse an ACPI AML table
363 1.1 christos *
364 1.1 christos *****************************************************************************/
365 1.1 christos
366 1.1 christos ACPI_STATUS
367 1.1 christos AdParseTable (
368 1.1 christos ACPI_TABLE_HEADER *Table,
369 1.1 christos ACPI_OWNER_ID *OwnerId,
370 1.1 christos BOOLEAN LoadTable,
371 1.1 christos BOOLEAN External)
372 1.1 christos {
373 1.1 christos ACPI_STATUS Status = AE_OK;
374 1.1 christos ACPI_WALK_STATE *WalkState;
375 1.1 christos UINT8 *AmlStart;
376 1.1 christos UINT32 AmlLength;
377 1.1 christos UINT32 TableIndex;
378 1.1 christos
379 1.1 christos
380 1.1 christos if (!Table)
381 1.1 christos {
382 1.1 christos return (AE_NOT_EXIST);
383 1.1 christos }
384 1.1 christos
385 1.1 christos /* Pass 1: Parse everything except control method bodies */
386 1.1 christos
387 1.1 christos fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
388 1.1 christos
389 1.1 christos AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
390 1.1 christos AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
391 1.1 christos
392 1.1 christos /* Create the root object */
393 1.1 christos
394 1.1 christos AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
395 1.1 christos if (!AcpiGbl_ParseOpRoot)
396 1.1 christos {
397 1.1 christos return (AE_NO_MEMORY);
398 1.1 christos }
399 1.1 christos
400 1.1 christos /* Create and initialize a new walk state */
401 1.1 christos
402 1.1 christos WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
403 1.1 christos if (!WalkState)
404 1.1 christos {
405 1.1 christos return (AE_NO_MEMORY);
406 1.1 christos }
407 1.1 christos
408 1.1 christos Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
409 1.1 christos NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
410 1.1 christos if (ACPI_FAILURE (Status))
411 1.1 christos {
412 1.1 christos return (Status);
413 1.1 christos }
414 1.1 christos
415 1.1 christos WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
416 1.1 christos WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
417 1.1 christos
418 1.1 christos Status = AcpiPsParseAml (WalkState);
419 1.1 christos if (ACPI_FAILURE (Status))
420 1.1 christos {
421 1.1 christos return (Status);
422 1.1 christos }
423 1.1 christos
424 1.1 christos /* If LoadTable is FALSE, we are parsing the last loaded table */
425 1.1 christos
426 1.1 christos TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
427 1.1 christos
428 1.1 christos /* Pass 2 */
429 1.1 christos
430 1.1 christos if (LoadTable)
431 1.1 christos {
432 1.1 christos Status = AdStoreTable (Table, &TableIndex);
433 1.1 christos if (ACPI_FAILURE (Status))
434 1.1 christos {
435 1.1 christos return (Status);
436 1.1 christos }
437 1.1 christos Status = AcpiTbAllocateOwnerId (TableIndex);
438 1.1 christos if (ACPI_FAILURE (Status))
439 1.1 christos {
440 1.1 christos return (Status);
441 1.1 christos }
442 1.1 christos if (OwnerId)
443 1.1 christos {
444 1.1 christos Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
445 1.1 christos if (ACPI_FAILURE (Status))
446 1.1 christos {
447 1.1 christos return (Status);
448 1.1 christos }
449 1.1 christos }
450 1.1 christos }
451 1.1 christos
452 1.1 christos fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
453 1.1 christos
454 1.1 christos Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
455 1.1 christos if (ACPI_FAILURE (Status))
456 1.1 christos {
457 1.1 christos return (Status);
458 1.1 christos }
459 1.1 christos
460 1.1 christos /* No need to parse control methods of external table */
461 1.1 christos
462 1.1 christos if (External)
463 1.1 christos {
464 1.1 christos return (AE_OK);
465 1.1 christos }
466 1.1 christos
467 1.1 christos /*
468 1.1 christos * Pass 3: Parse control methods and link their parse trees
469 1.1 christos * into the main parse tree
470 1.1 christos */
471 1.1 christos fprintf (stderr,
472 1.1 christos "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
473 1.1 christos
474 1.1 christos Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
475 1.1 christos fprintf (stderr, "\n");
476 1.1 christos
477 1.1 christos /* Process Resource Templates */
478 1.1 christos
479 1.1 christos AcpiDmFindResources (AcpiGbl_ParseOpRoot);
480 1.1 christos
481 1.1 christos fprintf (stderr, "Parsing completed\n");
482 1.1 christos return (AE_OK);
483 1.1 christos }
484