From e5ba06cbe80a02325184ffc9bc032e9794d963ae Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Fri, 6 Aug 2021 15:08:15 +0800 Subject: [PATCH] board_inspector: a workaround to an incorrect interpretation The current design of AML parsing, objects are first defined in the namespace and later dropped if they are in a False branch. This leads to incorrect interpretation of the AML code where: 1. A name T is defined in the root scope as an integer. 2. A method M in an inner scope S references T. 3. The name T is defined as a device, power resource or other named objects in scope S under conditions where M will not be called. As a workaround, check if both the left and right hand sides are integers first. If either is not the case, Tracked-On: #6287 Signed-off-by: Junjie Mao --- .../acpiparser/aml/datatypes.py | 4 +++- .../acpiparser/aml/interpreter.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/misc/config_tools/board_inspector/acpiparser/aml/datatypes.py b/misc/config_tools/board_inspector/acpiparser/aml/datatypes.py index 6b583c253..50ead0b92 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/datatypes.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/datatypes.py @@ -399,7 +399,9 @@ class Package(Object): def to_string(self): return "Package" -# PowerResource +class PowerResource(Object): + def __init__(self, name): + self.name = name # Processor diff --git a/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py b/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py index 37d41c941..3c9d5d362 100644 --- a/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py +++ b/misc/config_tools/board_inspector/acpiparser/aml/interpreter.py @@ -336,6 +336,9 @@ class ConcreteInterpreter(Interpreter): self.context.register_operation_region(sym.name, op_region) return op_region + def DefPowerRes(self, tree): + return PowerResource(tree.NameString.value) + # 20.2.5.3 Statement Opcodes Encoding def DefBreak(self, tree): self.to_break = True @@ -385,7 +388,20 @@ class ConcreteInterpreter(Interpreter): def __eval_binary_op(self, tree, op): lhs = self.interpret(tree.children[0]) rhs = self.interpret(tree.children[1]) - res = Integer(op(lhs.get(), rhs.get())) + # FIXME: The current design of AML parsing, objects are first defined in the namespace and later dropped if they + # are in a False branch. This leads to incorrect interpretation of the AML code where: + # + # 1. A name T is defined in the root scope as an integer. + # 2. A method M in an inner scope S references T. + # 3. The name T is defined as a device, power resource or other named objects in scope S under conditions + # where M will not be called. + # + # As a workaround, check if both the left and right hand sides are integers first. If either is not the case, + # the condition is evaluated to False. + if isinstance(lhs, Integer) and isinstance(rhs, Integer): + res = Integer(op(lhs.get(), rhs.get())) + else: + res = Integer(0) if len(tree.children) >= 3: target = self.interpret(tree.children[2]) if target: