xref: /onnv-gate/usr/src/uts/intel/io/acpica/disassembler/dmobject.c (revision 3446:5903aece022d)
1 /*******************************************************************************
2  *
3  * Module Name: dmobject - ACPI object decode and display
4  *              $Revision: 1.20 $
5  *
6  ******************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 
118 #include "acpi.h"
119 #include "amlcode.h"
120 #include "acnamesp.h"
121 #include "acdisasm.h"
122 #include "acparser.h"
123 
124 
125 #ifdef ACPI_DISASSEMBLER
126 
127 #define _COMPONENT          ACPI_CA_DEBUGGER
128         ACPI_MODULE_NAME    ("dmnames")
129 
130 /* Local prototypes */
131 
132 static void
133 AcpiDmDecodeNode (
134     ACPI_NAMESPACE_NODE     *Node);
135 
136 
137 /*******************************************************************************
138  *
139  * FUNCTION:    AcpiDmDumpMethodInfo
140  *
141  * PARAMETERS:  Status          - Method execution status
142  *              WalkState       - Current state of the parse tree walk
143  *              Op              - Executing parse op
144  *
145  * RETURN:      None
146  *
147  * DESCRIPTION: Called when a method has been aborted because of an error.
148  *              Dumps the method execution stack, and the method locals/args,
149  *              and disassembles the AML opcode that failed.
150  *
151  ******************************************************************************/
152 
153 void
154 AcpiDmDumpMethodInfo (
155     ACPI_STATUS             Status,
156     ACPI_WALK_STATE         *WalkState,
157     ACPI_PARSE_OBJECT       *Op)
158 {
159     ACPI_PARSE_OBJECT       *Next;
160     ACPI_THREAD_STATE       *Thread;
161     ACPI_WALK_STATE         *NextWalkState;
162     ACPI_NAMESPACE_NODE     *PreviousMethod = NULL;
163 
164 
165     /* Ignore control codes, they are not errors */
166 
167     if ((Status & AE_CODE_MASK) == AE_CODE_CONTROL)
168     {
169         return;
170     }
171 
172     /* We may be executing a deferred opcode */
173 
174     if (WalkState->DeferredNode)
175     {
176         AcpiOsPrintf ("Executing subtree for Buffer/Package/Region\n");
177         return;
178     }
179 
180     /*
181      * If there is no Thread, we are not actually executing a method.
182      * This can happen when the iASL compiler calls the interpreter
183      * to perform constant folding.
184      */
185     Thread = WalkState->Thread;
186     if (!Thread)
187     {
188         return;
189     }
190 
191     /* Display exception and method name */
192 
193     AcpiOsPrintf ("\n**** Exception %s during execution of method ",
194         AcpiFormatException (Status));
195     AcpiNsPrintNodePathname (WalkState->MethodNode, NULL);
196 
197     /* Display stack of executing methods */
198 
199     AcpiOsPrintf ("\n\nMethod Execution Stack:\n");
200     NextWalkState = Thread->WalkStateList;
201 
202     /* Walk list of linked walk states */
203 
204     while (NextWalkState)
205     {
206         AcpiOsPrintf ("    Method [%4.4s] executing: ",
207                 AcpiUtGetNodeName (NextWalkState->MethodNode));
208 
209         /* First method is the currently executing method */
210 
211         if (NextWalkState == WalkState)
212         {
213             /* Display currently executing ASL statement */
214 
215             Next = Op->Common.Next;
216             Op->Common.Next = NULL;
217 
218             AcpiDmDisassemble (NextWalkState, Op, ACPI_UINT32_MAX);
219             Op->Common.Next = Next;
220         }
221         else
222         {
223             /*
224              * This method has called another method
225              * NOTE: the method call parse subtree is already deleted at this
226              * point, so we cannot disassemble the method invocation.
227              */
228             AcpiOsPrintf ("Call to method ");
229             AcpiNsPrintNodePathname (PreviousMethod, NULL);
230         }
231 
232         PreviousMethod = NextWalkState->MethodNode;
233         NextWalkState = NextWalkState->Next;
234         AcpiOsPrintf ("\n");
235     }
236 
237     /* Display the method locals and arguments */
238 
239     AcpiOsPrintf ("\n");
240     AcpiDmDisplayLocals (WalkState);
241     AcpiOsPrintf ("\n");
242     AcpiDmDisplayArguments (WalkState);
243     AcpiOsPrintf ("\n");
244 }
245 
246 
247 /*******************************************************************************
248  *
249  * FUNCTION:    AcpiDmDecodeInternalObject
250  *
251  * PARAMETERS:  ObjDesc         - Object to be displayed
252  *
253  * RETURN:      None
254  *
255  * DESCRIPTION: Short display of an internal object.  Numbers/Strings/Buffers.
256  *
257  ******************************************************************************/
258 
259 void
260 AcpiDmDecodeInternalObject (
261     ACPI_OPERAND_OBJECT     *ObjDesc)
262 {
263     UINT32                  i;
264 
265 
266     if (!ObjDesc)
267     {
268         AcpiOsPrintf (" Uninitialized");
269         return;
270     }
271 
272     if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
273     {
274         AcpiOsPrintf (" %p [%s]", ObjDesc, AcpiUtGetDescriptorName (ObjDesc));
275         return;
276     }
277 
278     AcpiOsPrintf (" %s", AcpiUtGetObjectTypeName (ObjDesc));
279 
280     switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
281     {
282     case ACPI_TYPE_INTEGER:
283 
284         AcpiOsPrintf (" %8.8X%8.8X",
285                 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
286         break;
287 
288 
289     case ACPI_TYPE_STRING:
290 
291         AcpiOsPrintf ("(%d) \"%.24s",
292                 ObjDesc->String.Length, ObjDesc->String.Pointer);
293 
294         if (ObjDesc->String.Length > 24)
295         {
296             AcpiOsPrintf ("...");
297         }
298         else
299         {
300             AcpiOsPrintf ("\"");
301         }
302         break;
303 
304 
305     case ACPI_TYPE_BUFFER:
306 
307         AcpiOsPrintf ("(%d)", ObjDesc->Buffer.Length);
308         for (i = 0; (i < 8) && (i < ObjDesc->Buffer.Length); i++)
309         {
310             AcpiOsPrintf (" %2.2X", ObjDesc->Buffer.Pointer[i]);
311         }
312         break;
313 
314 
315     default:
316 
317         AcpiOsPrintf (" %p", ObjDesc);
318         break;
319     }
320 }
321 
322 
323 /*******************************************************************************
324  *
325  * FUNCTION:    AcpiDmDecodeNode
326  *
327  * PARAMETERS:  Node        - Object to be displayed
328  *
329  * RETURN:      None
330  *
331  * DESCRIPTION: Short display of a namespace node
332  *
333  ******************************************************************************/
334 
335 static void
336 AcpiDmDecodeNode (
337     ACPI_NAMESPACE_NODE     *Node)
338 {
339 
340     AcpiOsPrintf ("<Node>            Name %4.4s",
341             AcpiUtGetNodeName (Node));
342 
343     if (Node->Flags & ANOBJ_METHOD_ARG)
344     {
345         AcpiOsPrintf (" [Method Arg]");
346     }
347     if (Node->Flags & ANOBJ_METHOD_LOCAL)
348     {
349         AcpiOsPrintf (" [Method Local]");
350     }
351 
352     AcpiDmDecodeInternalObject (AcpiNsGetAttachedObject (Node));
353 }
354 
355 
356 /*******************************************************************************
357  *
358  * FUNCTION:    AcpiDmDisplayInternalObject
359  *
360  * PARAMETERS:  ObjDesc         - Object to be displayed
361  *              WalkState       - Current walk state
362  *
363  * RETURN:      None
364  *
365  * DESCRIPTION: Short display of an internal object
366  *
367  ******************************************************************************/
368 
369 void
370 AcpiDmDisplayInternalObject (
371     ACPI_OPERAND_OBJECT     *ObjDesc,
372     ACPI_WALK_STATE         *WalkState)
373 {
374     UINT8                   Type;
375 
376 
377     AcpiOsPrintf ("%p ", ObjDesc);
378 
379     if (!ObjDesc)
380     {
381         AcpiOsPrintf ("<Null Object>\n");
382         return;
383     }
384 
385     /* Decode the object type */
386 
387     switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
388     {
389     case ACPI_DESC_TYPE_PARSER:
390 
391         AcpiOsPrintf ("<Parser>  ");
392         break;
393 
394 
395     case ACPI_DESC_TYPE_NAMED:
396 
397         AcpiDmDecodeNode ((ACPI_NAMESPACE_NODE *) ObjDesc);
398         break;
399 
400 
401     case ACPI_DESC_TYPE_OPERAND:
402 
403         Type = ACPI_GET_OBJECT_TYPE (ObjDesc);
404         if (Type > ACPI_TYPE_LOCAL_MAX)
405         {
406             AcpiOsPrintf (" Type %X [Invalid Type]", (UINT32) Type);
407             return;
408         }
409 
410         /* Decode the ACPI object type */
411 
412         switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
413         {
414         case ACPI_TYPE_LOCAL_REFERENCE:
415 
416             switch (ObjDesc->Reference.Opcode)
417             {
418             case AML_LOCAL_OP:
419 
420                 AcpiOsPrintf ("[Local%d] ", ObjDesc->Reference.Offset);
421                 if (WalkState)
422                 {
423                     ObjDesc = WalkState->LocalVariables[
424                                 ObjDesc->Reference.Offset].Object;
425                     AcpiOsPrintf ("%p", ObjDesc);
426                     AcpiDmDecodeInternalObject (ObjDesc);
427                 }
428                 break;
429 
430 
431             case AML_ARG_OP:
432 
433                 AcpiOsPrintf ("[Arg%d]   ", ObjDesc->Reference.Offset);
434                 if (WalkState)
435                 {
436                     ObjDesc = WalkState->Arguments[
437                                 ObjDesc->Reference.Offset].Object;
438                     AcpiOsPrintf ("%p", ObjDesc);
439                     AcpiDmDecodeInternalObject (ObjDesc);
440                 }
441                 break;
442 
443 
444             case AML_DEBUG_OP:
445 
446                 AcpiOsPrintf ("[Debug]  ");
447                 break;
448 
449 
450             case AML_INDEX_OP:
451 
452                 AcpiOsPrintf ("[Index]  ");
453                 switch (ObjDesc->Reference.TargetType)
454                 {
455                 case ACPI_TYPE_BUFFER_FIELD:
456                     AcpiOsPrintf ("%p", ObjDesc->Reference.Object);
457                     AcpiDmDecodeInternalObject (ObjDesc->Reference.Object);
458                     break;
459 
460                 case ACPI_TYPE_PACKAGE:
461 
462                     AcpiOsPrintf ("%p", ObjDesc->Reference.Where);
463                     if (!ObjDesc->Reference.Where)
464                     {
465                         AcpiOsPrintf (" Uninitialized WHERE ptr");
466                     }
467                     else
468                     {
469                         AcpiDmDecodeInternalObject (
470                             *(ObjDesc->Reference.Where));
471                     }
472                     break;
473 
474                 default:
475                     AcpiOsPrintf ("Unknown index target type");
476                     break;
477                 }
478                 break;
479 
480 
481             case AML_LOAD_OP:
482 
483                 AcpiOsPrintf ("[DdbHandle]  ");
484                 break;
485 
486 
487             case AML_REF_OF_OP:
488 
489                 AcpiOsPrintf ("[RefOf]          ");
490 
491                 if (!ObjDesc->Reference.Object)
492                 {
493                     AcpiOsPrintf ("Uninitialized reference subobject ptr");
494                     break;
495                 }
496 
497                 /* Reference can be to a Node or an Operand object */
498 
499                 switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc->Reference.Object))
500                 {
501                 case ACPI_DESC_TYPE_NAMED:
502                     AcpiDmDecodeNode (ObjDesc->Reference.Object);
503                     break;
504 
505                 case ACPI_DESC_TYPE_OPERAND:
506                     AcpiDmDecodeInternalObject (ObjDesc->Reference.Object);
507                     break;
508 
509                 default:
510                     break;
511                 }
512                 break;
513 
514             case AML_INT_NAMEPATH_OP:
515 
516                 AcpiDmDecodeNode (ObjDesc->Reference.Node);
517                 break;
518 
519             default:
520 
521                 AcpiOsPrintf ("Unknown Reference opcode %X (%s)\n",
522                     ObjDesc->Reference.Opcode,
523                     AcpiPsGetOpcodeName (ObjDesc->Reference.Opcode));
524                 break;
525             }
526             break;
527 
528         default:
529 
530             AcpiOsPrintf ("<Obj>            ");
531             AcpiDmDecodeInternalObject (ObjDesc);
532             break;
533         }
534         break;
535 
536 
537     default:
538 
539         AcpiOsPrintf ("<Not a valid ACPI Object Descriptor> [%s]",
540                 AcpiUtGetDescriptorName (ObjDesc));
541         break;
542     }
543 
544     AcpiOsPrintf ("\n");
545 }
546 
547 
548 /*******************************************************************************
549  *
550  * FUNCTION:    AcpiDmDisplayLocals
551  *
552  * PARAMETERS:  WalkState       - State for current method
553  *
554  * RETURN:      None
555  *
556  * DESCRIPTION: Display all locals for the currently running control method
557  *
558  ******************************************************************************/
559 
560 void
561 AcpiDmDisplayLocals (
562     ACPI_WALK_STATE         *WalkState)
563 {
564     UINT32                  i;
565     ACPI_OPERAND_OBJECT     *ObjDesc;
566     ACPI_NAMESPACE_NODE     *Node;
567 
568 
569     ObjDesc = WalkState->MethodDesc;
570     Node    = WalkState->MethodNode;
571     if (!Node)
572     {
573         AcpiOsPrintf (
574             "No method node (Executing subtree for buffer or opregion)\n");
575         return;
576     }
577 
578     if (Node->Type != ACPI_TYPE_METHOD)
579     {
580         AcpiOsPrintf ("Executing subtree for Buffer/Package/Region\n");
581         return;
582     }
583 
584     AcpiOsPrintf ("Local Variables for method [%4.4s]:\n",
585             AcpiUtGetNodeName (Node));
586 
587     for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
588     {
589         ObjDesc = WalkState->LocalVariables[i].Object;
590         AcpiOsPrintf ("    Local%X: ", i);
591         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
592     }
593 }
594 
595 
596 /*******************************************************************************
597  *
598  * FUNCTION:    AcpiDmDisplayArguments
599  *
600  * PARAMETERS:  WalkState       - State for current method
601  *
602  * RETURN:      None
603  *
604  * DESCRIPTION: Display all arguments for the currently running control method
605  *
606  ******************************************************************************/
607 
608 void
609 AcpiDmDisplayArguments (
610     ACPI_WALK_STATE         *WalkState)
611 {
612     UINT32                  i;
613     ACPI_OPERAND_OBJECT     *ObjDesc;
614     ACPI_NAMESPACE_NODE     *Node;
615 
616 
617     ObjDesc = WalkState->MethodDesc;
618     Node    = WalkState->MethodNode;
619     if (!Node)
620     {
621         AcpiOsPrintf (
622             "No method node (Executing subtree for buffer or opregion)\n");
623         return;
624     }
625 
626     if (Node->Type != ACPI_TYPE_METHOD)
627     {
628         AcpiOsPrintf ("Executing subtree for Buffer/Package/Region\n");
629         return;
630     }
631 
632     AcpiOsPrintf (
633         "Arguments for Method [%4.4s]:  (%X arguments defined, max concurrency = %X)\n",
634         AcpiUtGetNodeName (Node), ObjDesc->Method.ParamCount, ObjDesc->Method.SyncLevel);
635 
636     for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
637     {
638         ObjDesc = WalkState->Arguments[i].Object;
639         AcpiOsPrintf ("    Arg%d:   ", i);
640         AcpiDmDisplayInternalObject (ObjDesc, WalkState);
641     }
642 }
643 
644 #endif
645 
646 
647