13446Smrj /*******************************************************************************
23446Smrj *
33446Smrj * Module Name: dmwalk - AML disassembly tree walk
43446Smrj *
53446Smrj ******************************************************************************/
63446Smrj
73446Smrj /******************************************************************************
83446Smrj *
93446Smrj * 1. Copyright Notice
103446Smrj *
119980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj * All rights reserved.
133446Smrj *
143446Smrj * 2. License
153446Smrj *
163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj * rights. You may have additional license terms from the party that provided
183446Smrj * you this software, covering your right to use that party's intellectual
193446Smrj * property rights.
203446Smrj *
213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj * copy of the source code appearing in this file ("Covered Code") an
233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj * make derivatives, distribute, use and display any portion of the Covered
263446Smrj * Code in any form, with the right to sublicense such rights; and
273446Smrj *
283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj * license (with the right to sublicense), under only those claims of Intel
303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj * solely to the minimum extent necessary to exercise the above copyright
333446Smrj * license, and in no event shall the patent license extend to any additions
343446Smrj * to or modifications of the Original Intel Code. No other license or right
353446Smrj * is granted directly or by implication, estoppel or otherwise;
363446Smrj *
373446Smrj * The above copyright and patent license is granted only if the following
383446Smrj * conditions are met:
393446Smrj *
403446Smrj * 3. Conditions
413446Smrj *
423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj * Redistribution of source code of any substantial portion of the Covered
443446Smrj * Code or modification with rights to further distribute source must include
453446Smrj * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj * and the following Disclaimer and Export Compliance provision. In addition,
473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj * contain a file documenting the changes Licensee made to create that Covered
493446Smrj * Code and the date of any change. Licensee must include in that file the
503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee
513446Smrj * must include a prominent statement that the modification is derived,
523446Smrj * directly or indirectly, from Original Intel Code.
533446Smrj *
543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj * Redistribution of source code of any substantial portion of the Covered
563446Smrj * Code or modification without rights to further distribute source must
573446Smrj * include the following Disclaimer and Export Compliance provision in the
583446Smrj * documentation and/or other materials provided with distribution. In
593446Smrj * addition, Licensee may not authorize further sublicense of source of any
603446Smrj * portion of the Covered Code, and must include terms to the effect that the
613446Smrj * license from Licensee to its licensee is limited to the intellectual
623446Smrj * property embodied in the software Licensee provides to its licensee, and
633446Smrj * not to intellectual property embodied in modifications its licensee may
643446Smrj * make.
653446Smrj *
663446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj * substantial portion of the Covered Code or modification must reproduce the
683446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj * provision in the documentation and/or other materials provided with the
703446Smrj * distribution.
713446Smrj *
723446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj * Intel Code.
743446Smrj *
753446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj * other dealings in products derived from or relating to the Covered Code
783446Smrj * without prior written authorization from Intel.
793446Smrj *
803446Smrj * 4. Disclaimer and Export Compliance
813446Smrj *
823446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
853446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
863446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj * PARTICULAR PURPOSE.
893446Smrj *
903446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
963446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj * LIMITED REMEDY.
983446Smrj *
993446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj * software or system incorporating such software without first obtaining any
1013446Smrj * required license or other approval from the U. S. Department of Commerce or
1023446Smrj * any other agency or department of the United States Government. In the
1033446Smrj * event Licensee exports any such software from the United States or
1043446Smrj * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj * ensure that the distribution and export/re-export of the software is in
1063446Smrj * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj * software, or service, directly or indirectly, to any country for which the
1103446Smrj * United States government or any agency thereof requires an export license,
1113446Smrj * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj * such license, approval or letter.
1133446Smrj *
1143446Smrj *****************************************************************************/
1153446Smrj
1163446Smrj
1173446Smrj #include "acpi.h"
1189980SDana.Myers@Sun.COM #include "accommon.h"
1193446Smrj #include "acparser.h"
1203446Smrj #include "amlcode.h"
1213446Smrj #include "acdisasm.h"
1223446Smrj #include "acdebug.h"
1233446Smrj
1243446Smrj
1253446Smrj #ifdef ACPI_DISASSEMBLER
1263446Smrj
1273446Smrj #define _COMPONENT ACPI_CA_DEBUGGER
1283446Smrj ACPI_MODULE_NAME ("dmwalk")
1293446Smrj
1303446Smrj
1313446Smrj #define DB_FULL_OP_INFO "[%4.4s] @%5.5X #%4.4X: "
1323446Smrj
133*11225SDana.Myers@Sun.COM /* Stub for non-compiler code */
134*11225SDana.Myers@Sun.COM
135*11225SDana.Myers@Sun.COM #ifndef ACPI_ASL_COMPILER
136*11225SDana.Myers@Sun.COM void
AcpiDmEmitExternals(void)137*11225SDana.Myers@Sun.COM AcpiDmEmitExternals (
138*11225SDana.Myers@Sun.COM void)
139*11225SDana.Myers@Sun.COM {
140*11225SDana.Myers@Sun.COM return;
141*11225SDana.Myers@Sun.COM }
142*11225SDana.Myers@Sun.COM #endif
143*11225SDana.Myers@Sun.COM
1443446Smrj /* Local prototypes */
1453446Smrj
1463446Smrj static ACPI_STATUS
1473446Smrj AcpiDmDescendingOp (
1483446Smrj ACPI_PARSE_OBJECT *Op,
1493446Smrj UINT32 Level,
1503446Smrj void *Context);
1513446Smrj
1523446Smrj static ACPI_STATUS
1533446Smrj AcpiDmAscendingOp (
1543446Smrj ACPI_PARSE_OBJECT *Op,
1553446Smrj UINT32 Level,
1563446Smrj void *Context);
1573446Smrj
1583446Smrj static UINT32
1593446Smrj AcpiDmBlockType (
1603446Smrj ACPI_PARSE_OBJECT *Op);
1613446Smrj
1629980SDana.Myers@Sun.COM
1633446Smrj
1643446Smrj /*******************************************************************************
1653446Smrj *
1663446Smrj * FUNCTION: AcpiDmDisassemble
1673446Smrj *
1683446Smrj * PARAMETERS: WalkState - Current state
1693446Smrj * Origin - Starting object
1703446Smrj * NumOpcodes - Max number of opcodes to be displayed
1713446Smrj *
1723446Smrj * RETURN: None
1733446Smrj *
1743446Smrj * DESCRIPTION: Disassemble parser object and its children. This is the
1753446Smrj * main entry point of the disassembler.
1763446Smrj *
1773446Smrj ******************************************************************************/
1783446Smrj
1793446Smrj void
AcpiDmDisassemble(ACPI_WALK_STATE * WalkState,ACPI_PARSE_OBJECT * Origin,UINT32 NumOpcodes)1803446Smrj AcpiDmDisassemble (
1813446Smrj ACPI_WALK_STATE *WalkState,
1823446Smrj ACPI_PARSE_OBJECT *Origin,
1833446Smrj UINT32 NumOpcodes)
1843446Smrj {
1853446Smrj ACPI_PARSE_OBJECT *Op = Origin;
1863446Smrj ACPI_OP_WALK_INFO Info;
1873446Smrj
1883446Smrj
1893446Smrj if (!Op)
1903446Smrj {
1913446Smrj return;
1923446Smrj }
1933446Smrj
1943446Smrj Info.Flags = 0;
1953446Smrj Info.Level = 0;
1963446Smrj Info.Count = 0;
1973446Smrj Info.WalkState = WalkState;
1983446Smrj AcpiDmWalkParseTree (Op, AcpiDmDescendingOp, AcpiDmAscendingOp, &Info);
1993446Smrj return;
2003446Smrj }
2013446Smrj
2023446Smrj
2033446Smrj /*******************************************************************************
2043446Smrj *
2053446Smrj * FUNCTION: AcpiDmWalkParseTree
2063446Smrj *
2073446Smrj * PARAMETERS: Op - Root Op object
2083446Smrj * DescendingCallback - Called during tree descent
2093446Smrj * AscendingCallback - Called during tree ascent
2103446Smrj * Context - To be passed to the callbacks
2113446Smrj *
2123446Smrj * RETURN: Status from callback(s)
2133446Smrj *
2143446Smrj * DESCRIPTION: Walk the entire parse tree.
2153446Smrj *
2163446Smrj ******************************************************************************/
2173446Smrj
2183446Smrj void
AcpiDmWalkParseTree(ACPI_PARSE_OBJECT * Op,ASL_WALK_CALLBACK DescendingCallback,ASL_WALK_CALLBACK AscendingCallback,void * Context)2193446Smrj AcpiDmWalkParseTree (
2203446Smrj ACPI_PARSE_OBJECT *Op,
2213446Smrj ASL_WALK_CALLBACK DescendingCallback,
2223446Smrj ASL_WALK_CALLBACK AscendingCallback,
2233446Smrj void *Context)
2243446Smrj {
2253446Smrj BOOLEAN NodePreviouslyVisited;
2263446Smrj ACPI_PARSE_OBJECT *StartOp = Op;
2273446Smrj ACPI_STATUS Status;
2283446Smrj ACPI_PARSE_OBJECT *Next;
2293446Smrj ACPI_OP_WALK_INFO *Info = Context;
2303446Smrj
2313446Smrj
2323446Smrj Info->Level = 0;
2333446Smrj NodePreviouslyVisited = FALSE;
2343446Smrj
2353446Smrj while (Op)
2363446Smrj {
2373446Smrj if (NodePreviouslyVisited)
2383446Smrj {
2393446Smrj if (AscendingCallback)
2403446Smrj {
2413446Smrj Status = AscendingCallback (Op, Info->Level, Context);
2423446Smrj if (ACPI_FAILURE (Status))
2433446Smrj {
2443446Smrj return;
2453446Smrj }
2463446Smrj }
2473446Smrj }
2483446Smrj else
2493446Smrj {
2503446Smrj /* Let the callback process the node */
2513446Smrj
2523446Smrj Status = DescendingCallback (Op, Info->Level, Context);
2533446Smrj if (ACPI_SUCCESS (Status))
2543446Smrj {
2553446Smrj /* Visit children first, once */
2563446Smrj
2573446Smrj Next = AcpiPsGetArg (Op, 0);
2583446Smrj if (Next)
2593446Smrj {
2603446Smrj Info->Level++;
2613446Smrj Op = Next;
2623446Smrj continue;
2633446Smrj }
2643446Smrj }
2653446Smrj else if (Status != AE_CTRL_DEPTH)
2663446Smrj {
2673446Smrj /* Exit immediately on any error */
2683446Smrj
2693446Smrj return;
2703446Smrj }
2713446Smrj }
2723446Smrj
2733446Smrj /* Terminate walk at start op */
2743446Smrj
2753446Smrj if (Op == StartOp)
2763446Smrj {
2773446Smrj break;
2783446Smrj }
2793446Smrj
2803446Smrj /* No more children, re-visit this node */
2813446Smrj
2823446Smrj if (!NodePreviouslyVisited)
2833446Smrj {
2843446Smrj NodePreviouslyVisited = TRUE;
2853446Smrj continue;
2863446Smrj }
2873446Smrj
2883446Smrj /* No more children, visit peers */
2893446Smrj
2903446Smrj if (Op->Common.Next)
2913446Smrj {
2923446Smrj Op = Op->Common.Next;
2933446Smrj NodePreviouslyVisited = FALSE;
2943446Smrj }
2953446Smrj else
2963446Smrj {
2973446Smrj /* No peers, re-visit parent */
2983446Smrj
2993446Smrj if (Info->Level != 0 )
3003446Smrj {
3013446Smrj Info->Level--;
3023446Smrj }
3033446Smrj
3043446Smrj Op = Op->Common.Parent;
3053446Smrj NodePreviouslyVisited = TRUE;
3063446Smrj }
3073446Smrj }
3083446Smrj
3093446Smrj /* If we get here, the walk completed with no errors */
3103446Smrj
3113446Smrj return;
3123446Smrj }
3133446Smrj
3143446Smrj
3153446Smrj /*******************************************************************************
3163446Smrj *
3173446Smrj * FUNCTION: AcpiDmBlockType
3183446Smrj *
3193446Smrj * PARAMETERS: Op - Object to be examined
3203446Smrj *
3213446Smrj * RETURN: BlockType - not a block, parens, braces, or even both.
3223446Smrj *
3233446Smrj * DESCRIPTION: Type of block for this op (parens or braces)
3243446Smrj *
3253446Smrj ******************************************************************************/
3263446Smrj
3273446Smrj static UINT32
AcpiDmBlockType(ACPI_PARSE_OBJECT * Op)3283446Smrj AcpiDmBlockType (
3293446Smrj ACPI_PARSE_OBJECT *Op)
3303446Smrj {
3313446Smrj const ACPI_OPCODE_INFO *OpInfo;
3323446Smrj
3333446Smrj
3343446Smrj if (!Op)
3353446Smrj {
3363446Smrj return (BLOCK_NONE);
3373446Smrj }
3383446Smrj
3393446Smrj switch (Op->Common.AmlOpcode)
3403446Smrj {
3413446Smrj case AML_ELSE_OP:
3423446Smrj
3433446Smrj return (BLOCK_BRACE);
3443446Smrj
3453446Smrj case AML_METHOD_OP:
3463446Smrj case AML_DEVICE_OP:
3473446Smrj case AML_SCOPE_OP:
3483446Smrj case AML_PROCESSOR_OP:
3493446Smrj case AML_POWER_RES_OP:
3503446Smrj case AML_THERMAL_ZONE_OP:
3513446Smrj case AML_IF_OP:
3523446Smrj case AML_WHILE_OP:
3533446Smrj case AML_FIELD_OP:
3543446Smrj case AML_INDEX_FIELD_OP:
3553446Smrj case AML_BANK_FIELD_OP:
3563446Smrj
3573446Smrj return (BLOCK_PAREN | BLOCK_BRACE);
3583446Smrj
3593446Smrj case AML_BUFFER_OP:
3603446Smrj
3613446Smrj if (Op->Common.DisasmOpcode == ACPI_DASM_UNICODE)
3623446Smrj {
3633446Smrj return (BLOCK_NONE);
3643446Smrj }
3653446Smrj
3663446Smrj /*lint -fallthrough */
3673446Smrj
3683446Smrj case AML_PACKAGE_OP:
3693446Smrj case AML_VAR_PACKAGE_OP:
3703446Smrj
3713446Smrj return (BLOCK_PAREN | BLOCK_BRACE);
3723446Smrj
3733446Smrj case AML_EVENT_OP:
3743446Smrj
3753446Smrj return (BLOCK_PAREN);
3763446Smrj
3773446Smrj default:
3783446Smrj
3793446Smrj OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
3803446Smrj if (OpInfo->Flags & AML_HAS_ARGS)
3813446Smrj {
3823446Smrj return (BLOCK_PAREN);
3833446Smrj }
3843446Smrj
3853446Smrj return (BLOCK_NONE);
3863446Smrj }
3873446Smrj }
3883446Smrj
3893446Smrj
3903446Smrj /*******************************************************************************
3913446Smrj *
3923446Smrj * FUNCTION: AcpiDmListType
3933446Smrj *
3943446Smrj * PARAMETERS: Op - Object to be examined
3953446Smrj *
3963446Smrj * RETURN: ListType - has commas or not.
3973446Smrj *
3983446Smrj * DESCRIPTION: Type of block for this op (parens or braces)
3993446Smrj *
4003446Smrj ******************************************************************************/
4013446Smrj
4023446Smrj UINT32
AcpiDmListType(ACPI_PARSE_OBJECT * Op)4033446Smrj AcpiDmListType (
4043446Smrj ACPI_PARSE_OBJECT *Op)
4053446Smrj {
4063446Smrj const ACPI_OPCODE_INFO *OpInfo;
4073446Smrj
4083446Smrj
4093446Smrj if (!Op)
4103446Smrj {
4113446Smrj return (BLOCK_NONE);
4123446Smrj }
4133446Smrj
4143446Smrj switch (Op->Common.AmlOpcode)
4153446Smrj {
4163446Smrj
4173446Smrj case AML_ELSE_OP:
4183446Smrj case AML_METHOD_OP:
4193446Smrj case AML_DEVICE_OP:
4203446Smrj case AML_SCOPE_OP:
4213446Smrj case AML_POWER_RES_OP:
4223446Smrj case AML_PROCESSOR_OP:
4233446Smrj case AML_THERMAL_ZONE_OP:
4243446Smrj case AML_IF_OP:
4253446Smrj case AML_WHILE_OP:
4263446Smrj case AML_FIELD_OP:
4273446Smrj case AML_INDEX_FIELD_OP:
4283446Smrj case AML_BANK_FIELD_OP:
4293446Smrj
4303446Smrj return (BLOCK_NONE);
4313446Smrj
4323446Smrj case AML_BUFFER_OP:
4333446Smrj case AML_PACKAGE_OP:
4343446Smrj case AML_VAR_PACKAGE_OP:
4353446Smrj
4363446Smrj return (BLOCK_COMMA_LIST);
4373446Smrj
4383446Smrj default:
4393446Smrj
4403446Smrj OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
4413446Smrj if (OpInfo->Flags & AML_HAS_ARGS)
4423446Smrj {
4433446Smrj return (BLOCK_COMMA_LIST);
4443446Smrj }
4453446Smrj
4463446Smrj return (BLOCK_NONE);
4473446Smrj }
4483446Smrj }
4493446Smrj
4503446Smrj
4513446Smrj /*******************************************************************************
4523446Smrj *
4533446Smrj * FUNCTION: AcpiDmDescendingOp
4543446Smrj *
4553446Smrj * PARAMETERS: ASL_WALK_CALLBACK
4563446Smrj *
4573446Smrj * RETURN: Status
4583446Smrj *
4593446Smrj * DESCRIPTION: First visitation of a parse object during tree descent.
4603446Smrj * Decode opcode name and begin parameter list(s), if any.
4613446Smrj *
4623446Smrj ******************************************************************************/
4633446Smrj
4643446Smrj static ACPI_STATUS
AcpiDmDescendingOp(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)4653446Smrj AcpiDmDescendingOp (
4663446Smrj ACPI_PARSE_OBJECT *Op,
4673446Smrj UINT32 Level,
4683446Smrj void *Context)
4693446Smrj {
4703446Smrj ACPI_OP_WALK_INFO *Info = Context;
4713446Smrj const ACPI_OPCODE_INFO *OpInfo;
4723446Smrj UINT32 Name;
4733446Smrj ACPI_PARSE_OBJECT *NextOp;
4743446Smrj
4753446Smrj
4763446Smrj if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
4773446Smrj {
4783446Smrj /* Ignore this op -- it was handled elsewhere */
4793446Smrj
4803446Smrj return (AE_CTRL_DEPTH);
4813446Smrj }
4823446Smrj
4833446Smrj /* Level 0 is at the Definition Block level */
4843446Smrj
4853446Smrj if (Level == 0)
4863446Smrj {
4873446Smrj /* In verbose mode, print the AML offset, opcode and depth count */
4883446Smrj
4893446Smrj if (Info->WalkState)
4903446Smrj {
4913446Smrj VERBOSE_PRINT ((DB_FULL_OP_INFO,
4923446Smrj (Info->WalkState->MethodNode ?
4933446Smrj Info->WalkState->MethodNode->Name.Ascii : " "),
4943446Smrj Op->Common.AmlOffset, (UINT32) Op->Common.AmlOpcode));
4953446Smrj }
4963446Smrj
4973446Smrj if (Op->Common.AmlOpcode == AML_SCOPE_OP)
4983446Smrj {
4993446Smrj /* This is the beginning of the Definition Block */
5003446Smrj
5013446Smrj AcpiOsPrintf ("{\n");
5023446Smrj
5033446Smrj /* Emit all External() declarations here */
5043446Smrj
505*11225SDana.Myers@Sun.COM AcpiDmEmitExternals ();
5063446Smrj return (AE_OK);
5073446Smrj }
5083446Smrj }
5093446Smrj else if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
5103446Smrj (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
5113446Smrj (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
5123446Smrj {
5133446Smrj /*
5143446Smrj * This is a first-level element of a term list,
5153446Smrj * indent a new line
5163446Smrj */
5173446Smrj AcpiDmIndent (Level);
5183446Smrj Info->LastLevel = Level;
5193446Smrj Info->Count = 0;
5203446Smrj }
5213446Smrj
5223446Smrj /*
5233446Smrj * This is an inexpensive mechanism to try and keep lines from getting
5243446Smrj * too long. When the limit is hit, start a new line at the previous
5253446Smrj * indent plus one. A better but more expensive mechanism would be to
5263446Smrj * keep track of the current column.
5273446Smrj */
5283446Smrj Info->Count++;
5293446Smrj if (Info->Count /*+Info->LastLevel*/ > 10)
5303446Smrj {
5313446Smrj Info->Count = 0;
5323446Smrj AcpiOsPrintf ("\n");
5333446Smrj AcpiDmIndent (Info->LastLevel + 1);
5343446Smrj }
5353446Smrj
5363446Smrj /* Print the opcode name */
5373446Smrj
5383446Smrj AcpiDmDisassembleOneOp (NULL, Info, Op);
5393446Smrj
5403446Smrj if (Op->Common.DisasmOpcode == ACPI_DASM_LNOT_PREFIX)
5413446Smrj {
5423446Smrj return (AE_OK);
5433446Smrj }
5443446Smrj
5453446Smrj if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
5463446Smrj (Op->Common.AmlOpcode == AML_RETURN_OP))
5473446Smrj {
5483446Smrj Info->Level--;
5493446Smrj }
5503446Smrj
5513446Smrj /* Start the opcode argument list if necessary */
5523446Smrj
5533446Smrj OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
5543446Smrj
5553446Smrj if ((OpInfo->Flags & AML_HAS_ARGS) ||
5563446Smrj (Op->Common.AmlOpcode == AML_EVENT_OP))
5573446Smrj {
5583446Smrj /* This opcode has an argument list */
5593446Smrj
5603446Smrj if (AcpiDmBlockType (Op) & BLOCK_PAREN)
5613446Smrj {
5623446Smrj AcpiOsPrintf (" (");
5633446Smrj }
5643446Smrj
5653446Smrj /* If this is a named opcode, print the associated name value */
5663446Smrj
5673446Smrj if (OpInfo->Flags & AML_NAMED)
5683446Smrj {
5693446Smrj switch (Op->Common.AmlOpcode)
5703446Smrj {
5713446Smrj case AML_ALIAS_OP:
5723446Smrj
5733446Smrj NextOp = AcpiPsGetDepthNext (NULL, Op);
5743446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
5753446Smrj AcpiDmNamestring (NextOp->Common.Value.Name);
5763446Smrj AcpiOsPrintf (", ");
5773446Smrj
5783446Smrj /*lint -fallthrough */
5793446Smrj
5803446Smrj default:
5813446Smrj
5823446Smrj Name = AcpiPsGetName (Op);
5833446Smrj if (Op->Named.Path)
5843446Smrj {
5853446Smrj AcpiDmNamestring ((char *) Op->Named.Path);
5863446Smrj }
5873446Smrj else
5883446Smrj {
5897851SDana.Myers@Sun.COM AcpiDmDumpName (Name);
5903446Smrj }
5913446Smrj
5923446Smrj if (Op->Common.AmlOpcode != AML_INT_NAMEDFIELD_OP)
5933446Smrj {
5943446Smrj if (AcpiGbl_DbOpt_verbose)
5953446Smrj {
5963446Smrj (void) AcpiPsDisplayObjectPathname (NULL, Op);
5973446Smrj }
5983446Smrj }
5993446Smrj break;
6003446Smrj }
6013446Smrj
6023446Smrj switch (Op->Common.AmlOpcode)
6033446Smrj {
6043446Smrj case AML_METHOD_OP:
6053446Smrj
6063446Smrj AcpiDmMethodFlags (Op);
6073446Smrj AcpiOsPrintf (")");
6083446Smrj break;
6093446Smrj
6103446Smrj
6113446Smrj case AML_NAME_OP:
6123446Smrj
6133446Smrj /* Check for _HID and related EISAID() */
6143446Smrj
6153446Smrj AcpiDmIsEisaId (Op);
6163446Smrj AcpiOsPrintf (", ");
6173446Smrj break;
6183446Smrj
6193446Smrj
6203446Smrj case AML_REGION_OP:
6213446Smrj
6223446Smrj AcpiDmRegionFlags (Op);
6233446Smrj break;
6243446Smrj
6253446Smrj
6263446Smrj case AML_POWER_RES_OP:
6273446Smrj
6283446Smrj /* Mark the next two Ops as part of the parameter list */
6293446Smrj
6303446Smrj AcpiOsPrintf (", ");
6313446Smrj NextOp = AcpiPsGetDepthNext (NULL, Op);
6323446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
6333446Smrj
6343446Smrj NextOp = NextOp->Common.Next;
6353446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
6363446Smrj return (AE_OK);
6373446Smrj
6383446Smrj
6393446Smrj case AML_PROCESSOR_OP:
6403446Smrj
6413446Smrj /* Mark the next three Ops as part of the parameter list */
6423446Smrj
6433446Smrj AcpiOsPrintf (", ");
6443446Smrj NextOp = AcpiPsGetDepthNext (NULL, Op);
6453446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
6463446Smrj
6473446Smrj NextOp = NextOp->Common.Next;
6483446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
6493446Smrj
6503446Smrj NextOp = NextOp->Common.Next;
6513446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
6523446Smrj return (AE_OK);
6533446Smrj
6543446Smrj
6553446Smrj case AML_MUTEX_OP:
6563446Smrj case AML_DATA_REGION_OP:
6573446Smrj
6583446Smrj AcpiOsPrintf (", ");
6593446Smrj return (AE_OK);
6603446Smrj
6613446Smrj
6623446Smrj case AML_EVENT_OP:
6633446Smrj case AML_ALIAS_OP:
6643446Smrj
6653446Smrj return (AE_OK);
6663446Smrj
6673446Smrj
6683446Smrj case AML_SCOPE_OP:
6693446Smrj case AML_DEVICE_OP:
6703446Smrj case AML_THERMAL_ZONE_OP:
6713446Smrj
6723446Smrj AcpiOsPrintf (")");
6733446Smrj break;
6743446Smrj
6753446Smrj
6763446Smrj default:
6773446Smrj
6783446Smrj AcpiOsPrintf ("*** Unhandled named opcode %X\n", Op->Common.AmlOpcode);
6793446Smrj break;
6803446Smrj }
6813446Smrj }
6823446Smrj
6833446Smrj else switch (Op->Common.AmlOpcode)
6843446Smrj {
6853446Smrj case AML_FIELD_OP:
6863446Smrj case AML_BANK_FIELD_OP:
6873446Smrj case AML_INDEX_FIELD_OP:
6883446Smrj
6893446Smrj Info->BitOffset = 0;
6903446Smrj
6913446Smrj /* Name of the parent OperationRegion */
6923446Smrj
6933446Smrj NextOp = AcpiPsGetDepthNext (NULL, Op);
6943446Smrj AcpiDmNamestring (NextOp->Common.Value.Name);
6953446Smrj AcpiOsPrintf (", ");
6963446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
6973446Smrj
6983446Smrj switch (Op->Common.AmlOpcode)
6993446Smrj {
7003446Smrj case AML_BANK_FIELD_OP:
7013446Smrj
7023446Smrj /* Namestring - Bank Name */
7033446Smrj
7043446Smrj NextOp = AcpiPsGetDepthNext (NULL, NextOp);
7053446Smrj AcpiDmNamestring (NextOp->Common.Value.Name);
7063446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
7073446Smrj AcpiOsPrintf (", ");
7083446Smrj
7093446Smrj /*
7103446Smrj * Bank Value. This is a TermArg in the middle of the parameter
7113446Smrj * list, must handle it here.
7123446Smrj *
7133446Smrj * Disassemble the TermArg parse tree. ACPI_PARSEOP_PARAMLIST
7143446Smrj * eliminates newline in the output.
7153446Smrj */
7163446Smrj NextOp = NextOp->Common.Next;
7173446Smrj
7183446Smrj Info->Flags = ACPI_PARSEOP_PARAMLIST;
7193446Smrj AcpiDmWalkParseTree (NextOp, AcpiDmDescendingOp, AcpiDmAscendingOp, Info);
7203446Smrj Info->Flags = 0;
7213446Smrj Info->Level = Level;
7223446Smrj
7233446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
7243446Smrj AcpiOsPrintf (", ");
7253446Smrj break;
7263446Smrj
7273446Smrj case AML_INDEX_FIELD_OP:
7283446Smrj
7293446Smrj /* Namestring - Data Name */
7303446Smrj
7313446Smrj NextOp = AcpiPsGetDepthNext (NULL, NextOp);
7323446Smrj AcpiDmNamestring (NextOp->Common.Value.Name);
7333446Smrj AcpiOsPrintf (", ");
7343446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
7353446Smrj break;
7363446Smrj
7373446Smrj default:
7383446Smrj
7393446Smrj break;
7403446Smrj }
7413446Smrj
7423446Smrj AcpiDmFieldFlags (NextOp);
7433446Smrj break;
7443446Smrj
7453446Smrj
7463446Smrj case AML_BUFFER_OP:
7473446Smrj
7483446Smrj /* The next op is the size parameter */
7493446Smrj
7503446Smrj NextOp = AcpiPsGetDepthNext (NULL, Op);
7513446Smrj if (!NextOp)
7523446Smrj {
7533446Smrj /* Single-step support */
7543446Smrj
7553446Smrj return (AE_OK);
7563446Smrj }
7573446Smrj
7583446Smrj if (Op->Common.DisasmOpcode == ACPI_DASM_RESOURCE)
7593446Smrj {
7603446Smrj /*
7613446Smrj * We have a resource list. Don't need to output
7623446Smrj * the buffer size Op. Open up a new block
7633446Smrj */
7643446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
7653446Smrj NextOp = NextOp->Common.Next;
7663446Smrj AcpiOsPrintf (")\n");
7673446Smrj AcpiDmIndent (Info->Level);
7683446Smrj AcpiOsPrintf ("{\n");
7693446Smrj return (AE_OK);
7703446Smrj }
7713446Smrj
7723446Smrj /* Normal Buffer, mark size as in the parameter list */
7733446Smrj
7743446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
7753446Smrj return (AE_OK);
7763446Smrj
7773446Smrj
7783446Smrj case AML_VAR_PACKAGE_OP:
7793446Smrj case AML_IF_OP:
7803446Smrj case AML_WHILE_OP:
7813446Smrj
7823446Smrj /* The next op is the size or predicate parameter */
7833446Smrj
7843446Smrj NextOp = AcpiPsGetDepthNext (NULL, Op);
7853446Smrj if (NextOp)
7863446Smrj {
7873446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
7883446Smrj }
7893446Smrj return (AE_OK);
7903446Smrj
7913446Smrj
7923446Smrj case AML_PACKAGE_OP:
7933446Smrj
7943446Smrj /* The next op is the size or predicate parameter */
7953446Smrj
7963446Smrj NextOp = AcpiPsGetDepthNext (NULL, Op);
7973446Smrj if (NextOp)
7983446Smrj {
7993446Smrj NextOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMLIST;
8003446Smrj }
8013446Smrj return (AE_OK);
8023446Smrj
8033446Smrj
8043446Smrj case AML_MATCH_OP:
8053446Smrj
8063446Smrj AcpiDmMatchOp (Op);
8073446Smrj break;
8083446Smrj
8093446Smrj
8103446Smrj default:
8113446Smrj
8123446Smrj break;
8133446Smrj }
8143446Smrj
8153446Smrj if (AcpiDmBlockType (Op) & BLOCK_BRACE)
8163446Smrj {
8173446Smrj AcpiOsPrintf ("\n");
8183446Smrj AcpiDmIndent (Level);
8193446Smrj AcpiOsPrintf ("{\n");
8203446Smrj }
8213446Smrj }
8223446Smrj
8233446Smrj return (AE_OK);
8243446Smrj }
8253446Smrj
8263446Smrj
8273446Smrj /*******************************************************************************
8283446Smrj *
8293446Smrj * FUNCTION: AcpiDmAscendingOp
8303446Smrj *
8313446Smrj * PARAMETERS: ASL_WALK_CALLBACK
8323446Smrj *
8333446Smrj * RETURN: Status
8343446Smrj *
8353446Smrj * DESCRIPTION: Second visitation of a parse object, during ascent of parse
8363446Smrj * tree. Close out any parameter lists and complete the opcode.
8373446Smrj *
8383446Smrj ******************************************************************************/
8393446Smrj
8403446Smrj static ACPI_STATUS
AcpiDmAscendingOp(ACPI_PARSE_OBJECT * Op,UINT32 Level,void * Context)8413446Smrj AcpiDmAscendingOp (
8423446Smrj ACPI_PARSE_OBJECT *Op,
8433446Smrj UINT32 Level,
8443446Smrj void *Context)
8453446Smrj {
8463446Smrj ACPI_OP_WALK_INFO *Info = Context;
8473446Smrj
8483446Smrj
8493446Smrj if (Op->Common.DisasmFlags & ACPI_PARSEOP_IGNORE)
8503446Smrj {
8513446Smrj /* Ignore this op -- it was handled elsewhere */
8523446Smrj
8533446Smrj return (AE_OK);
8543446Smrj }
8553446Smrj
8563446Smrj if ((Level == 0) && (Op->Common.AmlOpcode == AML_SCOPE_OP))
8573446Smrj {
8583446Smrj /* Indicates the end of the current descriptor block (table) */
8593446Smrj
8603446Smrj AcpiOsPrintf ("}\n\n");
8613446Smrj return (AE_OK);
8623446Smrj }
8633446Smrj
8643446Smrj switch (AcpiDmBlockType (Op))
8653446Smrj {
8663446Smrj case BLOCK_PAREN:
8673446Smrj
8683446Smrj /* Completed an op that has arguments, add closing paren */
8693446Smrj
8703446Smrj AcpiOsPrintf (")");
8713446Smrj
8723446Smrj /* Could be a nested operator, check if comma required */
8733446Smrj
8743446Smrj if (!AcpiDmCommaIfListMember (Op))
8753446Smrj {
8763446Smrj if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
8773446Smrj (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
8783446Smrj (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
8793446Smrj {
8803446Smrj /*
8813446Smrj * This is a first-level element of a term list
8823446Smrj * start a new line
8833446Smrj */
8843446Smrj if (!(Info->Flags & ACPI_PARSEOP_PARAMLIST))
8853446Smrj {
8863446Smrj AcpiOsPrintf ("\n");
8873446Smrj }
8883446Smrj }
8893446Smrj }
8903446Smrj break;
8913446Smrj
8923446Smrj
8933446Smrj case BLOCK_BRACE:
8943446Smrj case (BLOCK_BRACE | BLOCK_PAREN):
8953446Smrj
8963446Smrj /* Completed an op that has a term list, add closing brace */
8973446Smrj
8983446Smrj if (Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST)
8993446Smrj {
9003446Smrj AcpiOsPrintf ("}");
9013446Smrj }
9023446Smrj else
9033446Smrj {
9043446Smrj AcpiDmIndent (Level);
9053446Smrj AcpiOsPrintf ("}");
9063446Smrj }
9073446Smrj
9083446Smrj AcpiDmCommaIfListMember (Op);
9093446Smrj
9103446Smrj if (AcpiDmBlockType (Op->Common.Parent) != BLOCK_PAREN)
9113446Smrj {
9123446Smrj AcpiOsPrintf ("\n");
9133446Smrj if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_EMPTY_TERMLIST))
9143446Smrj {
9153446Smrj if ((Op->Common.AmlOpcode == AML_IF_OP) &&
9163446Smrj (Op->Common.Next) &&
9173446Smrj (Op->Common.Next->Common.AmlOpcode == AML_ELSE_OP))
9183446Smrj {
9193446Smrj break;
9203446Smrj }
9213446Smrj
9223446Smrj if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
9233446Smrj (!Op->Common.Next))
9243446Smrj {
9253446Smrj break;
9263446Smrj }
9273446Smrj AcpiOsPrintf ("\n");
9283446Smrj }
9293446Smrj }
9303446Smrj break;
9313446Smrj
9323446Smrj
9333446Smrj case BLOCK_NONE:
9343446Smrj default:
9353446Smrj
9363446Smrj /* Could be a nested operator, check if comma required */
9373446Smrj
9383446Smrj if (!AcpiDmCommaIfListMember (Op))
9393446Smrj {
9403446Smrj if ((AcpiDmBlockType (Op->Common.Parent) & BLOCK_BRACE) &&
9413446Smrj (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)) &&
9423446Smrj (Op->Common.AmlOpcode != AML_INT_BYTELIST_OP))
9433446Smrj {
9443446Smrj /*
9453446Smrj * This is a first-level element of a term list
9463446Smrj * start a new line
9473446Smrj */
9483446Smrj AcpiOsPrintf ("\n");
9493446Smrj }
9503446Smrj }
9513446Smrj else if (Op->Common.Parent)
9523446Smrj {
9533446Smrj switch (Op->Common.Parent->Common.AmlOpcode)
9543446Smrj {
9553446Smrj case AML_PACKAGE_OP:
9563446Smrj case AML_VAR_PACKAGE_OP:
9573446Smrj
9583446Smrj if (!(Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
9593446Smrj {
9603446Smrj AcpiOsPrintf ("\n");
9613446Smrj }
9623446Smrj break;
9633446Smrj
9643446Smrj default:
9653446Smrj
9663446Smrj break;
9673446Smrj }
9683446Smrj }
9693446Smrj break;
9703446Smrj }
9713446Smrj
9723446Smrj if (Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)
9733446Smrj {
9743446Smrj if ((Op->Common.Next) &&
9753446Smrj (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
9763446Smrj {
9773446Smrj return (AE_OK);
9783446Smrj }
9793446Smrj
9803446Smrj /*
9813446Smrj * Just completed a parameter node for something like "Buffer (param)".
9823446Smrj * Close the paren and open up the term list block with a brace
9833446Smrj */
9843446Smrj if (Op->Common.Next)
9853446Smrj {
9863446Smrj AcpiOsPrintf (")\n");
9873446Smrj AcpiDmIndent (Level - 1);
9883446Smrj AcpiOsPrintf ("{\n");
9893446Smrj }
9903446Smrj else
9913446Smrj {
9923446Smrj Op->Common.Parent->Common.DisasmFlags |=
9933446Smrj ACPI_PARSEOP_EMPTY_TERMLIST;
9943446Smrj AcpiOsPrintf (") {");
9953446Smrj }
9963446Smrj }
9973446Smrj
9983446Smrj if ((Op->Common.AmlOpcode == AML_NAME_OP) ||
9993446Smrj (Op->Common.AmlOpcode == AML_RETURN_OP))
10003446Smrj {
10013446Smrj Info->Level++;
10023446Smrj }
10033446Smrj return (AE_OK);
10043446Smrj }
10053446Smrj
10063446Smrj
10073446Smrj #endif /* ACPI_DISASSEMBLER */
1008