dmopcode.c revision 102550
1/*******************************************************************************
2 *
3 * Module Name: dmopcode - AML disassembler, specific AML opcodes
4 *              $Revision: 77 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, 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#include "acpi.h"
118#include "acparser.h"
119#include "amlcode.h"
120#include "acdisasm.h"
121#include "acdebug.h"
122
123#ifdef ACPI_DISASSEMBLER
124
125#define _COMPONENT          ACPI_CA_DEBUGGER
126        ACPI_MODULE_NAME    ("dmopcode")
127
128
129/*******************************************************************************
130 *
131 * FUNCTION:    AcpiDmMethodFlags
132 *
133 * PARAMETERS:  Op              - Method Object to be examined
134 *
135 * RETURN:      None
136 *
137 * DESCRIPTION: Decode control method flags
138 *
139 ******************************************************************************/
140
141void
142AcpiDmMethodFlags (
143    ACPI_PARSE_OBJECT       *Op)
144{
145    UINT32                  Flags;
146    UINT32                  Args;
147
148
149    /* The next Op contains the flags */
150
151    Op = AcpiPsGetDepthNext (NULL, Op);
152    Flags = Op->Common.Value.Integer8;
153    Args = Flags & 0x07;
154
155    /* Mark the Op as completed */
156
157    Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
158
159    /* 1) Method argument count */
160
161    AcpiOsPrintf (", %d, ", Args);
162
163    /* 2) Serialize rule */
164
165    if (!(Flags & 0x08))
166    {
167        AcpiOsPrintf ("Not");
168    }
169
170    AcpiOsPrintf ("Serialized");
171
172    /* 3) SyncLevel */
173
174    if (Flags & 0xF0)
175    {
176        AcpiOsPrintf (", %d", Flags >> 4);
177    }
178}
179
180
181/*******************************************************************************
182 *
183 * FUNCTION:    AcpiDmFieldFlags
184 *
185 * PARAMETERS:  Op              - Field Object to be examined
186 *
187 * RETURN:      None
188 *
189 * DESCRIPTION: Decode Field definition flags
190 *
191 ******************************************************************************/
192
193void
194AcpiDmFieldFlags (
195    ACPI_PARSE_OBJECT       *Op)
196{
197    UINT32                  Flags;
198
199
200    /* The next Op contains the flags */
201
202    Op = AcpiPsGetDepthNext (NULL, Op);
203    Flags = Op->Common.Value.Integer8;
204
205    /* Mark the Op as completed */
206
207    Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
208
209    AcpiOsPrintf ("%s, ", AcpiGbl_AccessTypes [Flags & 0x0F]);
210    AcpiOsPrintf ("%s, ", AcpiGbl_LockRule [(Flags & 0x10) >> 4]);
211    AcpiOsPrintf ("%s)",  AcpiGbl_UpdateRules [(Flags & 0x60) >> 5]);
212}
213
214
215/*******************************************************************************
216 *
217 * FUNCTION:    AcpiDmAddressSpace
218 *
219 * PARAMETERS:  SpaceId         - ID to be translated
220 *
221 * RETURN:      None
222 *
223 * DESCRIPTION: Decode a SpaceId to an AddressSpaceKeyword
224 *
225 ******************************************************************************/
226
227void
228AcpiDmAddressSpace (
229    UINT8                   SpaceId)
230{
231
232    if (SpaceId >= ACPI_NUM_PREDEFINED_REGIONS)
233    {
234        if (SpaceId == 0x7F)
235        {
236            AcpiOsPrintf ("FFixedHW, ");
237        }
238        else
239        {
240            AcpiOsPrintf ("0x%.2X, ", SpaceId);
241        }
242    }
243    else
244    {
245        AcpiOsPrintf ("%s, ", AcpiGbl_RegionTypes [SpaceId]);
246    }
247}
248
249
250/*******************************************************************************
251 *
252 * FUNCTION:    AcpiDmRegionFlags
253 *
254 * PARAMETERS:  Op              - Object to be examined
255 *
256 * RETURN:      None
257 *
258 * DESCRIPTION: Decode OperationRegion flags
259 *
260 ******************************************************************************/
261
262void
263AcpiDmRegionFlags (
264    ACPI_PARSE_OBJECT       *Op)
265{
266
267
268    /* The next Op contains the SpaceId */
269
270    Op = AcpiPsGetDepthNext (NULL, Op);
271
272    /* Mark the Op as completed */
273
274    Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
275
276    AcpiOsPrintf (", ");
277    AcpiDmAddressSpace (Op->Common.Value.Integer8);
278}
279
280
281/*******************************************************************************
282 *
283 * FUNCTION:    AcpiDmMatchOp
284 *
285 * PARAMETERS:  Op              - Match Object to be examined
286 *
287 * RETURN:      None
288 *
289 * DESCRIPTION: Decode Match opcode operands
290 *
291 ******************************************************************************/
292
293void
294AcpiDmMatchOp (
295    ACPI_PARSE_OBJECT       *Op)
296{
297    ACPI_PARSE_OBJECT       *NextOp;
298
299
300    NextOp = AcpiPsGetDepthNext (NULL, Op);
301    NextOp = NextOp->Common.Next;
302
303    if (!NextOp)
304    {
305        /* Handle partial tree during single-step */
306
307        return;
308    }
309
310    /* Mark the two nodes that contain the encoding for the match keywords */
311
312    NextOp->Common.DisasmOpcode = ACPI_DASM_MATCHOP;
313
314    NextOp = NextOp->Common.Next;
315    NextOp = NextOp->Common.Next;
316    NextOp->Common.DisasmOpcode = ACPI_DASM_MATCHOP;
317}
318
319
320/*******************************************************************************
321 *
322 * FUNCTION:    AcpiDmMatchKeyword
323 *
324 * PARAMETERS:  Op              - Match Object to be examined
325 *
326 * RETURN:      None
327 *
328 * DESCRIPTION: Decode Match opcode operands
329 *
330 ******************************************************************************/
331
332void
333AcpiDmMatchKeyword (
334    ACPI_PARSE_OBJECT       *Op)
335{
336
337
338    if (Op->Common.Value.Integer32 >= NUM_MATCH_OPS)
339    {
340        AcpiOsPrintf ("/* Unknown Match Keyword encoding */");
341    }
342    else
343    {
344        AcpiOsPrintf ("%s", (char *) AcpiGbl_MatchOps[Op->Common.Value.Integer32]);
345    }
346}
347
348
349/*******************************************************************************
350 *
351 * FUNCTION:    AcpiDmDisassembleOneOp
352 *
353 * PARAMETERS:  WalkState           - Current walk info
354 *              Info                - Parse tree walk info
355 *              Op                  - Op that is to be printed
356 *
357 * RETURN:      None
358 *
359 * DESCRIPTION: Disassemble a single AML opcode
360 *
361 ******************************************************************************/
362
363void
364AcpiDmDisassembleOneOp (
365    ACPI_WALK_STATE         *WalkState,
366    ACPI_OP_WALK_INFO       *Info,
367    ACPI_PARSE_OBJECT       *Op)
368{
369    const ACPI_OPCODE_INFO  *OpInfo = NULL;
370    UINT32                  Offset;
371    UINT32                  Length;
372
373
374    if (!Op)
375    {
376        AcpiOsPrintf ("<NULL OP PTR>");
377        return;
378    }
379
380    switch (Op->Common.DisasmOpcode)
381    {
382    case ACPI_DASM_MATCHOP:
383
384        AcpiDmMatchKeyword (Op);
385        return;
386
387    default:
388        break;
389    }
390
391
392    /* op and arguments */
393
394    switch (Op->Common.AmlOpcode)
395    {
396    case AML_ZERO_OP:
397
398        AcpiOsPrintf ("Zero");
399        break;
400
401
402    case AML_ONE_OP:
403
404        AcpiOsPrintf ("One");
405        break;
406
407
408    case AML_ONES_OP:
409
410        AcpiOsPrintf ("Ones");
411        break;
412
413
414    case AML_REVISION_OP:
415
416        AcpiOsPrintf ("Revision");
417        break;
418
419
420    case AML_BYTE_OP:
421
422        AcpiOsPrintf ("0x%2.2X", (UINT32) Op->Common.Value.Integer8);
423        break;
424
425
426    case AML_WORD_OP:
427
428        if (Op->Common.DisasmOpcode == ACPI_DASM_EISAID)
429        {
430            AcpiDmEisaId (Op->Common.Value.Integer32);
431        }
432        else
433        {
434            AcpiOsPrintf ("0x%4.4X", (UINT32) Op->Common.Value.Integer16);
435        }
436        break;
437
438
439    case AML_DWORD_OP:
440
441        if (Op->Common.DisasmOpcode == ACPI_DASM_EISAID)
442        {
443            AcpiDmEisaId (Op->Common.Value.Integer32);
444        }
445        else
446        {
447            AcpiOsPrintf ("0x%8.8X", Op->Common.Value.Integer32);
448        }
449        break;
450
451
452    case AML_QWORD_OP:
453
454        AcpiOsPrintf ("0x%8.8X%8.8X", Op->Common.Value.Integer64.Hi,
455                                      Op->Common.Value.Integer64.Lo);
456        break;
457
458
459    case AML_STRING_OP:
460
461        AcpiDmString (Op->Common.Value.String);
462        break;
463
464
465    case AML_BUFFER_OP:
466
467        /*
468         * Determine the type of buffer.  We can have one of the following:
469         *
470         * 1) ResourceTemplate containing Resource Descriptors.
471         * 2) Unicode String buffer
472         * 3) ASCII String buffer
473         * 4) Raw data buffer (if none of the above)
474         *
475         * Since there are no special AML opcodes to differentiate these
476         * types of buffers, we have to closely look at the data in the
477         * buffer to determine the type.
478         */
479        if (AcpiDmIsResourceDescriptor (Op))
480        {
481            Op->Common.DisasmOpcode = ACPI_DASM_RESOURCE;
482            AcpiOsPrintf ("ResourceTemplate");
483        }
484        else if (AcpiDmIsUnicodeBuffer (Op))
485        {
486            Op->Common.DisasmOpcode = ACPI_DASM_UNICODE;
487            AcpiOsPrintf ("Unicode (");
488        }
489        else if (AcpiDmIsStringBuffer (Op))
490        {
491            Op->Common.DisasmOpcode = ACPI_DASM_STRING;
492            AcpiOsPrintf ("Buffer");
493        }
494        else
495        {
496            Op->Common.DisasmOpcode = ACPI_DASM_BUFFER;
497            AcpiOsPrintf ("Buffer");
498        }
499        break;
500
501
502    case AML_INT_STATICSTRING_OP:
503
504        if (Op->Common.Value.String)
505        {
506            AcpiOsPrintf ("%s", Op->Common.Value.String);
507        }
508        else
509        {
510            AcpiOsPrintf ("\"<NULL STATIC STRING PTR>\"");
511        }
512        break;
513
514
515    case AML_INT_NAMEPATH_OP:
516
517        AcpiDmNamestring (Op->Common.Value.Name);
518        AcpiDmValidateName (Op->Common.Value.Name, Op);
519        break;
520
521
522    case AML_INT_NAMEDFIELD_OP:
523
524        Length = AcpiDmDumpName ((char *) &Op->Named.Name);
525        AcpiOsPrintf (",%*.s  %d", (int) (5 - Length), " ", Op->Common.Value.Integer32);
526        AcpiDmCommaIfFieldMember (Op);
527
528        Info->BitOffset += Op->Common.Value.Integer32;
529        break;
530
531
532    case AML_INT_RESERVEDFIELD_OP:
533
534        /* Offset() -- Must account for previous offsets */
535
536        Offset = Op->Common.Value.Integer32;
537        Info->BitOffset += Offset;
538
539        if (Info->BitOffset % 8 == 0)
540        {
541            AcpiOsPrintf ("Offset (0x%.2X)", ACPI_DIV_8 (Info->BitOffset));
542        }
543        else
544        {
545            AcpiOsPrintf ("    ,   %d", Offset);
546        }
547
548        AcpiDmCommaIfFieldMember (Op);
549        break;
550
551
552    case AML_INT_ACCESSFIELD_OP:
553
554        AcpiOsPrintf ("AccessAs (%s, 0x%.2X)",
555            AcpiGbl_AccessTypes [Op->Common.Value.Integer32 >> 8],
556            Op->Common.Value.Integer32 & 0x0F);
557
558        AcpiDmCommaIfFieldMember (Op);
559        break;
560
561
562    case AML_INT_BYTELIST_OP:
563
564        AcpiDmByteList (Info, Op);
565        break;
566
567
568    case AML_INT_METHODCALL_OP:
569
570        OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
571        Op = AcpiPsGetDepthNext (NULL, Op);
572        Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
573
574        AcpiDmNamestring (Op->Common.Value.Name);
575        break;
576
577
578    default:
579
580        /* Just get the opcode name and print it */
581
582        OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
583        AcpiOsPrintf ("%s", OpInfo->Name);
584
585
586#ifdef ACPI_DEBUGGER
587
588        if ((Op->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP) &&
589            (WalkState) &&
590            (WalkState->Results) &&
591            (WalkState->Results->Results.NumResults))
592        {
593            AcpiDbDecodeInternalObject (
594                WalkState->Results->Results.ObjDesc [WalkState->Results->Results.NumResults-1]);
595        }
596#endif
597        break;
598    }
599}
600
601#endif  /* ACPI_DISASSEMBLER */
602