summaryrefslogtreecommitdiffstats
path: root/sys/contrib/dev/acpica/components/disassembler/dmopcode.c
diff options
context:
space:
mode:
authorjkim <jkim@FreeBSD.org>2017-03-30 20:18:34 +0000
committerjkim <jkim@FreeBSD.org>2017-03-30 20:18:34 +0000
commit16f86484f4de9cf680d56e983d44216d7e152958 (patch)
tree73bd4837afc7b87c56534ea3430d7b67150c3c09 /sys/contrib/dev/acpica/components/disassembler/dmopcode.c
parent0c8318dc914dfce6474c5c02ac37d5e0601cbc39 (diff)
downloadFreeBSD-src-16f86484f4de9cf680d56e983d44216d7e152958.zip
FreeBSD-src-16f86484f4de9cf680d56e983d44216d7e152958.tar.gz
MFC: r306686, r308953, r311462, r311529, r312438, r314611
- Merge ACPICA 20170303. - Remove '-vd' option to make iasl(8) reproducible. Relnotes: yes
Diffstat (limited to 'sys/contrib/dev/acpica/components/disassembler/dmopcode.c')
-rw-r--r--sys/contrib/dev/acpica/components/disassembler/dmopcode.c724
1 files changed, 690 insertions, 34 deletions
diff --git a/sys/contrib/dev/acpica/components/disassembler/dmopcode.c b/sys/contrib/dev/acpica/components/disassembler/dmopcode.c
index 2ca1c85..587c5c0 100644
--- a/sys/contrib/dev/acpica/components/disassembler/dmopcode.c
+++ b/sys/contrib/dev/acpica/components/disassembler/dmopcode.c
@@ -4,10 +4,118 @@
*
******************************************************************************/
-/*
- * Copyright (C) 2000 - 2016, Intel Corp.
+/******************************************************************************
+ *
+ * 1. Copyright Notice
+ *
+ * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
* All rights reserved.
*
+ * 2. License
+ *
+ * 2.1. This is your license from Intel Corp. under its intellectual property
+ * rights. You may have additional license terms from the party that provided
+ * you this software, covering your right to use that party's intellectual
+ * property rights.
+ *
+ * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
+ * copy of the source code appearing in this file ("Covered Code") an
+ * irrevocable, perpetual, worldwide license under Intel's copyrights in the
+ * base code distributed originally by Intel ("Original Intel Code") to copy,
+ * make derivatives, distribute, use and display any portion of the Covered
+ * Code in any form, with the right to sublicense such rights; and
+ *
+ * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
+ * license (with the right to sublicense), under only those claims of Intel
+ * patents that are infringed by the Original Intel Code, to make, use, sell,
+ * offer to sell, and import the Covered Code and derivative works thereof
+ * solely to the minimum extent necessary to exercise the above copyright
+ * license, and in no event shall the patent license extend to any additions
+ * to or modifications of the Original Intel Code. No other license or right
+ * is granted directly or by implication, estoppel or otherwise;
+ *
+ * The above copyright and patent license is granted only if the following
+ * conditions are met:
+ *
+ * 3. Conditions
+ *
+ * 3.1. Redistribution of Source with Rights to Further Distribute Source.
+ * Redistribution of source code of any substantial portion of the Covered
+ * Code or modification with rights to further distribute source must include
+ * the above Copyright Notice, the above License, this list of Conditions,
+ * and the following Disclaimer and Export Compliance provision. In addition,
+ * Licensee must cause all Covered Code to which Licensee contributes to
+ * contain a file documenting the changes Licensee made to create that Covered
+ * Code and the date of any change. Licensee must include in that file the
+ * documentation of any changes made by any predecessor Licensee. Licensee
+ * must include a prominent statement that the modification is derived,
+ * directly or indirectly, from Original Intel Code.
+ *
+ * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
+ * Redistribution of source code of any substantial portion of the Covered
+ * Code or modification without rights to further distribute source must
+ * include the following Disclaimer and Export Compliance provision in the
+ * documentation and/or other materials provided with distribution. In
+ * addition, Licensee may not authorize further sublicense of source of any
+ * portion of the Covered Code, and must include terms to the effect that the
+ * license from Licensee to its licensee is limited to the intellectual
+ * property embodied in the software Licensee provides to its licensee, and
+ * not to intellectual property embodied in modifications its licensee may
+ * make.
+ *
+ * 3.3. Redistribution of Executable. Redistribution in executable form of any
+ * substantial portion of the Covered Code or modification must reproduce the
+ * above Copyright Notice, and the following Disclaimer and Export Compliance
+ * provision in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3.4. Intel retains all right, title, and interest in and to the Original
+ * Intel Code.
+ *
+ * 3.5. Neither the name Intel nor any other trademark owned or controlled by
+ * Intel shall be used in advertising or otherwise to promote the sale, use or
+ * other dealings in products derived from or relating to the Covered Code
+ * without prior written authorization from Intel.
+ *
+ * 4. Disclaimer and Export Compliance
+ *
+ * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
+ * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
+ * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
+ * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
+ * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
+ * PARTICULAR PURPOSE.
+ *
+ * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
+ * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
+ * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
+ * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
+ * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
+ * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
+ * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
+ * LIMITED REMEDY.
+ *
+ * 4.3. Licensee shall not export, either directly or indirectly, any of this
+ * software or system incorporating such software without first obtaining any
+ * required license or other approval from the U. S. Department of Commerce or
+ * any other agency or department of the United States Government. In the
+ * event Licensee exports any such software from the United States or
+ * re-exports any such software from a foreign destination, Licensee shall
+ * ensure that the distribution and export/re-export of the software is in
+ * compliance with all laws, regulations, orders, or other restrictions of the
+ * U.S. Export Administration Regulations. Licensee agrees that neither it nor
+ * any of its subsidiaries will export/re-export any technical data, process,
+ * software, or service, directly or indirectly, to any country for which the
+ * United States government or any agency thereof requires an export license,
+ * other governmental approval, or letter of assurance, without first obtaining
+ * such license, approval or letter.
+ *
+ *****************************************************************************
+ *
+ * Alternatively, you may choose to be licensed under the terms of the
+ * following license:
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -23,23 +131,23 @@
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
- * Alternatively, this software may be distributed under the terms of the
- * GNU General Public License ("GPL") version 2 as published by the Free
- * Software Foundation.
- *
- * NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- */
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Alternatively, you may choose to be licensed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ *****************************************************************************/
#include <contrib/dev/acpica/include/acpi.h>
#include <contrib/dev/acpica/include/accommon.h>
@@ -48,6 +156,7 @@
#include <contrib/dev/acpica/include/acinterp.h>
#include <contrib/dev/acpica/include/acnamesp.h>
#include <contrib/dev/acpica/include/acdebug.h>
+#include <contrib/dev/acpica/include/acconvert.h>
#define _COMPONENT ACPI_CA_DEBUGGER
@@ -64,6 +173,18 @@ static void
AcpiDmConvertToElseIf (
ACPI_PARSE_OBJECT *Op);
+static void
+AcpiDmPromoteSubtree (
+ ACPI_PARSE_OBJECT *StartOp);
+
+static BOOLEAN
+AcpiDmIsSwitchBlock (
+ ACPI_PARSE_OBJECT *Op,
+ char *Temp);
+
+static BOOLEAN
+AcpiDmIsCaseBlock (
+ ACPI_PARSE_OBJECT *Op);
/*******************************************************************************
*
@@ -430,6 +551,10 @@ AcpiDmFieldPredefinedDescription (
ACPI_CAST_PTR (char, Info->Description));
}
+ /* AML buffer (String) was allocated in AcpiGetTagPathname */
+
+ ACPI_FREE (IndexOp->Common.Value.String);
+
#endif
return;
}
@@ -705,15 +830,15 @@ AcpiDmDisassembleOneOp (
{
switch (Op->Common.AmlOpcode)
{
- case AML_LEQUAL_OP:
+ case AML_LOGICAL_EQUAL_OP:
AcpiOsPrintf ("LNotEqual");
break;
- case AML_LGREATER_OP:
+ case AML_LOGICAL_GREATER_OP:
AcpiOsPrintf ("LLessEqual");
break;
- case AML_LLESS_OP:
+ case AML_LOGICAL_LESS_OP:
AcpiOsPrintf ("LGreaterEqual");
break;
@@ -736,12 +861,12 @@ AcpiDmDisassembleOneOp (
switch (Op->Common.AmlOpcode)
{
- case AML_LNOT_OP:
+ case AML_LOGICAL_NOT_OP:
Child = Op->Common.Value.Arg;
- if ((Child->Common.AmlOpcode == AML_LEQUAL_OP) ||
- (Child->Common.AmlOpcode == AML_LGREATER_OP) ||
- (Child->Common.AmlOpcode == AML_LLESS_OP))
+ if ((Child->Common.AmlOpcode == AML_LOGICAL_EQUAL_OP) ||
+ (Child->Common.AmlOpcode == AML_LOGICAL_GREATER_OP) ||
+ (Child->Common.AmlOpcode == AML_LOGICAL_LESS_OP))
{
Child->Common.DisasmOpcode = ACPI_DASM_LNOT_SUFFIX;
Op->Common.DisasmOpcode = ACPI_DASM_LNOT_PREFIX;
@@ -870,8 +995,12 @@ AcpiDmDisassembleOneOp (
case AML_INT_NAMEDFIELD_OP:
Length = AcpiDmDumpName (Op->Named.Name);
- AcpiOsPrintf (",%*.s %u", (unsigned) (5 - Length), " ",
+
+ AcpiOsPrintf (",");
+ ASL_CV_PRINT_ONE_COMMENT (Op, AML_NAMECOMMENT, NULL, 0);
+ AcpiOsPrintf ("%*.s %u", (unsigned) (5 - Length), " ",
(UINT32) Op->Common.Value.Integer);
+
AcpiDmCommaIfFieldMember (Op);
Info->BitOffset += (UINT32) Op->Common.Value.Integer;
@@ -912,6 +1041,7 @@ AcpiDmDisassembleOneOp (
AcpiOsPrintf (")");
AcpiDmCommaIfFieldMember (Op);
+ ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
break;
case AML_INT_CONNECTION_OP:
@@ -945,6 +1075,8 @@ AcpiDmDisassembleOneOp (
AcpiOsPrintf (")");
AcpiDmCommaIfFieldMember (Op);
+ ASL_CV_PRINT_ONE_COMMENT (Op, AML_COMMENT_END_NODE, NULL, 0);
+ ASL_CV_PRINT_ONE_COMMENT (Op, AMLCOMMENT_INLINE, NULL, 0);
AcpiOsPrintf ("\n");
Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE; /* for now, ignore in AcpiDmAscendingOp */
@@ -964,6 +1096,28 @@ AcpiDmDisassembleOneOp (
AcpiDmNamestring (Op->Common.Value.Name);
break;
+ case AML_WHILE_OP:
+
+ if (Op->Common.DisasmOpcode == ACPI_DASM_SWITCH)
+ {
+ AcpiOsPrintf ("%s", "Switch");
+ break;
+ }
+
+ AcpiOsPrintf ("%s", OpInfo->Name);
+ break;
+
+ case AML_IF_OP:
+
+ if (Op->Common.DisasmOpcode == ACPI_DASM_CASE)
+ {
+ AcpiOsPrintf ("%s", "Case");
+ break;
+ }
+
+ AcpiOsPrintf ("%s", OpInfo->Name);
+ break;
+
case AML_ELSE_OP:
AcpiDmConvertToElseIf (Op);
@@ -973,15 +1127,13 @@ AcpiDmDisassembleOneOp (
if (AcpiGbl_DmEmitExternalOpcodes)
{
- AcpiOsPrintf ("/* Opcode 0x15 */ ");
-
- /* Fallthrough */
- }
- else
- {
+ AcpiDmEmitExternal (AcpiPsGetArg(Op, 0),
+ AcpiPsGetArg(Op, 1));
break;
}
+ break;
+
default:
/* Just get the opcode name and print it */
@@ -1067,19 +1219,64 @@ AcpiDmConvertToElseIf (
* be the only blocks under the original Else.
*/
IfOp = OriginalElseOp->Common.Value.Arg;
+
if (!IfOp ||
(IfOp->Common.AmlOpcode != AML_IF_OP) ||
(IfOp->Asl.Next && (IfOp->Asl.Next->Common.AmlOpcode != AML_ELSE_OP)))
{
- /* Not an Else..If sequence, cannot convert to ElseIf */
+ /* Not a proper Else..If sequence, cannot convert to ElseIf */
+
+ if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_DEFAULT)
+ {
+ AcpiOsPrintf ("%s", "Default");
+ return;
+ }
AcpiOsPrintf ("%s", "Else");
return;
}
- /* Emit ElseIf, mark the IF as now an ELSEIF */
+ /* Cannot have anything following the If...Else block */
+
+ ElseOp = IfOp->Common.Next;
+ if (ElseOp && ElseOp->Common.Next)
+ {
+ if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_DEFAULT)
+ {
+ AcpiOsPrintf ("%s", "Default");
+ return;
+ }
+
+ AcpiOsPrintf ("%s", "Else");
+ return;
+ }
+
+ if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_DEFAULT)
+ {
+ /*
+ * There is an ElseIf but in this case the Else is actually
+ * a Default block for a Switch/Case statement. No conversion.
+ */
+ AcpiOsPrintf ("%s", "Default");
+ return;
+ }
+
+ if (OriginalElseOp->Common.DisasmOpcode == ACPI_DASM_CASE)
+ {
+ /*
+ * This ElseIf is actually a Case block for a Switch/Case
+ * statement. Print Case but do not return so that we can
+ * promote the subtree and keep the indentation level.
+ */
+ AcpiOsPrintf ("%s", "Case");
+ }
+ else
+ {
+ /* Emit ElseIf, mark the IF as now an ELSEIF */
+
+ AcpiOsPrintf ("%s", "ElseIf");
+ }
- AcpiOsPrintf ("%s", "ElseIf");
IfOp->Common.DisasmFlags |= ACPI_PARSEOP_ELSEIF;
/* The IF parent will now be the same as the original ELSE parent */
@@ -1100,7 +1297,10 @@ AcpiDmConvertToElseIf (
/* If an ELSE matches the IF, promote it also */
ElseOp->Common.Parent = OriginalElseOp->Common.Parent;
- ElseOp->Common.Next = OriginalElseOp->Common.Next;
+
+ /* Promote the entire block under the ElseIf (All Next OPs) */
+
+ AcpiDmPromoteSubtree (OriginalElseOp);
}
else
{
@@ -1122,3 +1322,459 @@ AcpiDmConvertToElseIf (
OriginalElseOp->Common.Next = IfOp;
}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiDmPromoteSubtree
+ *
+ * PARAMETERS: StartOpOp - Original parent of the entire subtree
+ *
+ * RETURN: None
+ *
+ * DESCRIPTION: Promote an entire parse subtree up one level.
+ *
+ ******************************************************************************/
+
+static void
+AcpiDmPromoteSubtree (
+ ACPI_PARSE_OBJECT *StartOp)
+{
+ ACPI_PARSE_OBJECT *Op;
+ ACPI_PARSE_OBJECT *ParentOp;
+
+
+ /* New parent for subtree elements */
+
+ ParentOp = StartOp->Common.Parent;
+
+ /* First child starts the subtree */
+
+ Op = StartOp->Common.Value.Arg;
+
+ /* Walk the top-level elements of the subtree */
+
+ while (Op)
+ {
+ Op->Common.Parent = ParentOp;
+ if (!Op->Common.Next)
+ {
+ /* Last Op in list, update its next field */
+
+ Op->Common.Next = StartOp->Common.Next;
+ break;
+ }
+ Op = Op->Common.Next;
+ }
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiDmIsTempName
+ *
+ * PARAMETERS: Op - Object to be examined
+ *
+ * RETURN: TRUE if object is a temporary (_T_x) name for a matching While
+ * loop that can be converted to a Switch.
+ *
+ * DESCRIPTION: _T_X objects are only used for Switch statements. If a temporary
+ * name exists, search the siblings for a matching While (One) loop
+ * that can be converted to a Switch. Return TRUE if a match was
+ * found, FALSE otherwise.
+ *
+ ******************************************************************************/
+
+BOOLEAN
+AcpiDmIsTempName (
+ ACPI_PARSE_OBJECT *Op)
+{
+ ACPI_PARSE_OBJECT *CurrentOp;
+ char *Temp;
+
+ if (Op->Common.AmlOpcode != AML_NAME_OP)
+ {
+ return (FALSE);
+ }
+
+ Temp = (char *)(Op->Common.Aml);
+ ++Temp;
+
+ if (strncmp(Temp, "_T_", 3))
+ {
+ return (FALSE);
+ }
+
+ CurrentOp = Op->Common.Next;
+ while (CurrentOp)
+ {
+ if (CurrentOp->Common.AmlOpcode == AML_WHILE_OP &&
+ AcpiDmIsSwitchBlock(CurrentOp, Temp))
+ {
+ Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
+ CurrentOp->Common.DisasmOpcode = ACPI_DASM_SWITCH;
+
+ return (TRUE);
+ }
+ CurrentOp = CurrentOp->Common.Next;
+ }
+
+ return (FALSE);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiDmIsSwitchBlock
+ *
+ * PARAMETERS: Op - While Object
+ *
+ * RETURN: TRUE if While block can be converted to a Switch/Case block
+ *
+ * DESCRIPTION: Determines if While block is a Switch/Case statement. Modifies
+ * parse tree to allow for Switch/Case disassembly during walk.
+ *
+ * EXAMPLE: Example of parse tree to be converted
+ *
+ * While
+ * One
+ * Store
+ * ByteConst
+ * -NamePath-
+ * If
+ * LEqual
+ * -NamePath-
+ * Zero
+ * Return
+ * One
+ * Else
+ * Return
+ * WordConst
+ * Break
+ *
+ ******************************************************************************/
+
+static BOOLEAN
+AcpiDmIsSwitchBlock (
+ ACPI_PARSE_OBJECT *Op,
+ char *Temp)
+{
+ ACPI_PARSE_OBJECT *OneOp;
+ ACPI_PARSE_OBJECT *StoreOp;
+ ACPI_PARSE_OBJECT *NamePathOp;
+ ACPI_PARSE_OBJECT *PredicateOp;
+ ACPI_PARSE_OBJECT *CurrentOp;
+ ACPI_PARSE_OBJECT *TempOp;
+
+ /* Check for One Op Predicate */
+
+ OneOp = AcpiPsGetArg (Op, 0);
+ if (!OneOp || (OneOp->Common.AmlOpcode != AML_ONE_OP))
+ {
+ return (FALSE);
+ }
+
+ /* Check for Store Op */
+
+ StoreOp = OneOp->Common.Next;
+ if (!StoreOp || (StoreOp->Common.AmlOpcode != AML_STORE_OP))
+ {
+ return (FALSE);
+ }
+
+ /* Check for Name Op with _T_ string */
+
+ NamePathOp = AcpiPsGetArg (StoreOp, 1);
+ if (!NamePathOp || (NamePathOp->Common.AmlOpcode != AML_INT_NAMEPATH_OP))
+ {
+ return (FALSE);
+ }
+
+ if (strncmp((char *)(NamePathOp->Common.Aml), Temp, 4))
+ {
+ return (FALSE);
+ }
+
+ /* This is a Switch/Case control block */
+
+ /* Ignore the One Op Predicate */
+
+ OneOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
+
+ /* Ignore the Store Op, but not the children */
+
+ StoreOp->Common.DisasmOpcode = ACPI_DASM_IGNORE_SINGLE;
+
+ /*
+ * First arg of Store Op is the Switch condition.
+ * Mark it as a Switch predicate and as a parameter list for paren
+ * closing and correct indentation.
+ */
+ PredicateOp = AcpiPsGetArg (StoreOp, 0);
+ PredicateOp->Common.DisasmOpcode = ACPI_DASM_SWITCH_PREDICATE;
+ PredicateOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
+
+ /* Ignore the Name Op */
+
+ NamePathOp->Common.DisasmFlags = ACPI_PARSEOP_IGNORE;
+
+ /* Remaining opcodes are the Case statements (If/ElseIf's) */
+
+ CurrentOp = StoreOp->Common.Next;
+ while (AcpiDmIsCaseBlock (CurrentOp))
+ {
+ /* Block is a Case structure */
+
+ if (CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
+ {
+ /* ElseIf */
+
+ CurrentOp->Common.DisasmOpcode = ACPI_DASM_CASE;
+ CurrentOp = AcpiPsGetArg (CurrentOp, 0);
+ }
+
+ /* If */
+
+ CurrentOp->Common.DisasmOpcode = ACPI_DASM_CASE;
+
+ /*
+ * Mark the parse tree for Case disassembly. There are two
+ * types of Case statements. The first type of statement begins with
+ * an LEqual. The second starts with an LNot and uses a Match statement
+ * on a Package of constants.
+ */
+ TempOp = AcpiPsGetArg (CurrentOp, 0);
+ switch (TempOp->Common.AmlOpcode)
+ {
+ case (AML_LOGICAL_EQUAL_OP):
+
+ /* Ignore just the LEqual Op */
+
+ TempOp->Common.DisasmOpcode = ACPI_DASM_IGNORE_SINGLE;
+
+ /* Ignore the NamePath Op */
+
+ TempOp = AcpiPsGetArg (TempOp, 0);
+ TempOp->Common.DisasmFlags = ACPI_PARSEOP_IGNORE;
+
+ /*
+ * Second arg of LEqual will be the Case predicate.
+ * Mark it as a predicate and also as a parameter list for paren
+ * closing and correct indentation.
+ */
+ PredicateOp = TempOp->Common.Next;
+ PredicateOp->Common.DisasmOpcode = ACPI_DASM_SWITCH_PREDICATE;
+ PredicateOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
+
+ break;
+
+ case (AML_LOGICAL_NOT_OP):
+
+ /*
+ * The Package will be the predicate of the Case statement.
+ * It's under:
+ * LNOT
+ * LEQUAL
+ * MATCH
+ * PACKAGE
+ */
+
+ /* Get the LEqual Op from LNot */
+
+ TempOp = AcpiPsGetArg (TempOp, 0);
+
+ /* Get the Match Op from LEqual */
+
+ TempOp = AcpiPsGetArg (TempOp, 0);
+
+ /* Get the Package Op from Match */
+
+ PredicateOp = AcpiPsGetArg (TempOp, 0);
+
+ /* Mark as parameter list for paren closing */
+
+ PredicateOp->Common.DisasmFlags |= ACPI_PARSEOP_PARAMETER_LIST;
+
+ /*
+ * The Package list would be too deeply indented if we
+ * chose to simply ignore the all the parent opcodes, so
+ * we rearrange the parse tree instead.
+ */
+
+ /*
+ * Save the second arg of the If/Else Op which is the
+ * block code of code for this Case statement.
+ */
+ TempOp = AcpiPsGetArg (CurrentOp, 1);
+
+ /*
+ * Move the Package Op to the child (predicate) of the
+ * Case statement.
+ */
+ CurrentOp->Common.Value.Arg = PredicateOp;
+ PredicateOp->Common.Parent = CurrentOp;
+
+ /* Add the block code */
+
+ PredicateOp->Common.Next = TempOp;
+
+ break;
+
+ default:
+
+ /* Should never get here */
+
+ break;
+ }
+
+ /* Advance to next Case block */
+
+ CurrentOp = CurrentOp->Common.Next;
+ }
+
+ /* If CurrentOp is now an Else, then this is a Default block */
+
+ if (CurrentOp && CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
+ {
+ CurrentOp->Common.DisasmOpcode = ACPI_DASM_DEFAULT;
+ }
+
+ /*
+ * From the first If advance to the Break op. It's possible to
+ * have an Else (Default) op here when there is only one Case
+ * statement, so check for it.
+ */
+ CurrentOp = StoreOp->Common.Next->Common.Next;
+ if (CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
+ {
+ CurrentOp = CurrentOp->Common.Next;
+ }
+
+ /* Ignore the Break Op */
+
+ CurrentOp->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
+
+ return (TRUE);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION: AcpiDmIsCaseBlock
+ *
+ * PARAMETERS: Op - Object to test
+ *
+ * RETURN: TRUE if Object is beginning of a Case block.
+ *
+ * DESCRIPTION: Determines if an Object is the beginning of a Case block for a
+ * Switch/Case statement. Parse tree must be one of the following
+ * forms:
+ *
+ * Else (Optional)
+ * If
+ * LEqual
+ * -NamePath- _T_x
+ *
+ * Else (Optional)
+ * If
+ * LNot
+ * LEqual
+ * Match
+ * Package
+ * ByteConst
+ * -NamePath- _T_x
+ *
+ ******************************************************************************/
+
+static BOOLEAN
+AcpiDmIsCaseBlock (
+ ACPI_PARSE_OBJECT *Op)
+{
+ ACPI_PARSE_OBJECT *CurrentOp;
+
+ if (!Op)
+ {
+ return (FALSE);
+ }
+
+ /* Look for an If or ElseIf */
+
+ CurrentOp = Op;
+ if (CurrentOp->Common.AmlOpcode == AML_ELSE_OP)
+ {
+ CurrentOp = AcpiPsGetArg (CurrentOp, 0);
+ if (!CurrentOp)
+ {
+ return (FALSE);
+ }
+ }
+
+ if (!CurrentOp || CurrentOp->Common.AmlOpcode != AML_IF_OP)
+ {
+ return (FALSE);
+ }
+
+ /* Child must be LEqual or LNot */
+
+ CurrentOp = AcpiPsGetArg (CurrentOp, 0);
+ if (!CurrentOp)
+ {
+ return (FALSE);
+ }
+
+ switch (CurrentOp->Common.AmlOpcode)
+ {
+ case (AML_LOGICAL_EQUAL_OP):
+
+ /* Next child must be NamePath with string _T_ */
+
+ CurrentOp = AcpiPsGetArg (CurrentOp, 0);
+ if (!CurrentOp || !CurrentOp->Common.Value.Name ||
+ strncmp(CurrentOp->Common.Value.Name, "_T_", 3))
+ {
+ return (FALSE);
+ }
+
+ break;
+
+ case (AML_LOGICAL_NOT_OP):
+
+ /* Child of LNot must be LEqual op */
+
+ CurrentOp = AcpiPsGetArg (CurrentOp, 0);
+ if (!CurrentOp || (CurrentOp->Common.AmlOpcode != AML_LOGICAL_EQUAL_OP))
+ {
+ return (FALSE);
+ }
+
+ /* Child of LNot must be Match op */
+
+ CurrentOp = AcpiPsGetArg (CurrentOp, 0);
+ if (!CurrentOp || (CurrentOp->Common.AmlOpcode != AML_MATCH_OP))
+ {
+ return (FALSE);
+ }
+
+ /* First child of Match must be Package op */
+
+ CurrentOp = AcpiPsGetArg (CurrentOp, 0);
+ if (!CurrentOp || (CurrentOp->Common.AmlOpcode != AML_PACKAGE_OP))
+ {
+ return (FALSE);
+ }
+
+ /* Third child of Match must be NamePath with string _T_ */
+
+ CurrentOp = AcpiPsGetArg (CurrentOp->Common.Parent, 2);
+ if (!CurrentOp || !CurrentOp->Common.Value.Name ||
+ strncmp(CurrentOp->Common.Value.Name, "_T_", 3))
+ {
+ return (FALSE);
+ }
+
+ break;
+
+ default:
+
+ return (FALSE);
+ }
+
+ return (TRUE);
+}
OpenPOWER on IntegriCloud