dmtables.c revision 1.1.1.2 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 "acapps.h"
46 1.1 christos #include "acdispat.h"
47 1.1 christos #include "acnamesp.h"
48 1.1 christos #include "actables.h"
49 1.1 christos #include "acparser.h"
50 1.1 christos
51 1.1 christos #include <stdio.h>
52 1.1 christos #include <time.h>
53 1.1 christos
54 1.1 christos #define _COMPONENT ACPI_TOOLS
55 1.1 christos ACPI_MODULE_NAME ("dmtables")
56 1.1 christos
57 1.1 christos
58 1.1 christos /* Local prototypes */
59 1.1 christos
60 1.1 christos static void
61 1.1 christos AdCreateTableHeader (
62 1.1 christos char *Filename,
63 1.1 christos ACPI_TABLE_HEADER *Table);
64 1.1 christos
65 1.1 christos static ACPI_STATUS
66 1.1 christos AdStoreTable (
67 1.1 christos ACPI_TABLE_HEADER *Table,
68 1.1 christos UINT32 *TableIndex);
69 1.1 christos
70 1.1 christos
71 1.1 christos extern ACPI_TABLE_DESC LocalTables[1];
72 1.1 christos extern ACPI_PARSE_OBJECT *AcpiGbl_ParseOpRoot;
73 1.1 christos
74 1.1 christos
75 1.1 christos /******************************************************************************
76 1.1 christos *
77 1.1 christos * FUNCTION: AdDisassemblerHeader
78 1.1 christos *
79 1.1 christos * PARAMETERS: Filename - Input file for the table
80 1.1 christos * TableType - Either AML or DataTable
81 1.1 christos *
82 1.1 christos * RETURN: None
83 1.1 christos *
84 1.1 christos * DESCRIPTION: Create the disassembler header, including ACPICA signon with
85 1.1 christos * current time and date.
86 1.1 christos *
87 1.1 christos *****************************************************************************/
88 1.1 christos
89 1.1 christos void
90 1.1 christos AdDisassemblerHeader (
91 1.1 christos char *Filename,
92 1.1 christos UINT8 TableType)
93 1.1 christos {
94 1.1 christos time_t Timer;
95 1.1 christos
96 1.1 christos
97 1.1 christos time (&Timer);
98 1.1 christos
99 1.1 christos /* Header and input table info */
100 1.1 christos
101 1.1 christos AcpiOsPrintf ("/*\n");
102 1.1 christos AcpiOsPrintf (ACPI_COMMON_HEADER (AML_DISASSEMBLER_NAME, " * "));
103 1.1 christos
104 1.1 christos if (TableType == ACPI_IS_AML_TABLE)
105 1.1 christos {
106 1.1 christos if (AcpiGbl_CstyleDisassembly)
107 1.1 christos {
108 1.1 christos AcpiOsPrintf (
109 1.1 christos " * Disassembling to symbolic ASL+ operators\n"
110 1.1 christos " *\n");
111 1.1 christos }
112 1.1 christos else
113 1.1 christos {
114 1.1 christos AcpiOsPrintf (
115 1.1 christos " * Disassembling to non-symbolic legacy ASL operators\n"
116 1.1 christos " *\n");
117 1.1 christos }
118 1.1 christos }
119 1.1 christos
120 1.1 christos AcpiOsPrintf (" * Disassembly of %s, %s", Filename, ctime (&Timer));
121 1.1 christos AcpiOsPrintf (" *\n");
122 1.1 christos }
123 1.1 christos
124 1.1 christos
125 1.1 christos /******************************************************************************
126 1.1 christos *
127 1.1 christos * FUNCTION: AdCreateTableHeader
128 1.1 christos *
129 1.1 christos * PARAMETERS: Filename - Input file for the table
130 1.1 christos * Table - Pointer to the raw table
131 1.1 christos *
132 1.1 christos * RETURN: None
133 1.1 christos *
134 1.1 christos * DESCRIPTION: Create the ASL table header, including ACPICA signon with
135 1.1 christos * current time and date.
136 1.1 christos *
137 1.1 christos *****************************************************************************/
138 1.1 christos
139 1.1 christos static void
140 1.1 christos AdCreateTableHeader (
141 1.1 christos char *Filename,
142 1.1 christos ACPI_TABLE_HEADER *Table)
143 1.1 christos {
144 1.1 christos UINT8 Checksum;
145 1.1 christos
146 1.1 christos
147 1.1.1.2 christos /* Reset globals for External statements */
148 1.1.1.2 christos
149 1.1.1.2 christos AcpiGbl_NumExternalMethods = 0;
150 1.1.1.2 christos AcpiGbl_ResolvedExternalMethods = 0;
151 1.1.1.2 christos
152 1.1 christos /*
153 1.1 christos * Print file header and dump original table header
154 1.1 christos */
155 1.1 christos AdDisassemblerHeader (Filename, ACPI_IS_AML_TABLE);
156 1.1 christos
157 1.1 christos AcpiOsPrintf (" * Original Table Header:\n");
158 1.1 christos AcpiOsPrintf (" * Signature \"%4.4s\"\n", Table->Signature);
159 1.1 christos AcpiOsPrintf (" * Length 0x%8.8X (%u)\n", Table->Length, Table->Length);
160 1.1 christos
161 1.1 christos /* Print and validate the revision */
162 1.1 christos
163 1.1 christos AcpiOsPrintf (" * Revision 0x%2.2X", Table->Revision);
164 1.1 christos
165 1.1 christos switch (Table->Revision)
166 1.1 christos {
167 1.1 christos case 0:
168 1.1 christos
169 1.1 christos AcpiOsPrintf (" **** Invalid Revision");
170 1.1 christos break;
171 1.1 christos
172 1.1 christos case 1:
173 1.1 christos
174 1.1 christos /* Revision of DSDT controls the ACPI integer width */
175 1.1 christos
176 1.1 christos if (ACPI_COMPARE_NAME (Table->Signature, ACPI_SIG_DSDT))
177 1.1 christos {
178 1.1 christos AcpiOsPrintf (" **** 32-bit table (V1), no 64-bit math support");
179 1.1 christos }
180 1.1 christos break;
181 1.1 christos
182 1.1 christos default:
183 1.1 christos
184 1.1 christos break;
185 1.1 christos }
186 1.1 christos
187 1.1 christos /* Print and validate the table checksum */
188 1.1 christos
189 1.1.1.2 christos AcpiOsPrintf ("\n * Checksum 0x%2.2X", Table->Checksum);
190 1.1 christos
191 1.1 christos Checksum = AcpiTbChecksum (ACPI_CAST_PTR (UINT8, Table), Table->Length);
192 1.1 christos if (Checksum)
193 1.1 christos {
194 1.1 christos AcpiOsPrintf (" **** Incorrect checksum, should be 0x%2.2X",
195 1.1 christos (UINT8) (Table->Checksum - Checksum));
196 1.1 christos }
197 1.1 christos
198 1.1 christos AcpiOsPrintf ("\n");
199 1.1 christos AcpiOsPrintf (" * OEM ID \"%.6s\"\n", Table->OemId);
200 1.1 christos AcpiOsPrintf (" * OEM Table ID \"%.8s\"\n", Table->OemTableId);
201 1.1 christos AcpiOsPrintf (" * OEM Revision 0x%8.8X (%u)\n", Table->OemRevision, Table->OemRevision);
202 1.1 christos AcpiOsPrintf (" * Compiler ID \"%.4s\"\n", Table->AslCompilerId);
203 1.1 christos AcpiOsPrintf (" * Compiler Version 0x%8.8X (%u)\n", Table->AslCompilerRevision, Table->AslCompilerRevision);
204 1.1 christos AcpiOsPrintf (" */\n");
205 1.1 christos
206 1.1.1.2 christos /*
207 1.1.1.2 christos * Open the ASL definition block.
208 1.1.1.2 christos *
209 1.1.1.2 christos * Note: the AMLFilename string is left zero-length in order to just let
210 1.1.1.2 christos * the compiler create it when the disassembled file is compiled. This
211 1.1.1.2 christos * makes it easier to rename the disassembled ASL file if needed.
212 1.1.1.2 christos */
213 1.1 christos AcpiOsPrintf (
214 1.1.1.2 christos "DefinitionBlock (\"\", \"%4.4s\", %hu, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
215 1.1.1.2 christos Table->Signature, Table->Revision,
216 1.1 christos Table->OemId, Table->OemTableId, Table->OemRevision);
217 1.1 christos }
218 1.1 christos
219 1.1 christos
220 1.1 christos /******************************************************************************
221 1.1 christos *
222 1.1 christos * FUNCTION: AdDisplayTables
223 1.1 christos *
224 1.1 christos * PARAMETERS: Filename - Input file for the table
225 1.1 christos * Table - Pointer to the raw table
226 1.1 christos *
227 1.1 christos * RETURN: Status
228 1.1 christos *
229 1.1 christos * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
230 1.1 christos *
231 1.1 christos *****************************************************************************/
232 1.1 christos
233 1.1 christos ACPI_STATUS
234 1.1 christos AdDisplayTables (
235 1.1 christos char *Filename,
236 1.1 christos ACPI_TABLE_HEADER *Table)
237 1.1 christos {
238 1.1 christos
239 1.1 christos
240 1.1 christos if (!AcpiGbl_ParseOpRoot)
241 1.1 christos {
242 1.1 christos return (AE_NOT_EXIST);
243 1.1 christos }
244 1.1 christos
245 1.1 christos if (!AcpiGbl_DmOpt_Listing)
246 1.1 christos {
247 1.1 christos AdCreateTableHeader (Filename, Table);
248 1.1 christos }
249 1.1 christos
250 1.1 christos AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
251 1.1 christos MpEmitMappingInfo ();
252 1.1 christos
253 1.1 christos if (AcpiGbl_DmOpt_Listing)
254 1.1 christos {
255 1.1 christos AcpiOsPrintf ("\n\nTable Header:\n");
256 1.1 christos AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
257 1.1 christos DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
258 1.1 christos
259 1.1 christos AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
260 1.1 christos AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
261 1.1 christos Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
262 1.1 christos }
263 1.1 christos
264 1.1 christos return (AE_OK);
265 1.1 christos }
266 1.1 christos
267 1.1 christos
268 1.1 christos /*******************************************************************************
269 1.1 christos *
270 1.1 christos * FUNCTION: AdStoreTable
271 1.1 christos *
272 1.1 christos * PARAMETERS: Table - Table header
273 1.1 christos * TableIndex - Where the table index is returned
274 1.1 christos *
275 1.1 christos * RETURN: Status and table index.
276 1.1 christos *
277 1.1 christos * DESCRIPTION: Add an ACPI table to the global table list
278 1.1 christos *
279 1.1 christos ******************************************************************************/
280 1.1 christos
281 1.1 christos static ACPI_STATUS
282 1.1 christos AdStoreTable (
283 1.1 christos ACPI_TABLE_HEADER *Table,
284 1.1 christos UINT32 *TableIndex)
285 1.1 christos {
286 1.1 christos ACPI_STATUS Status;
287 1.1 christos ACPI_TABLE_DESC *TableDesc;
288 1.1 christos
289 1.1 christos
290 1.1 christos Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
291 1.1 christos if (ACPI_FAILURE (Status))
292 1.1 christos {
293 1.1 christos return (Status);
294 1.1 christos }
295 1.1 christos
296 1.1 christos /* Initialize added table */
297 1.1 christos
298 1.1 christos AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
299 1.1 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
300 1.1 christos Status = AcpiTbValidateTable (TableDesc);
301 1.1 christos return (Status);
302 1.1 christos }
303 1.1 christos
304 1.1 christos
305 1.1 christos /******************************************************************************
306 1.1 christos *
307 1.1 christos * FUNCTION: AdGetLocalTables
308 1.1 christos *
309 1.1 christos * PARAMETERS: None
310 1.1 christos *
311 1.1 christos * RETURN: Status
312 1.1 christos *
313 1.1 christos * DESCRIPTION: Get the ACPI tables from either memory or a file
314 1.1 christos *
315 1.1 christos *****************************************************************************/
316 1.1 christos
317 1.1 christos ACPI_STATUS
318 1.1 christos AdGetLocalTables (
319 1.1 christos void)
320 1.1 christos {
321 1.1 christos ACPI_STATUS Status;
322 1.1 christos ACPI_TABLE_HEADER TableHeader;
323 1.1 christos ACPI_TABLE_HEADER *NewTable;
324 1.1 christos UINT32 TableIndex;
325 1.1 christos
326 1.1 christos
327 1.1 christos /* Get the DSDT via table override */
328 1.1 christos
329 1.1 christos ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
330 1.1 christos AcpiOsTableOverride (&TableHeader, &NewTable);
331 1.1 christos if (!NewTable)
332 1.1 christos {
333 1.1 christos fprintf (stderr, "Could not obtain DSDT\n");
334 1.1 christos return (AE_NO_ACPI_TABLES);
335 1.1 christos }
336 1.1 christos
337 1.1 christos AdWriteTable (NewTable, NewTable->Length,
338 1.1 christos ACPI_SIG_DSDT, NewTable->OemTableId);
339 1.1 christos
340 1.1 christos /* Store DSDT in the Table Manager */
341 1.1 christos
342 1.1 christos Status = AdStoreTable (NewTable, &TableIndex);
343 1.1 christos if (ACPI_FAILURE (Status))
344 1.1 christos {
345 1.1 christos fprintf (stderr, "Could not store DSDT\n");
346 1.1 christos return (AE_NO_ACPI_TABLES);
347 1.1 christos }
348 1.1 christos
349 1.1 christos return (AE_OK);
350 1.1 christos }
351 1.1 christos
352 1.1 christos
353 1.1 christos /******************************************************************************
354 1.1 christos *
355 1.1 christos * FUNCTION: AdParseTable
356 1.1 christos *
357 1.1 christos * PARAMETERS: Table - Pointer to the raw table
358 1.1 christos * OwnerId - Returned OwnerId of the table
359 1.1 christos * LoadTable - If add table to the global table list
360 1.1 christos * External - If this is an external table
361 1.1 christos *
362 1.1 christos * RETURN: Status
363 1.1 christos *
364 1.1 christos * DESCRIPTION: Parse an ACPI AML table
365 1.1 christos *
366 1.1 christos *****************************************************************************/
367 1.1 christos
368 1.1 christos ACPI_STATUS
369 1.1 christos AdParseTable (
370 1.1 christos ACPI_TABLE_HEADER *Table,
371 1.1 christos ACPI_OWNER_ID *OwnerId,
372 1.1 christos BOOLEAN LoadTable,
373 1.1 christos BOOLEAN External)
374 1.1 christos {
375 1.1 christos ACPI_STATUS Status = AE_OK;
376 1.1 christos ACPI_WALK_STATE *WalkState;
377 1.1 christos UINT8 *AmlStart;
378 1.1 christos UINT32 AmlLength;
379 1.1 christos UINT32 TableIndex;
380 1.1 christos
381 1.1 christos
382 1.1 christos if (!Table)
383 1.1 christos {
384 1.1 christos return (AE_NOT_EXIST);
385 1.1 christos }
386 1.1 christos
387 1.1 christos /* Pass 1: Parse everything except control method bodies */
388 1.1 christos
389 1.1 christos fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
390 1.1 christos
391 1.1 christos AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
392 1.1 christos AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
393 1.1 christos
394 1.1 christos /* Create the root object */
395 1.1 christos
396 1.1 christos AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
397 1.1 christos if (!AcpiGbl_ParseOpRoot)
398 1.1 christos {
399 1.1 christos return (AE_NO_MEMORY);
400 1.1 christos }
401 1.1 christos
402 1.1 christos /* Create and initialize a new walk state */
403 1.1 christos
404 1.1 christos WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
405 1.1 christos if (!WalkState)
406 1.1 christos {
407 1.1 christos return (AE_NO_MEMORY);
408 1.1 christos }
409 1.1 christos
410 1.1 christos Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
411 1.1 christos NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
412 1.1 christos if (ACPI_FAILURE (Status))
413 1.1 christos {
414 1.1 christos return (Status);
415 1.1 christos }
416 1.1 christos
417 1.1 christos WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
418 1.1 christos WalkState->ParseFlags |= ACPI_PARSE_DISASSEMBLE;
419 1.1 christos
420 1.1 christos Status = AcpiPsParseAml (WalkState);
421 1.1 christos if (ACPI_FAILURE (Status))
422 1.1 christos {
423 1.1 christos return (Status);
424 1.1 christos }
425 1.1 christos
426 1.1 christos /* If LoadTable is FALSE, we are parsing the last loaded table */
427 1.1 christos
428 1.1 christos TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
429 1.1 christos
430 1.1 christos /* Pass 2 */
431 1.1 christos
432 1.1 christos if (LoadTable)
433 1.1 christos {
434 1.1 christos Status = AdStoreTable (Table, &TableIndex);
435 1.1 christos if (ACPI_FAILURE (Status))
436 1.1 christos {
437 1.1 christos return (Status);
438 1.1 christos }
439 1.1 christos Status = AcpiTbAllocateOwnerId (TableIndex);
440 1.1 christos if (ACPI_FAILURE (Status))
441 1.1 christos {
442 1.1 christos return (Status);
443 1.1 christos }
444 1.1 christos if (OwnerId)
445 1.1 christos {
446 1.1 christos Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
447 1.1 christos if (ACPI_FAILURE (Status))
448 1.1 christos {
449 1.1 christos return (Status);
450 1.1 christos }
451 1.1 christos }
452 1.1 christos }
453 1.1 christos
454 1.1 christos fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
455 1.1 christos
456 1.1 christos Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
457 1.1 christos if (ACPI_FAILURE (Status))
458 1.1 christos {
459 1.1 christos return (Status);
460 1.1 christos }
461 1.1 christos
462 1.1 christos /* No need to parse control methods of external table */
463 1.1 christos
464 1.1 christos if (External)
465 1.1 christos {
466 1.1 christos return (AE_OK);
467 1.1 christos }
468 1.1 christos
469 1.1 christos /*
470 1.1 christos * Pass 3: Parse control methods and link their parse trees
471 1.1 christos * into the main parse tree
472 1.1 christos */
473 1.1 christos fprintf (stderr,
474 1.1 christos "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
475 1.1 christos
476 1.1 christos Status = AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
477 1.1 christos fprintf (stderr, "\n");
478 1.1 christos
479 1.1 christos /* Process Resource Templates */
480 1.1 christos
481 1.1 christos AcpiDmFindResources (AcpiGbl_ParseOpRoot);
482 1.1 christos
483 1.1 christos fprintf (stderr, "Parsing completed\n");
484 1.1 christos return (AE_OK);
485 1.1 christos }
486