Skip to content

Commit

Permalink
Disassembler: Do not unconditionally remove temporary names
Browse files Browse the repository at this point in the history
Change the Switch disassembly code to check if the conversion can be
done before removing temporary (_T_x) names. Prevents invalid
disassembly of AML created by older compilers (circa 2005).

Link: https://bugs.acpica.org/show_bug.cgi?id=1358
Link: https://bugs.acpica.org/show_bug.cgi?id=1360
Reported-by: racerrehabman@gmail.com
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
  • Loading branch information
debox1 committed Feb 24, 2017
1 parent bb1a602 commit c46f496
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
37 changes: 26 additions & 11 deletions source/components/disassembler/dmopcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ AcpiDmPromoteSubtree (

static BOOLEAN
AcpiDmIsSwitchBlock (
ACPI_PARSE_OBJECT *Op);
ACPI_PARSE_OBJECT *Op,
char *Temp);

static BOOLEAN
AcpiDmIsCaseBlock (
Expand Down Expand Up @@ -1049,7 +1050,7 @@ AcpiDmDisassembleOneOp (

case AML_WHILE_OP:

if (AcpiDmIsSwitchBlock(Op))
if (Op->Common.DisasmOpcode == ACPI_DASM_SWITCH)
{
AcpiOsPrintf ("%s", "Switch");
break;
Expand Down Expand Up @@ -1327,18 +1328,21 @@ AcpiDmPromoteSubtree (
*
* PARAMETERS: Op - Object to be examined
*
* RETURN: TRUE if object is a temporary (_T_x) name
* RETURN: TRUE if object is a temporary (_T_x) name for a matching While
* loop that can be converted to a Switch.
*
* DESCRIPTION: Determine if an object is a temporary name and ignore it.
* Temporary names are only used for Switch statements. This
* function depends on this restriced usage.
* 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)
Expand All @@ -1354,11 +1358,21 @@ AcpiDmIsTempName (
return (FALSE);
}

/* Ignore Op */
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;

Op->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
return (TRUE);
}
CurrentOp = CurrentOp->Common.Next;
}

return (TRUE);
return (FALSE);
}

/*******************************************************************************
Expand Down Expand Up @@ -1394,7 +1408,8 @@ AcpiDmIsTempName (

static BOOLEAN
AcpiDmIsSwitchBlock (
ACPI_PARSE_OBJECT *Op)
ACPI_PARSE_OBJECT *Op,
char *Temp)
{
ACPI_PARSE_OBJECT *OneOp;
ACPI_PARSE_OBJECT *StoreOp;
Expand Down Expand Up @@ -1427,7 +1442,7 @@ AcpiDmIsSwitchBlock (
return (FALSE);
}

if (strncmp((char *)(NamePathOp->Common.Aml), "_T_", 3))
if (strncmp((char *)(NamePathOp->Common.Aml), Temp, 4))
{
return (FALSE);
}
Expand Down
7 changes: 4 additions & 3 deletions source/include/aclocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1009,9 +1009,10 @@ typedef union acpi_parse_value
#define ACPI_DASM_LNOT_SUFFIX 0x09 /* End of a LNotEqual (etc.) pair of opcodes */
#define ACPI_DASM_HID_STRING 0x0A /* String is a _HID or _CID */
#define ACPI_DASM_IGNORE_SINGLE 0x0B /* Ignore the opcode but not it's children */
#define ACPI_DASM_SWITCH_PREDICATE 0x0C /* Object is a predicate for a Switch or Case block */
#define ACPI_DASM_CASE 0x0D /* If/Else is a Case in a Switch/Case block */
#define ACPI_DASM_DEFAULT 0x0E /* Else is a Default in a Switch/Case block */
#define ACPI_DASM_SWITCH 0x0C /* While is a Switch */
#define ACPI_DASM_SWITCH_PREDICATE 0x0D /* Object is a predicate for a Switch or Case block */
#define ACPI_DASM_CASE 0x0E /* If/Else is a Case in a Switch/Case block */
#define ACPI_DASM_DEFAULT 0x0F /* Else is a Default in a Switch/Case block */

/*
* Generic operation (for example: If, While, Store)
Expand Down

0 comments on commit c46f496

Please sign in to comment.