From 05cfb8ad4e1e644890bd68fd4a49bd1645e95e41 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Wed, 31 Aug 2022 13:36:48 +0300 Subject: [PATCH] power_insn: support target_addr operands --- src/openpower/decoder/power_insn.py | 35 +++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/openpower/decoder/power_insn.py b/src/openpower/decoder/power_insn.py index d5681635..b34944a2 100644 --- a/src/openpower/decoder/power_insn.py +++ b/src/openpower/decoder/power_insn.py @@ -421,17 +421,44 @@ class Operands(tuple): name: str value: int = None - def __new__(cls, iterable): - dynamic_cls = cls.DynamicOperand - static_cls = cls.StaticOperand + @_dataclasses.dataclass(eq=True, frozen=True) + class DynamicOperandTargetAddrIForm(DynamicOperand): + def disassemble(self, value, record): + return hex(int(_selectconcat( + value[record.fields["LI"]], + _SelectableInt(value=0b00, bits=2)))) + + class DynamicOperandTargetAddrBForm(DynamicOperand): + def disassemble(self, value, record): + return hex(int(_selectconcat( + value[record.fields["BD"]], + _SelectableInt(value=0b00, bits=2)))) + + def __new__(cls, insn, iterable): + branches = { + "b": {"target_addr": cls.DynamicOperandTargetAddrIForm}, + "ba": {"target_addr": cls.DynamicOperandTargetAddrIForm}, + "bl": {"target_addr": cls.DynamicOperandTargetAddrIForm}, + "bla": {"target_addr": cls.DynamicOperandTargetAddrIForm}, + "bc": {"target_addr": cls.DynamicOperandTargetAddrBForm}, + "bca": {"target_addr": cls.DynamicOperandTargetAddrBForm}, + "bcl": {"target_addr": cls.DynamicOperandTargetAddrBForm}, + "bcla": {"target_addr": cls.DynamicOperandTargetAddrBForm}, + } operands = [] for operand in iterable: + dynamic_cls = cls.DynamicOperand + static_cls = cls.StaticOperand + if "=" in operand: (name, value) = operand.split("=") operand = static_cls(name=name, value=int(value)) else: + if insn in branches and operand in branches[insn]: + dynamic_cls = branches[insn][operand] operand = dynamic_cls(name=operand) + operands.append(operand) return super().__new__(cls, operands) @@ -788,7 +815,7 @@ class MarkdownDatabase: (dynamic, *static) = desc.regs operands.extend(dynamic) operands.extend(static) - db[name] = Operands(iterable=operands) + db[name] = Operands(insn=name, iterable=operands) self.__db = db return super().__init__() -- 2.30.2