]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/components/disassembler/dmwalk.c
Merge ACPICA 20150818.
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / components / disassembler / dmwalk.c
1 /*******************************************************************************
2  *
3  * Module Name: dmwalk - AML disassembly tree walk
4  *
5  ******************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acparser.h>
47 #include <contrib/dev/acpica/include/amlcode.h>
48 #include <contrib/dev/acpica/include/acdebug.h>
49
50
51 #define _COMPONENT          ACPI_CA_DEBUGGER
52         ACPI_MODULE_NAME    ("dmwalk")
53
54
55 #define DB_FULL_OP_INFO     "[%4.4s] @%5.5X #%4.4X:  "
56
57 /* Stub for non-compiler code */
58
59 #ifndef ACPI_ASL_COMPILER
60 void
61 AcpiDmEmitExternals (
62     void)
63 {
64     return;
65 }
66 #endif
67
68 /* Local prototypes */
69
70 static ACPI_STATUS
71 AcpiDmDescendingOp (
72     ACPI_PARSE_OBJECT       *Op,
73     UINT32                  Level,
74     void                    *Context);
75
76 static ACPI_STATUS
77 AcpiDmAscendingOp (
78     ACPI_PARSE_OBJECT       *Op,
79     UINT32                  Level,
80     void                    *Context);
81
82 static UINT32
83 AcpiDmBlockType (
84     ACPI_PARSE_OBJECT       *Op);
85
86
87 /*******************************************************************************
88  *
89  * FUNCTION:    AcpiDmDisassemble
90  *
91  * PARAMETERS:  WalkState       - Current state
92  *              Origin          - Starting object
93  *              NumOpcodes      - Max number of opcodes to be displayed
94  *
95  * RETURN:      None
96  *
97  * DESCRIPTION: Disassemble parser object and its children. This is the
98  *              main entry point of the disassembler.
99  *
100  ******************************************************************************/
101
102 void
103 AcpiDmDisassemble (
104     ACPI_WALK_STATE         *WalkState,
105     ACPI_PARSE_OBJECT       *Origin,
106     UINT32                  NumOpcodes)
107 {
108     ACPI_PARSE_OBJECT       *Op = Origin;
109     ACPI_OP_WALK_INFO       Info;
110
111
112     if (!Op)
113     {
114         return;
115     }
116
117     memset (&Info, 0, sizeof (ACPI_OP_WALK_INFO));
118     Info.WalkState = WalkState;
119     Info.StartAml = Op->Common.Aml - sizeof (ACPI_TABLE_HEADER);
120     Info.AmlOffset = Op->Common.Aml - Info.StartAml;
121
122     AcpiDmWalkParseTree (Op, AcpiDmDescendingOp, AcpiDmAscendingOp, &Info);
123     return;
124 }
125
126
127 /*******************************************************************************
128  *
129  * FUNCTION:    AcpiDmWalkParseTree
130  *
131  * PARAMETERS:  Op                      - Root Op object
132  *              DescendingCallback      - Called during tree descent
133  *              AscendingCallback       - Called during tree ascent
134  *              Context                 - To be passed to the callbacks
135  *
136  * RETURN:      Status from callback(s)
137  *
138  * DESCRIPTION: Walk the entire parse tree.
139  *
140  ******************************************************************************/
141
142 void
143 AcpiDmWalkParseTree (
144     ACPI_PARSE_OBJECT       *Op,
145     ASL_WALK_CALLBACK       DescendingCallback,
146     ASL_WALK_CALLBACK       AscendingCallback,
147     void                    *Context)
148 {
149     BOOLEAN                 NodePreviouslyVisited;
150     ACPI_PARSE_OBJECT       *StartOp = Op;
151     ACPI_STATUS             Status;
152     ACPI_PARSE_OBJECT       *Next;
153     ACPI_OP_WALK_INFO       *Info = Context;
154
155
156     Info->Level = 0;
157     NodePreviouslyVisited = FALSE;
158
159     while (Op)
160     {
161         if (NodePreviouslyVisited)
162         {
163             if (AscendingCallback)
164             {
165                 Status = AscendingCallback (Op, Info->Level, Context);
166                 if (ACPI_FAILURE (Status))
167                 {
168                     return;
169                 }
170             }
171         }
172         else
173         {
174             /* Let the callback process the node */
175
176             Status = DescendingCallback (Op, Info->Level, Context);
177             if (ACPI_SUCCESS (Status))
178             {
179                 /* Visit children first, once */
180
181                 Next = AcpiPsGetArg (Op, 0);
182                 if (Next)
183                 {
184                     Info->Level++;
185                     Op = Next;
186                     continue;
187                 }
188             }
189             else if (Status != AE_CTRL_DEPTH)
190             {
191                 /* Exit immediately on any error */
192
193                 return;
194             }
195         }
196
197         /* Terminate walk at start op */
198
199         if (Op == StartOp)
200         {
201             break;
202         }
203
204         /* No more children, re-visit this node */
205
206         if (!NodePreviouslyVisited)
207         {
208             NodePreviouslyVisited = TRUE;
209             continue;
210         }
211
212         /* No more children, visit peers */
213
214         if (Op->Common.Next)
215         {
216             Op = Op->Common.Next;
217             NodePreviouslyVisited = FALSE;
218         }
219         else
220         {
221             /* No peers, re-visit parent */
222
223             if (Info->Level != 0 )
224             {
225                 Info->Level--;
226             }
227
228             Op = Op->Common.Parent;
229             NodePreviouslyVisited = TRUE;
230         }
231     }
232
233     /* If we get here, the walk completed with no errors */
234
235     return;
236 }
237
238
239 /*******************************************************************************
240  *
241  * FUNCTION:    AcpiDmBlockType
242  *
243  * PARAMETERS:  Op              - Object to be examined
244  *
245  * RETURN:      BlockType - not a block, parens, braces, or even both.
246  *
247  * DESCRIPTION: Type of block for this op (parens or braces)
248  *
249  ******************************************************************************/
250
251 static UINT32
252 AcpiDmBlockType (
253     ACPI_PARSE_OBJECT       *Op)
254 {
255     const ACPI_OPCODE_INFO  *OpInfo;
256
257
258     if (!Op)
259     {
260         return (BLOCK_NONE);
261     }
262
263     switch (Op->Common.AmlOpcode)
264     {
265     case AML_ELSE_OP:
266
267         return (BLOCK_BRACE);
268
269     case AML_METHOD_OP:
270     case AML_DEVICE_OP:
271     case AML_SCOPE_OP:
272     case AML_PROCESSOR_OP:
273     case AML_POWER_RES_OP:
274     case AML_THERMAL_ZONE_OP:
275     case AML_IF_OP:
276     case AML_WHILE_OP:
277     case AML_FIELD_OP:
278     case AML_INDEX_FIELD_OP:
279     case AML_BANK_FIELD_OP:
280
281         return (BLOCK_PAREN | BLOCK_BRACE);
282
283     case AML_BUFFER_OP:
284
285         if ((Op->Common.DisasmOpcode == ACPI_DASM_UNICODE) ||
286             (Op->Common.DisasmOpcode == ACPI_DASM_UUID) ||
287             (Op->Common.DisasmOpcode == ACPI_DASM_PLD_METHOD))
288         {
289             return (BLOCK_NONE);
290         }
291
292         /*lint -fallthrough */
293
294     case AML_PACKAGE_OP:
295     case AML_VAR_PACKAGE_OP:
296
297         return (BLOCK_PAREN | BLOCK_BRACE);
298
299     case AML_EVENT_OP:
300
301         return (BLOCK_PAREN);
302
303     case AML_INT_METHODCALL_OP:
304
305         if (Op->Common.Parent &&
306             ((Op->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
307              (Op->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
308         {
309             /* This is a reference to a method, not an invocation */
310
311             return (BLOCK_NONE);
312         }
313
314         /*lint -fallthrough */
315
316     default:
317
318         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
319         if (OpInfo->Flags & AML_HAS_ARGS)
320         {
321             return (BLOCK_PAREN);
322         }
323
324         return (BLOCK_NONE);
325     }
326 }
327
328
329 /*******************************************************************************
330  *
331  * FUNCTION:    AcpiDmListType
332  *
333  * PARAMETERS:  Op              - Object to be examined
334  *
335  * RETURN:      ListType - has commas or not.
336  *
337  * DESCRIPTION: Type of block for this op (parens or braces)
338  *
339  ******************************************************************************/
340
341 UINT32
342 AcpiDmListType (
343     ACPI_PARSE_OBJECT       *Op)
344 {
345     const ACPI_OPCODE_INFO  *OpInfo;
346
347
348     if (!Op)
349     {
350         return (BLOCK_NONE);
351     }
352
353     switch (Op->Common.AmlOpcode)
354     {
355
356     case AML_ELSE_OP:
357     case AML_METHOD_OP:
358     case AML_DEVICE_OP:
359     case AML_SCOPE_OP:
360     case AML_POWER_RES_OP:
361     case AML_PROCESSOR_OP:
362     case AML_THERMAL_ZONE_OP:
363     case AML_IF_OP:
364     case AML_WHILE_OP:
365     case AML_FIELD_OP:
366     case AML_INDEX_FIELD_OP:
367     case AML_BANK_FIELD_OP:
368
369         return (BLOCK_NONE);
370
371     case AML_BUFFER_OP:
372     case AML_PACKAGE_OP:
373     case AML_VAR_PACKAGE_OP:
374
375         return (BLOCK_COMMA_LIST);
376
377     default:
378
379         OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
380         if (OpInfo->Flags & AML_HAS_ARGS)
381         {
382             return (BLOCK_COMMA_LIST);
383         }
384
385         return (BLOCK_NONE);
386     }
387 }
388
389
390 /*******************************************************************************
391  *
392  * FUNCTION:    AcpiDmDescendingOp
393  *
394  * PARAMETERS:  ASL_WALK_CALLBACK
395  *
396  * RETURN:      Status
397  *
398  * DESCRIPTION: First visitation of a parse object during tree descent.
399  *              Decode opcode name and begin parameter list(s), if any.
400  *
401  ******************************************************************************/
402
403 static ACPI_STATUS
404 AcpiDmDescendingOp (
405     ACPI_PARSE_OBJECT       *Op,
406     UINT32                  Level,
407     void                    *Context)
408 {
409     ACPI_OP_WALK_INFO       *Info = Context;
410     const ACPI_OPCODE_INFO  *OpInfo;
411     UINT32                  Name;
412     ACPI_PARSE_OBJECT       *NextOp;
413     UINT32                  AmlOffset;
414
415
416     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
417
418     /* Listing support to dump the AML code after the ASL statement */
419
420     if (AcpiGbl_DmOpt_Listing)
421     {
422         /* We only care about these classes of objects */
423
424         if ((OpInfo->Class == AML_CLASS_NAMED_OBJECT) ||
425             (OpInfo->Class == AML_CLASS_CONTROL) ||
426             (OpInfo->Class == AML_CLASS_CREATE) ||
427             ((OpInfo->Class == AML_CLASS_EXECUTE) && (!Op->Common.Next)))
428         {
429             if (AcpiGbl_DmOpt_Listing && Info->PreviousAml)
430             {
431                 /* Dump the AML byte code for the previous Op */
432
433                 if (Op->Common.Aml > Info->PreviousAml)
434                 {
435                     AcpiOsPrintf ("\n");
436                     AcpiUtDumpBuffer (
437                         (Info->StartAml + Info->AmlOffset),
438                         (Op->Common.Aml - Info->PreviousAml),
439                         DB_BYTE_DISPLAY,
440                         Info->AmlOffset);
441                     AcpiOsPrintf ("\n");
442                 }
443
444                 Info->AmlOffset = (Op->Common.Aml - Info->StartAml);
445             }
446
447             Info->PreviousAml = Op->Common.Aml;
448         }
449     }
450
451     if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
452     {
453         /* Ignore this op -- it was handled elsewhere */
454
455         return (AE_CTRL_DEPTH);
456     }
457
458     /* Level 0 is at the Definition Block level */
459
460     if (Level == 0)
461     {
462         /* In verbose mode, print the AML offset, opcode and depth count */
463
464         if (Info->WalkState)
465         {
466             AmlOffset = (UINT32) ACPI_PTR_DIFF (Op->Common.Aml,
467                             Info->WalkState->ParserState.AmlStart);
468             if (AcpiGbl_DmOpt_Verbose)
469             {
470                 AcpiOsPrintf (DB_FULL_OP_INFO,
471                     (Info->WalkState->MethodNode ?
472                         Info->WalkState->MethodNode->Name.Ascii : "   "),
473                     AmlOffset, (UINT32) Op->Common.AmlOpcode);
474             }
475         }
476
477         if (Op->Common.AmlOpcode == AML_SCOPE_OP)
478         {
479             /* This is the beginning of the Definition Block */
480
481             AcpiOsPrintf ("{\n");
482
483             /* Emit all External() declarations here */
484
485             AcpiDmEmitExternals ();
486             return (AE_OK);
487         }
488     }
489     else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
490              (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
491              (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
492     {
493             /*
494              * This is a first-level element of a term list,
495              * indent a new line
496              */
497             switch (Op->Common.AmlOpcode)
498             {
499             case AML_NOOP_OP:
500                 /*
501                  * Optionally just ignore this opcode. Some tables use
502                  * NoOp opcodes for "padding" out packages that the BIOS
503                  * changes dynamically. This can leave hundreds or
504                  * thousands of NoOp opcodes that if disassembled,
505                  * cannot be compiled because they are syntactically
506                  * incorrect.
507                  */
508                 if (AcpiGbl_IgnoreNoopOperator)
509                 {
510                     Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
511                     return (AE_OK);
512                 }
513
514                 /* Fallthrough */
515
516             default:
517
518                 AcpiDmIndent (Level);
519                 break;
520             }
521
522             Info->LastLevel = Level;
523             Info->Count = 0;
524     }
525
526     /*
527      * This is an inexpensive mechanism to try and keep lines from getting
528      * too long. When the limit is hit, start a new line at the previous
529      * indent plus one. A better but more expensive mechanism would be to
530      * keep track of the current column.
531      */
532     Info->Count++;
533     if (Info->Count /* +Info->LastLevel */ > 12)
534     {
535         Info->Count = 0;
536         AcpiOsPrintf ("\n");
537         AcpiDmIndent (Info->LastLevel + 1);
538     }
539
540     /* If ASL+ is enabled, check for a C-style operator */
541
542     if (AcpiDmCheckForSymbolicOpcode (Op, Info))
543     {
544         return (AE_OK);
545     }
546
547     /* Print the opcode name */
548
549     AcpiDmDisassembleOneOp (NULL, Info, Op);
550
551     if ((Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX) ||
552         (Op->Common.AmlOpcode == AML_INT_CONNECTION_OP))
553     {
554         return (AE_OK);
555     }
556
557     if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
558         (Op->Common.AmlOpcode == AML_RETURN_OP))
559     {
560         Info->Level--;
561     }
562
563     /* Start the opcode argument list if necessary */
564
565     if ((OpInfo->Flags & AML_HAS_ARGS) ||
566         (Op->Common.AmlOpcode == AML_EVENT_OP))
567     {
568         /* This opcode has an argument list */
569
570         if (AcpiDmBlockType (Op) & BLOCK_PAREN)
571         {
572             AcpiOsPrintf (" (");
573         }
574
575         /* If this is a named opcode, print the associated name value */
576
577         if (OpInfo->Flags & AML_NAMED)
578         {
579             switch (Op->Common.AmlOpcode)
580             {
581             case AML_ALIAS_OP:
582
583                 NextOp = AcpiPsGetDepthNext (NULL, Op);
584                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
585                 AcpiDmNamestring (NextOp->Common.Value.Name);
586                 AcpiOsPrintf (", ");
587
588                 /*lint -fallthrough */
589
590             default:
591
592                 Name = AcpiPsGetName (Op);
593                 if (Op->Named.Path)
594                 {
595                     AcpiDmNamestring ((char *) Op->Named.Path);
596                 }
597                 else
598                 {
599                     AcpiDmDumpName (Name);
600                 }
601
602                 if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP)
603                 {
604                     if (AcpiGbl_DmOpt_Verbose)
605                     {
606                         (void) AcpiPsDisplayObjectPathname (NULL, Op);
607                     }
608                 }
609                 break;
610             }
611
612             switch (Op->Common.AmlOpcode)
613             {
614             case AML_METHOD_OP:
615
616                 AcpiDmMethodFlags (Op);
617                 AcpiOsPrintf (")");
618
619                 /* Emit description comment for Method() with a predefined ACPI name */
620
621                 AcpiDmPredefinedDescription (Op);
622                 break;
623
624             case AML_NAME_OP:
625
626                 /* Check for _HID and related EISAID() */
627
628                 AcpiDmCheckForHardwareId (Op);
629                 AcpiOsPrintf (", ");
630                 break;
631
632             case AML_REGION_OP:
633
634                 AcpiDmRegionFlags (Op);
635                 break;
636
637             case AML_POWER_RES_OP:
638
639                 /* Mark the next two Ops as part of the parameter list */
640
641                 AcpiOsPrintf (", ");
642                 NextOp = AcpiPsGetDepthNext (NULL, Op);
643                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
644
645                 NextOp = NextOp->Common.Next;
646                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
647                 return (AE_OK);
648
649             case AML_PROCESSOR_OP:
650
651                 /* Mark the next three Ops as part of the parameter list */
652
653                 AcpiOsPrintf (", ");
654                 NextOp = AcpiPsGetDepthNext (NULL, Op);
655                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
656
657                 NextOp = NextOp->Common.Next;
658                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
659
660                 NextOp = NextOp->Common.Next;
661                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
662                 return (AE_OK);
663
664             case AML_MUTEX_OP:
665             case AML_DATA_REGION_OP:
666
667                 AcpiOsPrintf (", ");
668                 return (AE_OK);
669
670             case AML_EVENT_OP:
671             case AML_ALIAS_OP:
672
673                 return (AE_OK);
674
675             case AML_SCOPE_OP:
676             case AML_DEVICE_OP:
677             case AML_THERMAL_ZONE_OP:
678
679                 AcpiOsPrintf (")");
680                 break;
681
682             default:
683
684                 AcpiOsPrintf ("*** Unhandled named opcode %X\n",
685                     Op->Common.AmlOpcode);
686                 break;
687             }
688         }
689
690         else switch (Op->Common.AmlOpcode)
691         {
692         case AML_FIELD_OP:
693         case AML_BANK_FIELD_OP:
694         case AML_INDEX_FIELD_OP:
695
696             Info->BitOffset = 0;
697
698             /* Name of the parent OperationRegion */
699
700             NextOp = AcpiPsGetDepthNext (NULL, Op);
701             AcpiDmNamestring (NextOp->Common.Value.Name);
702             AcpiOsPrintf (", ");
703             NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
704
705             switch (Op->Common.AmlOpcode)
706             {
707             case AML_BANK_FIELD_OP:
708
709                 /* Namestring - Bank Name */
710
711                 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
712                 AcpiDmNamestring (NextOp->Common.Value.Name);
713                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
714                 AcpiOsPrintf (", ");
715
716                 /*
717                  * Bank Value. This is a TermArg in the middle of the parameter
718                  * list, must handle it here.
719                  *
720                  * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMLIST
721                  * eliminates newline in the output.
722                  */
723                 NextOp = NextOp->Common.Next;
724
725                 Info->Flags = ACPI_PARSEOP_PARAMLIST;
726                 AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp,
727                     AcpiDmAscendingOp, Info);
728                 Info->Flags = 0;
729                 Info->Level = Level;
730
731                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
732                 AcpiOsPrintf (", ");
733                 break;
734
735             case AML_INDEX_FIELD_OP:
736
737                 /* Namestring - Data Name */
738
739                 NextOp = AcpiPsGetDepthNext (NULL, NextOp);
740                 AcpiDmNamestring (NextOp->Common.Value.Name);
741                 AcpiOsPrintf (", ");
742                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
743                 break;
744
745             default:
746
747                 break;
748             }
749
750             AcpiDmFieldFlags (NextOp);
751             break;
752
753         case AML_BUFFER_OP:
754
755             /* The next op is the size parameter */
756
757             NextOp = AcpiPsGetDepthNext (NULL, Op);
758             if (!NextOp)
759             {
760                 /* Single-step support */
761
762                 return (AE_OK);
763             }
764
765             if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE)
766             {
767                 /*
768                  * We have a resource list. Don't need to output
769                  * the buffer size Op. Open up a new block
770                  */
771                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
772                 NextOp = NextOp->Common.Next;
773                 AcpiOsPrintf (")");
774
775                 /* Emit description comment for Name() with a predefined ACPI name */
776
777                 AcpiDmPredefinedDescription (Op->Asl.Parent);
778
779                 AcpiOsPrintf ("\n");
780                 AcpiDmIndent (Info->Level);
781                 AcpiOsPrintf ("{\n");
782                 return (AE_OK);
783             }
784
785             /* Normal Buffer, mark size as in the parameter list */
786
787             NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
788             return (AE_OK);
789
790         case AML_VAR_PACKAGE_OP:
791         case AML_IF_OP:
792         case AML_WHILE_OP:
793
794             /* The next op is the size or predicate parameter */
795
796             NextOp = AcpiPsGetDepthNext (NULL, Op);
797             if (NextOp)
798             {
799                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
800             }
801             return (AE_OK);
802
803         case AML_PACKAGE_OP:
804
805             /* The next op is the size parameter */
806
807             NextOp = AcpiPsGetDepthNext (NULL, Op);
808             if (NextOp)
809             {
810                 NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
811             }
812             return (AE_OK);
813
814         case AML_MATCH_OP:
815
816             AcpiDmMatchOp (Op);
817             break;
818
819         default:
820
821             break;
822         }
823
824         if (AcpiDmBlockType (Op) & BLOCK_BRACE)
825         {
826             AcpiOsPrintf ("\n");
827             AcpiDmIndent (Level);
828             AcpiOsPrintf ("{\n");
829         }
830     }
831
832     return (AE_OK);
833 }
834
835
836 /*******************************************************************************
837  *
838  * FUNCTION:    AcpiDmAscendingOp
839  *
840  * PARAMETERS:  ASL_WALK_CALLBACK
841  *
842  * RETURN:      Status
843  *
844  * DESCRIPTION: Second visitation of a parse object, during ascent of parse
845  *              tree. Close out any parameter lists and complete the opcode.
846  *
847  ******************************************************************************/
848
849 static ACPI_STATUS
850 AcpiDmAscendingOp (
851     ACPI_PARSE_OBJECT       *Op,
852     UINT32                  Level,
853     void                    *Context)
854 {
855     ACPI_OP_WALK_INFO       *Info = Context;
856     ACPI_PARSE_OBJECT       *ParentOp;
857
858
859     if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
860     {
861         /* Ignore this op -- it was handled elsewhere */
862
863         return (AE_OK);
864     }
865
866     if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP))
867     {
868         /* Indicates the end of the current descriptor block (table) */
869
870         AcpiOsPrintf ("}\n\n");
871         return (AE_OK);
872     }
873
874     switch (AcpiDmBlockType (Op))
875     {
876     case BLOCK_PAREN:
877
878         /* Completed an op that has arguments, add closing paren if needed */
879
880         AcpiDmCloseOperator (Op);
881
882         if (Op->Common.AmlOpcode == AML_NAME_OP)
883         {
884             /* Emit description comment for Name() with a predefined ACPI name */
885
886             AcpiDmPredefinedDescription (Op);
887         }
888         else
889         {
890             /* For Create* operators, attempt to emit resource tag description */
891
892             AcpiDmFieldPredefinedDescription (Op);
893         }
894
895         /* Decode Notify() values */
896
897         if (Op->Common.AmlOpcode == AML_NOTIFY_OP)
898         {
899             AcpiDmNotifyDescription (Op);
900         }
901
902         AcpiDmDisplayTargetPathname (Op);
903
904         /* Could be a nested operator, check if comma required */
905
906         if (!AcpiDmCommaIfListMember (Op))
907         {
908             if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
909                      (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
910                      (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
911             {
912                 /*
913                  * This is a first-level element of a term list
914                  * start a new line
915                  */
916                 if (!(Info->Flags & ACPI_PARSEOP_PARAMLIST))
917                 {
918                     AcpiOsPrintf ("\n");
919                 }
920             }
921         }
922         break;
923
924     case BLOCK_BRACE:
925     case (BLOCK_BRACE | BLOCK_PAREN):
926
927         /* Completed an op that has a term list, add closing brace */
928
929         if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)
930         {
931             AcpiOsPrintf ("}");
932         }
933         else
934         {
935             AcpiDmIndent (Level);
936             AcpiOsPrintf ("}");
937         }
938
939         AcpiDmCommaIfListMember (Op);
940
941         if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN)
942         {
943             AcpiOsPrintf ("\n");
944             if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST))
945             {
946                 if ((Op->Common.AmlOpcode == AML_IF_OP)  &&
947                     (Op->Common.Next) &&
948                     (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP))
949                 {
950                     break;
951                 }
952
953                 if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
954                     (!Op->Common.Next))
955                 {
956                     break;
957                 }
958                 AcpiOsPrintf ("\n");
959             }
960         }
961         break;
962
963     case BLOCK_NONE:
964     default:
965
966         /* Could be a nested operator, check if comma required */
967
968         if (!AcpiDmCommaIfListMember (Op))
969         {
970             if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
971                      (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
972                      (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
973             {
974                 /*
975                  * This is a first-level element of a term list
976                  * start a new line
977                  */
978                 AcpiOsPrintf ("\n");
979             }
980         }
981         else if (Op->Common.Parent)
982         {
983             switch (Op->Common.Parent->Common.AmlOpcode)
984             {
985             case AML_PACKAGE_OP:
986             case AML_VAR_PACKAGE_OP:
987
988                 if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
989                 {
990                     AcpiOsPrintf ("\n");
991                 }
992                 break;
993
994             default:
995
996                 break;
997             }
998         }
999         break;
1000     }
1001
1002     if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)
1003     {
1004         if ((Op->Common.Next) &&
1005             (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
1006         {
1007             return (AE_OK);
1008         }
1009
1010         /*
1011          * The parent Op is guaranteed to be valid because of the flag
1012          * ACPI_PARSEOP_PARAMLIST -- which means that this op is part of
1013          * a parameter list and thus has a valid parent.
1014          */
1015         ParentOp = Op->Common.Parent;
1016
1017         /*
1018          * Just completed a parameter node for something like "Buffer (param)".
1019          * Close the paren and open up the term list block with a brace
1020          */
1021         if (Op->Common.Next)
1022         {
1023             AcpiOsPrintf (")");
1024
1025             /*
1026              * Emit a description comment for a Name() operator that is a
1027              * predefined ACPI name. Must check the grandparent.
1028              */
1029             ParentOp = ParentOp->Common.Parent;
1030             if (ParentOp &&
1031                 (ParentOp->Asl.AmlOpcode == AML_NAME_OP))
1032             {
1033                 AcpiDmPredefinedDescription (ParentOp);
1034             }
1035
1036             AcpiOsPrintf ("\n");
1037             AcpiDmIndent (Level - 1);
1038             AcpiOsPrintf ("{\n");
1039         }
1040         else
1041         {
1042             ParentOp->Common.DisasmFlags |= ACPI_PARSEOP_EMPTY_TERMLIST;
1043             AcpiOsPrintf (") {");
1044         }
1045     }
1046
1047     if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
1048         (Op->Common.AmlOpcode == AML_RETURN_OP))
1049     {
1050         Info->Level++;
1051     }
1052
1053     /*
1054      * For ASL+, check for and emit a C-style symbol. If valid, the
1055      * symbol string has been deferred until after the first operand
1056      */
1057     if (AcpiGbl_CstyleDisassembly)
1058     {
1059         if (Op->Asl.OperatorSymbol)
1060         {
1061             AcpiOsPrintf ("%s", Op->Asl.OperatorSymbol);
1062             Op->Asl.OperatorSymbol = NULL;
1063         }
1064     }
1065
1066     return (AE_OK);
1067 }