dmtables.c revision 1.5 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.5 christos * Copyright (C) 2000 - 2021, 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.5 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 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.2 christos #include "acapps.h"
50 1.2 christos #include "acmacros.h"
51 1.2 christos #include "acconvert.h"
52 1.1 christos
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.2 christos /* Reset globals for External statements */
148 1.2 christos
149 1.2 christos AcpiGbl_NumExternalMethods = 0;
150 1.2 christos AcpiGbl_ResolvedExternalMethods = 0;
151 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.2 christos if (ACPI_COMPARE_NAMESEG (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.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.2 christos /*
207 1.2 christos * Print comments that come before this definition block.
208 1.2 christos */
209 1.2 christos if (AcpiGbl_CaptureComments)
210 1.1 christos {
211 1.2 christos ASL_CV_PRINT_ONE_COMMENT(AcpiGbl_ParseOpRoot,AML_COMMENT_STANDARD, NULL, 0);
212 1.1 christos }
213 1.1 christos
214 1.2 christos /*
215 1.2 christos * Open the ASL definition block.
216 1.2 christos *
217 1.2 christos * Note: the AMLFilename string is left zero-length in order to just let
218 1.2 christos * the compiler create it when the disassembled file is compiled. This
219 1.2 christos * makes it easier to rename the disassembled ASL file if needed.
220 1.2 christos */
221 1.1 christos AcpiOsPrintf (
222 1.3 christos "DefinitionBlock (\"\", \"%4.4s\", %u, \"%.6s\", \"%.8s\", 0x%8.8X)\n",
223 1.2 christos Table->Signature, Table->Revision,
224 1.1 christos Table->OemId, Table->OemTableId, Table->OemRevision);
225 1.1 christos }
226 1.1 christos
227 1.1 christos
228 1.1 christos /******************************************************************************
229 1.1 christos *
230 1.1 christos * FUNCTION: AdDisplayTables
231 1.1 christos *
232 1.1 christos * PARAMETERS: Filename - Input file for the table
233 1.1 christos * Table - Pointer to the raw table
234 1.1 christos *
235 1.1 christos * RETURN: Status
236 1.1 christos *
237 1.1 christos * DESCRIPTION: Display (disassemble) loaded tables and dump raw tables
238 1.1 christos *
239 1.1 christos *****************************************************************************/
240 1.1 christos
241 1.1 christos ACPI_STATUS
242 1.1 christos AdDisplayTables (
243 1.1 christos char *Filename,
244 1.1 christos ACPI_TABLE_HEADER *Table)
245 1.1 christos {
246 1.1 christos
247 1.1 christos
248 1.1 christos if (!AcpiGbl_ParseOpRoot)
249 1.1 christos {
250 1.1 christos return (AE_NOT_EXIST);
251 1.1 christos }
252 1.1 christos
253 1.1 christos if (!AcpiGbl_DmOpt_Listing)
254 1.1 christos {
255 1.1 christos AdCreateTableHeader (Filename, Table);
256 1.1 christos }
257 1.1 christos
258 1.1 christos AcpiDmDisassemble (NULL, AcpiGbl_ParseOpRoot, ACPI_UINT32_MAX);
259 1.1 christos MpEmitMappingInfo ();
260 1.1 christos
261 1.1 christos if (AcpiGbl_DmOpt_Listing)
262 1.1 christos {
263 1.1 christos AcpiOsPrintf ("\n\nTable Header:\n");
264 1.1 christos AcpiUtDebugDumpBuffer ((UINT8 *) Table, sizeof (ACPI_TABLE_HEADER),
265 1.1 christos DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
266 1.1 christos
267 1.1 christos AcpiOsPrintf ("Table Body (Length 0x%X)\n", Table->Length);
268 1.1 christos AcpiUtDebugDumpBuffer (((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER)),
269 1.1 christos Table->Length, DB_BYTE_DISPLAY, ACPI_UINT32_MAX);
270 1.1 christos }
271 1.1 christos
272 1.1 christos return (AE_OK);
273 1.1 christos }
274 1.1 christos
275 1.1 christos
276 1.1 christos /*******************************************************************************
277 1.1 christos *
278 1.1 christos * FUNCTION: AdStoreTable
279 1.1 christos *
280 1.1 christos * PARAMETERS: Table - Table header
281 1.1 christos * TableIndex - Where the table index is returned
282 1.1 christos *
283 1.1 christos * RETURN: Status and table index.
284 1.1 christos *
285 1.1 christos * DESCRIPTION: Add an ACPI table to the global table list
286 1.1 christos *
287 1.1 christos ******************************************************************************/
288 1.1 christos
289 1.1 christos static ACPI_STATUS
290 1.1 christos AdStoreTable (
291 1.1 christos ACPI_TABLE_HEADER *Table,
292 1.1 christos UINT32 *TableIndex)
293 1.1 christos {
294 1.1 christos ACPI_STATUS Status;
295 1.1 christos ACPI_TABLE_DESC *TableDesc;
296 1.1 christos
297 1.1 christos
298 1.1 christos Status = AcpiTbGetNextTableDescriptor (TableIndex, &TableDesc);
299 1.1 christos if (ACPI_FAILURE (Status))
300 1.1 christos {
301 1.1 christos return (Status);
302 1.1 christos }
303 1.1 christos
304 1.1 christos /* Initialize added table */
305 1.1 christos
306 1.1 christos AcpiTbInitTableDescriptor (TableDesc, ACPI_PTR_TO_PHYSADDR (Table),
307 1.1 christos ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, Table);
308 1.1 christos Status = AcpiTbValidateTable (TableDesc);
309 1.1 christos return (Status);
310 1.1 christos }
311 1.1 christos
312 1.1 christos
313 1.1 christos /******************************************************************************
314 1.1 christos *
315 1.1 christos * FUNCTION: AdGetLocalTables
316 1.1 christos *
317 1.1 christos * PARAMETERS: None
318 1.1 christos *
319 1.1 christos * RETURN: Status
320 1.1 christos *
321 1.1 christos * DESCRIPTION: Get the ACPI tables from either memory or a file
322 1.1 christos *
323 1.1 christos *****************************************************************************/
324 1.1 christos
325 1.1 christos ACPI_STATUS
326 1.1 christos AdGetLocalTables (
327 1.1 christos void)
328 1.1 christos {
329 1.1 christos ACPI_STATUS Status;
330 1.1 christos ACPI_TABLE_HEADER TableHeader;
331 1.1 christos ACPI_TABLE_HEADER *NewTable;
332 1.1 christos UINT32 TableIndex;
333 1.1 christos
334 1.1 christos
335 1.1 christos /* Get the DSDT via table override */
336 1.1 christos
337 1.1 christos ACPI_MOVE_32_TO_32 (TableHeader.Signature, ACPI_SIG_DSDT);
338 1.2 christos Status = AcpiOsTableOverride (&TableHeader, &NewTable);
339 1.2 christos if (ACPI_FAILURE (Status) || !NewTable)
340 1.1 christos {
341 1.1 christos fprintf (stderr, "Could not obtain DSDT\n");
342 1.1 christos return (AE_NO_ACPI_TABLES);
343 1.1 christos }
344 1.1 christos
345 1.1 christos AdWriteTable (NewTable, NewTable->Length,
346 1.1 christos ACPI_SIG_DSDT, NewTable->OemTableId);
347 1.1 christos
348 1.1 christos /* Store DSDT in the Table Manager */
349 1.1 christos
350 1.1 christos Status = AdStoreTable (NewTable, &TableIndex);
351 1.1 christos if (ACPI_FAILURE (Status))
352 1.1 christos {
353 1.1 christos fprintf (stderr, "Could not store DSDT\n");
354 1.1 christos return (AE_NO_ACPI_TABLES);
355 1.1 christos }
356 1.1 christos
357 1.1 christos return (AE_OK);
358 1.1 christos }
359 1.1 christos
360 1.1 christos
361 1.1 christos /******************************************************************************
362 1.1 christos *
363 1.1 christos * FUNCTION: AdParseTable
364 1.1 christos *
365 1.1 christos * PARAMETERS: Table - Pointer to the raw table
366 1.1 christos * OwnerId - Returned OwnerId of the table
367 1.1 christos * LoadTable - If add table to the global table list
368 1.1 christos * External - If this is an external table
369 1.1 christos *
370 1.1 christos * RETURN: Status
371 1.1 christos *
372 1.1 christos * DESCRIPTION: Parse an ACPI AML table
373 1.1 christos *
374 1.1 christos *****************************************************************************/
375 1.1 christos
376 1.1 christos ACPI_STATUS
377 1.1 christos AdParseTable (
378 1.1 christos ACPI_TABLE_HEADER *Table,
379 1.1 christos ACPI_OWNER_ID *OwnerId,
380 1.1 christos BOOLEAN LoadTable,
381 1.1 christos BOOLEAN External)
382 1.1 christos {
383 1.1 christos ACPI_STATUS Status = AE_OK;
384 1.1 christos ACPI_WALK_STATE *WalkState;
385 1.1 christos UINT8 *AmlStart;
386 1.1 christos UINT32 AmlLength;
387 1.1 christos UINT32 TableIndex;
388 1.1 christos
389 1.1 christos
390 1.1 christos if (!Table)
391 1.1 christos {
392 1.1 christos return (AE_NOT_EXIST);
393 1.1 christos }
394 1.1 christos
395 1.1 christos /* Pass 1: Parse everything except control method bodies */
396 1.1 christos
397 1.1 christos fprintf (stderr, "Pass 1 parse of [%4.4s]\n", (char *) Table->Signature);
398 1.1 christos
399 1.1 christos AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
400 1.1 christos AmlStart = ((UINT8 *) Table + sizeof (ACPI_TABLE_HEADER));
401 1.1 christos
402 1.3 christos AcpiUtSetIntegerWidth (Table->Revision);
403 1.3 christos
404 1.1 christos /* Create the root object */
405 1.1 christos
406 1.1 christos AcpiGbl_ParseOpRoot = AcpiPsCreateScopeOp (AmlStart);
407 1.1 christos if (!AcpiGbl_ParseOpRoot)
408 1.1 christos {
409 1.1 christos return (AE_NO_MEMORY);
410 1.1 christos }
411 1.1 christos
412 1.2 christos #ifdef ACPI_ASL_COMPILER
413 1.2 christos if (AcpiGbl_CaptureComments)
414 1.2 christos {
415 1.2 christos AcpiGbl_ParseOpRoot->Common.CvFilename = AcpiGbl_FileTreeRoot->Filename;
416 1.2 christos }
417 1.2 christos else
418 1.2 christos {
419 1.2 christos AcpiGbl_ParseOpRoot->Common.CvFilename = NULL;
420 1.2 christos }
421 1.2 christos #endif
422 1.2 christos
423 1.1 christos /* Create and initialize a new walk state */
424 1.1 christos
425 1.1 christos WalkState = AcpiDsCreateWalkState (0, AcpiGbl_ParseOpRoot, NULL, NULL);
426 1.1 christos if (!WalkState)
427 1.1 christos {
428 1.1 christos return (AE_NO_MEMORY);
429 1.1 christos }
430 1.1 christos
431 1.1 christos Status = AcpiDsInitAmlWalk (WalkState, AcpiGbl_ParseOpRoot,
432 1.1 christos NULL, AmlStart, AmlLength, NULL, ACPI_IMODE_LOAD_PASS1);
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
438 1.1 christos WalkState->ParseFlags &= ~ACPI_PARSE_DELETE_TREE;
439 1.1 christos
440 1.1 christos Status = AcpiPsParseAml (WalkState);
441 1.1 christos if (ACPI_FAILURE (Status))
442 1.1 christos {
443 1.1 christos return (Status);
444 1.1 christos }
445 1.1 christos
446 1.1 christos /* If LoadTable is FALSE, we are parsing the last loaded table */
447 1.1 christos
448 1.1 christos TableIndex = AcpiGbl_RootTableList.CurrentTableCount - 1;
449 1.1 christos
450 1.1 christos /* Pass 2 */
451 1.1 christos
452 1.1 christos if (LoadTable)
453 1.1 christos {
454 1.1 christos Status = AdStoreTable (Table, &TableIndex);
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 Status = AcpiTbAllocateOwnerId (TableIndex);
460 1.1 christos if (ACPI_FAILURE (Status))
461 1.1 christos {
462 1.1 christos return (Status);
463 1.1 christos }
464 1.1 christos if (OwnerId)
465 1.1 christos {
466 1.1 christos Status = AcpiTbGetOwnerId (TableIndex, OwnerId);
467 1.1 christos if (ACPI_FAILURE (Status))
468 1.1 christos {
469 1.1 christos return (Status);
470 1.1 christos }
471 1.1 christos }
472 1.1 christos }
473 1.1 christos
474 1.1 christos fprintf (stderr, "Pass 2 parse of [%4.4s]\n", (char *) Table->Signature);
475 1.1 christos
476 1.1 christos Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2, TableIndex, NULL);
477 1.1 christos if (ACPI_FAILURE (Status))
478 1.1 christos {
479 1.1 christos return (Status);
480 1.1 christos }
481 1.1 christos
482 1.1 christos /* No need to parse control methods of external table */
483 1.1 christos
484 1.1 christos if (External)
485 1.1 christos {
486 1.1 christos return (AE_OK);
487 1.1 christos }
488 1.1 christos
489 1.1 christos /*
490 1.1 christos * Pass 3: Parse control methods and link their parse trees
491 1.1 christos * into the main parse tree
492 1.1 christos */
493 1.1 christos fprintf (stderr,
494 1.1 christos "Parsing Deferred Opcodes (Methods/Buffers/Packages/Regions)\n");
495 1.1 christos
496 1.3 christos (void) AcpiDmParseDeferredOps (AcpiGbl_ParseOpRoot);
497 1.1 christos fprintf (stderr, "\n");
498 1.1 christos
499 1.1 christos /* Process Resource Templates */
500 1.1 christos
501 1.1 christos AcpiDmFindResources (AcpiGbl_ParseOpRoot);
502 1.1 christos
503 1.1 christos fprintf (stderr, "Parsing completed\n");
504 1.1 christos return (AE_OK);
505 1.1 christos }
506