1 /*******************************************************************************
2 *
3 * Module Name: dmwalk - AML disassembly tree walk
4 *
5 ******************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************
115 *
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
118 *
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
133 *
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 *
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
149 *
150 *****************************************************************************/
151
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acparser.h"
155 #include "amlcode.h"
156 #include "acdebug.h"
157 #include "acconvert.h"
158
159
160 #ifdef ACPI_DISASSEMBLER
161
162 #define _COMPONENT ACPI_CA_DEBUGGER
163 ACPI_MODULE_NAME ("dmwalk")
164
165
166 /* Stub for non-compiler code */
167
168 #ifndef ACPI_ASL_COMPILER
169 void
AcpiDmEmitExternals(void)170 AcpiDmEmitExternals (
171 void)
172 {
173 return;
174 }
175
176 void
AcpiDmEmitExternal(ACPI_PARSE_OBJECT * NameOp,ACPI_PARSE_OBJECT * TypeOp)177 AcpiDmEmitExternal (
178 ACPI_PARSE_OBJECT *NameOp,
179 ACPI_PARSE_OBJECT *TypeOp)
180 {
181 return;
182 }
183 #endif
184
185 /* Local prototypes */
186
187 static ACPI_STATUS
188 AcpiDmDescendingOp (
189 ACPI_PARSE_OBJECT *Op,
190 UINT32 Level,
191 void *Context);
192
193 static ACPI_STATUS
194 AcpiDmAscendingOp (
195 ACPI_PARSE_OBJECT *Op,
196 UINT32 Level,
197 void *Context);
198
199
200 /*******************************************************************************
201 *
202 * FUNCTION: AcpiDmDisassemble
203 *
204 * PARAMETERS: WalkState - Current state
205 * Origin - Starting object
206 * NumOpcodes - Max number of opcodes to be displayed
207 *
208 * RETURN: None
209 *
210 * DESCRIPTION: Disassemble parser object and its children. This is the
211 * main entry point of the disassembler.
212 *
213 ******************************************************************************/
214
215 void
AcpiDmDisassemble(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Origin,UINT32 NumOpcodes)216 AcpiDmDisassemble (
217 ACPI_WALK_STATE *WalkState,
218 ACPI_PARSE_OBJECT *Origin,
219 UINT32 NumOpcodes)
220 {
221 ACPI_PARSE_OBJECT *Op = Origin;
222 ACPI_OP_WALK_INFO Info;
223
224
225 if (!Op)
226 {
227 return;
228 }
229
230 memset (&Info, 0, sizeof (ACPI_OP_WALK_INFO));
231 Info.WalkState = WalkState;
232 Info.StartAml = Op->Common.Aml - sizeof (ACPI_TABLE_HEADER);
233 Info.AmlOffset = Op->Common.Aml - Info.StartAml;
234
235 AcpiDmWalkParseTree (Op, AcpiDmDescendingOp, AcpiDmAscendingOp, &Info);
236 return;
237 }
238
239
240 /*******************************************************************************
241 *
242 * FUNCTION: AcpiDmWalkParseTree
243 *
244 * PARAMETERS: Op - Root Op object
245 * DescendingCallback - Called during tree descent
246 * AscendingCallback - Called during tree ascent
247 * Context - To be passed to the callbacks
248 *
249 * RETURN: Status from callback(s)
250 *
251 * DESCRIPTION: Walk the entire parse tree.
252 *
253 ******************************************************************************/
254
255 void
AcpiDmWalkParseTree(ACPI_PARSE_OBJECT * Op,ASL_WALK_CALLBACK DescendingCallback,ASL_WALK_CALLBACK AscendingCallback,void * Context)256 AcpiDmWalkParseTree (
257 ACPI_PARSE_OBJECT *Op,
258 ASL_WALK_CALLBACK DescendingCallback,
259 ASL_WALK_CALLBACK AscendingCallback,
260 void *Context)
261 {
262 BOOLEAN NodePreviouslyVisited;
263 ACPI_PARSE_OBJECT *StartOp = Op;
264 ACPI_STATUS Status;
265 ACPI_PARSE_OBJECT *Next;
266 ACPI_OP_WALK_INFO *Info = Context;
267
268
269 Info->Level = 0;
270 NodePreviouslyVisited = FALSE;
271
272 while (Op)
273 {
274 if (NodePreviouslyVisited)
275 {
276 if (AscendingCallback)
277 {
278 Status = AscendingCallback (Op, Info->Level, Context);
279 if (ACPI_FAILURE (Status))
280 {
281 return;
282 }
283 }
284 }
285 else
286 {
287 /* Let the callback process the node */
288
289 Status = DescendingCallback (Op, Info->Level, Context);
290 if (ACPI_SUCCESS (Status))
291 {
292 /* Visit children first, once */
293
294 Next = AcpiPsGetArg (Op, 0);
295 if (Next)
296 {
297 Info->Level++;
298 Op = Next;
299 continue;
300 }
301 }
302 else if (Status != AE_CTRL_DEPTH)
303 {
304 /* Exit immediately on any error */
305
306 return;
307 }
308 }
309
310 /* Terminate walk at start op */
311
312 if (Op == StartOp)
313 {
314 break;
315 }
316
317 /* No more children, re-visit this node */
318
319 if (!NodePreviouslyVisited)
320 {
321 NodePreviouslyVisited = TRUE;
322 continue;
323 }
324
325 /* No more children, visit peers */
326
327 if (Op->Common.Next)
328 {
329 Op = Op->Common.Next;
330 NodePreviouslyVisited = FALSE;
331 }
332 else
333 {
334 /* No peers, re-visit parent */
335
336 if (Info->Level != 0 )
337 {
338 Info->Level--;
339 }
340
341 Op = Op->Common.Parent;
342 NodePreviouslyVisited = TRUE;
343 }
344 }
345
346 /* If we get here, the walk completed with no errors */
347
348 return;
349 }
350
351
352 /*******************************************************************************
353 *
354 * FUNCTION: AcpiDmBlockType
355 *
356 * PARAMETERS: Op - Object to be examined
357 *
358 * RETURN: BlockType - not a block, parens, braces, or even both.
359 *
360 * DESCRIPTION: Type of block for this op (parens or braces)
361 *
362 ******************************************************************************/
363
364 UINT32
AcpiDmBlockType(ACPI_PARSE_OBJECT * Op)365 AcpiDmBlockType (
366 ACPI_PARSE_OBJECT *Op)
367 {
368 const ACPI_OPCODE_INFO *OpInfo;
369
370
371 if (!Op)
372 {
373 return (BLOCK_NONE);
374 }
375
376 switch (Op->Common.AmlOpcode)
377 {
378 case AML_ELSE_OP:
379
380 return (BLOCK_BRACE);
381
382 case AML_METHOD_OP:
383 case AML_DEVICE_OP:
384 case AML_SCOPE_OP:
385 case AML_PROCESSOR_OP:
386 case AML_POWER_RESOURCE_OP:
387 case AML_THERMAL_ZONE_OP:
388 case AML_IF_OP:
389 case AML_WHILE_OP:
390 case AML_FIELD_OP:
391 case AML_INDEX_FIELD_OP:
392 case AML_BANK_FIELD_OP:
393
394 return (BLOCK_PAREN | BLOCK_BRACE);
395
396 case AML_BUFFER_OP:
397
398 if ((Op->Common.DisasmOpcode == ACPI_DASM_UNICODE) ||
399 (Op->Common.DisasmOpcode == ACPI_DASM_UUID) ||
400 (Op->Common.DisasmOpcode == ACPI_DASM_PLD_METHOD))
401 {
402 return (BLOCK_NONE);
403 }
404
405 ACPI_FALLTHROUGH;
406
407 case AML_PACKAGE_OP:
408 case AML_VARIABLE_PACKAGE_OP:
409
410 return (BLOCK_PAREN | BLOCK_BRACE);
411
412 case AML_EVENT_OP:
413
414 return (BLOCK_PAREN);
415
416 case AML_INT_METHODCALL_OP:
417
418 if (Op->Common.Parent &&
419 ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
420 (Op->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP)))
421 {
422 /* This is a reference to a method, not an invocation */
423
424 return (BLOCK_NONE);
425 }
426
427 ACPI_FALLTHROUGH;
428
429 default:
430
431 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
432 if (OpInfo->Flags & AML_HAS_ARGS)
433 {
434 return (BLOCK_PAREN);
435 }
436
437 return (BLOCK_NONE);
438 }
439 }
440
441
442 /*******************************************************************************
443 *
444 * FUNCTION: AcpiDmListType
445 *
446 * PARAMETERS: Op - Object to be examined
447 *
448 * RETURN: ListType - has commas or not.
449 *
450 * DESCRIPTION: Type of block for this op (parens or braces)
451 *
452 ******************************************************************************/
453
454 UINT32
AcpiDmListType(ACPI_PARSE_OBJECT * Op)455 AcpiDmListType (
456 ACPI_PARSE_OBJECT *Op)
457 {
458 const ACPI_OPCODE_INFO *OpInfo;
459
460
461 if (!Op)
462 {
463 return (BLOCK_NONE);
464 }
465
466 switch (Op->Common.AmlOpcode)
467 {
468
469 case AML_ELSE_OP:
470 case AML_METHOD_OP:
471 case AML_DEVICE_OP:
472 case AML_SCOPE_OP:
473 case AML_POWER_RESOURCE_OP:
474 case AML_PROCESSOR_OP:
475 case AML_THERMAL_ZONE_OP:
476 case AML_IF_OP:
477 case AML_WHILE_OP:
478 case AML_FIELD_OP:
479 case AML_INDEX_FIELD_OP:
480 case AML_BANK_FIELD_OP:
481
482 return (BLOCK_NONE);
483
484 case AML_BUFFER_OP:
485 case AML_PACKAGE_OP:
486 case AML_VARIABLE_PACKAGE_OP:
487
488 return (BLOCK_COMMA_LIST);
489
490 default:
491
492 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
493 if (OpInfo->Flags & AML_HAS_ARGS)
494 {
495 return (BLOCK_COMMA_LIST);
496 }
497
498 return (BLOCK_NONE);
499 }
500 }
501
502
503 /*******************************************************************************
504 *
505 * FUNCTION: AcpiDmDescendingOp
506 *
507 * PARAMETERS: ASL_WALK_CALLBACK
508 *
509 * RETURN: Status
510 *
511 * DESCRIPTION: First visitation of a parse object during tree descent.
512 * Decode opcode name and begin parameter list(s), if any.
513 *
514 ******************************************************************************/
515
516 static ACPI_STATUS
AcpiDmDescendingOp(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)517 AcpiDmDescendingOp (
518 ACPI_PARSE_OBJECT *Op,
519 UINT32 Level,
520 void *Context)
521 {
522 ACPI_OP_WALK_INFO *Info = Context;
523 const ACPI_OPCODE_INFO *OpInfo;
524 UINT32 Name;
525 ACPI_PARSE_OBJECT *NextOp;
526 ACPI_PARSE_OBJECT *NextOp2;
527 UINT32 AmlOffset;
528
529
530 /* Determine which file this parse node is contained in. */
531
532 if (AcpiGbl_CaptureComments)
533 {
534 ASL_CV_LABEL_FILENODE (Op);
535
536 if (Level != 0 && ASL_CV_FILE_HAS_SWITCHED (Op))
537 {
538 ASL_CV_SWITCH_FILES (Level, Op);
539 }
540
541 /* If this parse node has regular comments, print them here. */
542
543 ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_STANDARD, NULL, Level);
544 }
545
546 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
547
548 /* Listing support to dump the AML code after the ASL statement */
549
550 if (AcpiGbl_DmOpt_Listing)
551 {
552 /* We only care about these classes of objects */
553
554 if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) ||
555 (OpInfo->Class == AML_CLASS_CONTROL) ||
556 (OpInfo->Class == AML_CLASS_CREATE) ||
557 ((OpInfo->Class == AML_CLASS_EXECUTE) && (!Op->Common.Next)))
558 {
559 if (AcpiGbl_DmOpt_Listing && Info->PreviousAml)
560 {
561 /* Dump the AML byte code for the previous Op */
562
563 if (Op->Common.Aml > Info->PreviousAml)
564 {
565 AcpiOsPrintf ("\n");
566 AcpiUtDumpBuffer (
567 (Info->StartAml + Info->AmlOffset),
568 (Op->Common.Aml - Info->PreviousAml),
569 DB_BYTE_DISPLAY, Info->AmlOffset);
570 AcpiOsPrintf ("\n");
571 }
572
573 Info->AmlOffset = (Op->Common.Aml - Info->StartAml);
574 }
575
576 Info->PreviousAml = Op->Common.Aml;
577 }
578 }
579
580 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
581 {
582 /* Ignore this op -- it was handled elsewhere */
583
584 return (AE_CTRL_DEPTH);
585 }
586
587 if (Op->Common.DisasmOpcode == ACPI_DASM_IGNORE_SINGLE)
588 {
589 /* Ignore this op, but not it's children */
590
591 return (AE_OK);
592 }
593
594 if (Op->Common.AmlOpcode == AML_IF_OP)
595 {
596 NextOp = AcpiPsGetDepthNext (NULL, Op);
597 if (NextOp)
598 {
599 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
600
601 /* Don't emit the actual embedded externals unless asked */
602
603 if (!AcpiGbl_DmEmitExternalOpcodes)
604 {
605 /*
606 * A Zero predicate indicates the possibility of one or more
607 * External() opcodes within the If() block.
608 */
609 if (NextOp->Common.AmlOpcode == AML_ZERO_OP)
610 {
611 NextOp2 = NextOp->Common.Next;
612
613 if (NextOp2 &&
614 (NextOp2->Common.AmlOpcode == AML_EXTERNAL_OP))
615 {
616 /* Ignore the If 0 block and all children */
617
618 Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
619 return (AE_CTRL_DEPTH);
620 }
621 }
622 }
623 }
624 }
625
626 /* Level 0 is at the Definition Block level */
627
628 if (Level == 0)
629 {
630 /* In verbose mode, print the AML offset, opcode and depth count */
631
632 if (Info->WalkState)
633 {
634 AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
635 Info->WalkState->ParserState.AmlStart);
636 if (AcpiGbl_DmOpt_Verbose)
637 {
638 if (AcpiGbl_CmSingleStep)
639 {
640 AcpiOsPrintf ("%5.5X/%4.4X: ",
641 AmlOffset, (UINT32) Op->Common.AmlOpcode);
642 }
643 else
644 {
645 AcpiOsPrintf ("AML Offset %5.5X, Opcode %4.4X: ",
646 AmlOffset, (UINT32) Op->Common.AmlOpcode);
647 }
648 }
649 }
650
651 if (Op->Common.AmlOpcode == AML_SCOPE_OP)
652 {
653 /* This is the beginning of the Definition Block */
654
655 AcpiOsPrintf ("{\n");
656
657 /* Emit all External() declarations here */
658
659 if (!AcpiGbl_DmEmitExternalOpcodes)
660 {
661 AcpiDmEmitExternals ();
662 }
663
664 return (AE_OK);
665 }
666 }
667 else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
668 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) &&
669 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_ELSEIF)) &&
670 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
671 {
672 /*
673 * This is a first-level element of a term list,
674 * indent a new line
675 */
676 switch (Op->Common.AmlOpcode)
677 {
678 case AML_NOOP_OP:
679 /*
680 * Optionally just ignore this opcode. Some tables use
681 * NoOp opcodes for "padding" out packages that the BIOS
682 * changes dynamically. This can leave hundreds or
683 * thousands of NoOp opcodes that if disassembled,
684 * cannot be compiled because they are syntactically
685 * incorrect.
686 */
687 if (AcpiGbl_IgnoreNoopOperator)
688 {
689 Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
690 return (AE_OK);
691 }
692
693 ACPI_FALLTHROUGH;
694
695 default:
696
697 AcpiDmIndent (Level);
698 break;
699 }
700
701 Info->LastLevel = Level;
702 Info->Count = 0;
703 }
704
705 /*
706 * This is an inexpensive mechanism to try and keep lines from getting
707 * too long. When the limit is hit, start a new line at the previous
708 * indent plus one. A better but more expensive mechanism would be to
709 * keep track of the current column.
710 */
711 Info->Count++;
712 if (Info->Count /* +Info->LastLevel */ > 12)
713 {
714 Info->Count = 0;
715 AcpiOsPrintf ("\n");
716 AcpiDmIndent (Info->LastLevel + 1);
717 }
718
719 /* If ASL+ is enabled, check for a C-style operator */
720
721 if (AcpiDmCheckForSymbolicOpcode (Op, Info))
722 {
723 return (AE_OK);
724 }
725
726 /* Print the opcode name */
727
728 AcpiDmDisassembleOneOp (NULL, Info, Op);
729
730 if ((Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX) ||
731 (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP))
732 {
733 return (AE_OK);
734 }
735
736 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
737 (Op->Common.AmlOpcode == AML_RETURN_OP))
738 {
739 Info->Level--;
740 }
741
742 if (Op->Common.AmlOpcode == AML_EXTERNAL_OP)
743 {
744 Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
745 return (AE_CTRL_DEPTH);
746 }
747
748 /* Start the opcode argument list if necessary */
749
750 if ((OpInfo->Flags & AML_HAS_ARGS) ||
751 (Op->Common.AmlOpcode == AML_EVENT_OP))
752 {
753 /* This opcode has an argument list */
754
755 if (AcpiDmBlockType (Op) & BLOCK_PAREN)
756 {
757 AcpiOsPrintf (" (");
758 if (!(AcpiDmBlockType (Op) & BLOCK_BRACE))
759 {
760 ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, " ", 0);
761 }
762 }
763
764 /* If this is a named opcode, print the associated name value */
765
766 if (OpInfo->Flags & AML_NAMED)
767 {
768 switch (Op->Common.AmlOpcode)
769 {
770 case AML_ALIAS_OP:
771
772 NextOp = AcpiPsGetDepthNext (NULL, Op);
773 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
774 AcpiDmNamestring (NextOp->Common.Value.Name);
775 AcpiOsPrintf (", ");
776
777 ACPI_FALLTHROUGH;
778
779 default:
780
781 Name = AcpiPsGetName (Op);
782 if (Op->Named.Path)
783 {
784 AcpiDmNamestring (Op->Named.Path);
785 }
786 else
787 {
788 AcpiDmDumpName (Name);
789 }
790
791 if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP)
792 {
793 if (AcpiGbl_DmOpt_Verbose)
794 {
795 (void) AcpiPsDisplayObjectPathname (NULL, Op);
796 }
797 }
798 break;
799 }
800
801 switch (Op->Common.AmlOpcode)
802 {
803 case AML_METHOD_OP:
804
805 AcpiDmMethodFlags (Op);
806 ASL_CV_CLOSE_PAREN (Op, Level);
807
808 /* Emit description comment for Method() with a predefined ACPI name */
809
810 AcpiDmPredefinedDescription (Op);
811 break;
812
813 case AML_NAME_OP:
814
815 /* Check for _HID and related EISAID() */
816
817 AcpiDmCheckForHardwareId (Op);
818 AcpiOsPrintf (", ");
819 ASL_CV_PRINT_ONE_COMMENT (Op, AML_NAMECOMMENT, NULL, 0);
820 break;
821
822 case AML_REGION_OP:
823
824 AcpiDmRegionFlags (Op);
825 break;
826
827 case AML_POWER_RESOURCE_OP:
828
829 /* Mark the next two Ops as part of the parameter list */
830
831 AcpiOsPrintf (", ");
832 NextOp = AcpiPsGetDepthNext (NULL, Op);
833 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
834
835 NextOp = NextOp->Common.Next;
836 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
837 return (AE_OK);
838
839 case AML_PROCESSOR_OP:
840
841 /* Mark the next three Ops as part of the parameter list */
842
843 AcpiOsPrintf (", ");
844 NextOp = AcpiPsGetDepthNext (NULL, Op);
845 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
846
847 NextOp = NextOp->Common.Next;
848 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
849
850 NextOp = NextOp->Common.Next;
851 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
852 return (AE_OK);
853
854 case AML_MUTEX_OP:
855 case AML_DATA_REGION_OP:
856
857 AcpiOsPrintf (", ");
858 return (AE_OK);
859
860 case AML_EVENT_OP:
861 case AML_ALIAS_OP:
862
863 return (AE_OK);
864
865 case AML_SCOPE_OP:
866 case AML_DEVICE_OP:
867 case AML_THERMAL_ZONE_OP:
868
869 ASL_CV_CLOSE_PAREN (Op, Level);
870 break;
871
872 default:
873
874 AcpiOsPrintf ("*** Unhandled named opcode %X\n",
875 Op->Common.AmlOpcode);
876 break;
877 }
878 }
879
880 else switch (Op->Common.AmlOpcode)
881 {
882 case AML_FIELD_OP:
883 case AML_BANK_FIELD_OP:
884 case AML_INDEX_FIELD_OP:
885
886 Info->BitOffset = 0;
887
888 /* Name of the parent OperationRegion */
889
890 NextOp = AcpiPsGetDepthNext (NULL, Op);
891 AcpiDmNamestring (NextOp->Common.Value.Name);
892 AcpiOsPrintf (", ");
893 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
894
895 switch (Op->Common.AmlOpcode)
896 {
897 case AML_BANK_FIELD_OP:
898
899 /* Namestring - Bank Name */
900
901 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
902 AcpiDmNamestring (NextOp->Common.Value.Name);
903 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
904 AcpiOsPrintf (", ");
905
906 /*
907 * Bank Value. This is a TermArg in the middle of the parameter
908 * list, must handle it here.
909 *
910 * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMETER_LIST
911 * eliminates newline in the output.
912 */
913 NextOp = NextOp->Common.Next;
914
915 Info->Flags = ACPI_PARSEOP_PARAMETER_LIST;
916 AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp,
917 AcpiDmAscendingOp, Info);
918 Info->Flags = 0;
919 Info->Level = Level;
920
921 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
922 AcpiOsPrintf (", ");
923 break;
924
925 case AML_INDEX_FIELD_OP:
926
927 /* Namestring - Data Name */
928
929 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
930 AcpiDmNamestring (NextOp->Common.Value.Name);
931 AcpiOsPrintf (", ");
932 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
933 break;
934
935 default:
936
937 break;
938 }
939
940 AcpiDmFieldFlags (NextOp);
941 break;
942
943 case AML_BUFFER_OP:
944
945 /* The next op is the size parameter */
946
947 NextOp = AcpiPsGetDepthNext (NULL, Op);
948 if (!NextOp)
949 {
950 /* Single-step support */
951
952 return (AE_OK);
953 }
954
955 if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE)
956 {
957 /*
958 * We have a resource list. Don't need to output
959 * the buffer size Op. Open up a new block
960 */
961 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
962 ASL_CV_CLOSE_PAREN (Op, Level);
963
964 /* Emit description comment for Name() with a predefined ACPI name */
965
966 AcpiDmPredefinedDescription (Op->Asl.Parent);
967
968 AcpiOsPrintf ("\n");
969 AcpiDmIndent (Info->Level);
970 AcpiOsPrintf ("{\n");
971 return (AE_OK);
972 }
973
974 /* Normal Buffer, mark size as in the parameter list */
975
976 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
977 return (AE_OK);
978
979 case AML_IF_OP:
980 case AML_VARIABLE_PACKAGE_OP:
981 case AML_WHILE_OP:
982
983 /* The next op is the size or predicate parameter */
984
985 NextOp = AcpiPsGetDepthNext (NULL, Op);
986 if (NextOp)
987 {
988 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
989 }
990 return (AE_OK);
991
992 case AML_PACKAGE_OP:
993
994 /* The next op is the size parameter */
995
996 NextOp = AcpiPsGetDepthNext (NULL, Op);
997 if (NextOp)
998 {
999 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
1000 }
1001 return (AE_OK);
1002
1003 case AML_MATCH_OP:
1004
1005 AcpiDmMatchOp (Op);
1006 break;
1007
1008 default:
1009
1010 break;
1011 }
1012
1013 if (AcpiDmBlockType (Op) & BLOCK_BRACE)
1014 {
1015 AcpiOsPrintf ("\n");
1016 AcpiDmIndent (Level);
1017 AcpiOsPrintf ("{\n");
1018 }
1019 }
1020
1021 return (AE_OK);
1022 }
1023
1024
1025 /*******************************************************************************
1026 *
1027 * FUNCTION: AcpiDmAscendingOp
1028 *
1029 * PARAMETERS: ASL_WALK_CALLBACK
1030 *
1031 * RETURN: Status
1032 *
1033 * DESCRIPTION: Second visitation of a parse object, during ascent of parse
1034 * tree. Close out any parameter lists and complete the opcode.
1035 *
1036 ******************************************************************************/
1037
1038 static ACPI_STATUS
AcpiDmAscendingOp(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)1039 AcpiDmAscendingOp (
1040 ACPI_PARSE_OBJECT *Op,
1041 UINT32 Level,
1042 void *Context)
1043 {
1044 ACPI_OP_WALK_INFO *Info = Context;
1045 ACPI_PARSE_OBJECT *ParentOp;
1046
1047
1048 /* Point the Op's filename pointer to the proper file */
1049
1050 if (AcpiGbl_CaptureComments)
1051 {
1052 ASL_CV_LABEL_FILENODE (Op);
1053
1054 /* Switch the output of these files if necessary */
1055
1056 if (ASL_CV_FILE_HAS_SWITCHED (Op))
1057 {
1058 ASL_CV_SWITCH_FILES (Level, Op);
1059 }
1060 }
1061
1062 if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE ||
1063 Op->Common.DisasmOpcode == ACPI_DASM_IGNORE_SINGLE)
1064 {
1065 /* Ignore this op -- it was handled elsewhere */
1066
1067 return (AE_OK);
1068 }
1069
1070 if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP))
1071 {
1072 /* Indicates the end of the current descriptor block (table) */
1073
1074 ASL_CV_CLOSE_BRACE (Op, Level);
1075
1076 /* Print any comments that are at the end of the file here */
1077
1078 if (AcpiGbl_CaptureComments && AcpiGbl_LastListHead)
1079 {
1080 AcpiOsPrintf ("\n");
1081 ASL_CV_PRINT_ONE_COMMENT_LIST (AcpiGbl_LastListHead, 0);
1082 }
1083 AcpiOsPrintf ("\n\n");
1084
1085 return (AE_OK);
1086 }
1087
1088 switch (AcpiDmBlockType (Op))
1089 {
1090 case BLOCK_PAREN:
1091
1092 /* Completed an op that has arguments, add closing paren if needed */
1093
1094 AcpiDmCloseOperator (Op);
1095
1096 if (Op->Common.AmlOpcode == AML_NAME_OP)
1097 {
1098 /* Emit description comment for Name() with a predefined ACPI name */
1099
1100 AcpiDmPredefinedDescription (Op);
1101 }
1102 else
1103 {
1104 /* For Create* operators, attempt to emit resource tag description */
1105
1106 AcpiDmFieldPredefinedDescription (Op);
1107 }
1108
1109 /* Decode Notify() values */
1110
1111 if (Op->Common.AmlOpcode == AML_NOTIFY_OP)
1112 {
1113 AcpiDmNotifyDescription (Op);
1114 }
1115
1116 AcpiDmDisplayTargetPathname (Op);
1117
1118 /* Could be a nested operator, check if comma required */
1119
1120 if (!AcpiDmCommaIfListMember (Op))
1121 {
1122 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
1123 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) &&
1124 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
1125 {
1126 /*
1127 * This is a first-level element of a term list
1128 * start a new line
1129 */
1130 if (!(Info->Flags & ACPI_PARSEOP_PARAMETER_LIST))
1131 {
1132 AcpiOsPrintf ("\n");
1133 }
1134 }
1135 }
1136 break;
1137
1138 case BLOCK_BRACE:
1139 case (BLOCK_BRACE | BLOCK_PAREN):
1140
1141 /* Completed an op that has a term list, add closing brace */
1142
1143 if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)
1144 {
1145 ASL_CV_CLOSE_BRACE (Op, Level);
1146 }
1147 else
1148 {
1149 AcpiDmIndent (Level);
1150 ASL_CV_CLOSE_BRACE (Op, Level);
1151 }
1152
1153 AcpiDmCommaIfListMember (Op);
1154
1155 if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN)
1156 {
1157 AcpiOsPrintf ("\n");
1158 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST))
1159 {
1160 if ((Op->Common.AmlOpcode == AML_IF_OP) &&
1161 (Op->Common.Next) &&
1162 (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP))
1163 {
1164 break;
1165 }
1166
1167 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
1168 (!Op->Common.Next))
1169 {
1170 break;
1171 }
1172 AcpiOsPrintf ("\n");
1173 }
1174 }
1175 break;
1176
1177 case BLOCK_NONE:
1178 default:
1179
1180 /* Could be a nested operator, check if comma required */
1181
1182 if (!AcpiDmCommaIfListMember (Op))
1183 {
1184 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
1185 (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)) &&
1186 (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
1187 {
1188 /*
1189 * This is a first-level element of a term list
1190 * start a new line
1191 */
1192 AcpiOsPrintf ("\n");
1193 }
1194 }
1195 else if (Op->Common.Parent)
1196 {
1197 switch (Op->Common.Parent->Common.AmlOpcode)
1198 {
1199 case AML_PACKAGE_OP:
1200 case AML_VARIABLE_PACKAGE_OP:
1201
1202 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST))
1203 {
1204 AcpiOsPrintf ("\n");
1205 }
1206 break;
1207
1208 default:
1209
1210 break;
1211 }
1212 }
1213 break;
1214 }
1215
1216 if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST)
1217 {
1218 if ((Op->Common.Next) &&
1219 (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMETER_LIST))
1220 {
1221 return (AE_OK);
1222 }
1223
1224 /*
1225 * The parent Op is guaranteed to be valid because of the flag
1226 * ACPI_PARSEOP_PARAMETER_LIST -- which means that this op is part of
1227 * a parameter list and thus has a valid parent.
1228 */
1229 ParentOp = Op->Common.Parent;
1230
1231 /*
1232 * Just completed a parameter node for something like "Buffer (param)".
1233 * Close the paren and open up the term list block with a brace.
1234 *
1235 * Switch predicates don't have a Next node but require a closing paren
1236 * and opening brace.
1237 */
1238 if (Op->Common.Next || Op->Common.DisasmOpcode == ACPI_DASM_SWITCH_PREDICATE)
1239 {
1240 ASL_CV_CLOSE_PAREN (Op, Level);
1241
1242 /*
1243 * Emit a description comment for a Name() operator that is a
1244 * predefined ACPI name. Must check the grandparent.
1245 */
1246 ParentOp = ParentOp->Common.Parent;
1247 if (ParentOp &&
1248 (ParentOp->Asl.AmlOpcode == AML_NAME_OP))
1249 {
1250 AcpiDmPredefinedDescription (ParentOp);
1251 }
1252
1253 /* Correct the indentation level for Switch and Case predicates */
1254
1255 if (Op->Common.DisasmOpcode == ACPI_DASM_SWITCH_PREDICATE)
1256 {
1257 --Level;
1258 }
1259
1260 AcpiOsPrintf ("\n");
1261 AcpiDmIndent (Level - 1);
1262 AcpiOsPrintf ("{\n");
1263 }
1264 else
1265 {
1266 ParentOp->Common.DisasmFlags |= ACPI_PARSEOP_EMPTY_TERMLIST;
1267 ASL_CV_CLOSE_PAREN (Op, Level);
1268 AcpiOsPrintf ("{");
1269 }
1270 }
1271
1272 if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
1273 (Op->Common.AmlOpcode == AML_RETURN_OP))
1274 {
1275 Info->Level++;
1276 }
1277
1278 /*
1279 * For ASL+, check for and emit a C-style symbol. If valid, the
1280 * symbol string has been deferred until after the first operand
1281 */
1282 if (AcpiGbl_CstyleDisassembly)
1283 {
1284 if (Op->Asl.OperatorSymbol)
1285 {
1286 AcpiOsPrintf ("%s", Op->Asl.OperatorSymbol);
1287 Op->Asl.OperatorSymbol = NULL;
1288 }
1289 }
1290
1291 return (AE_OK);
1292 }
1293
1294 #endif /* ACPI_DISASSEMBLER */
1295