power_insn: support legacy style
authorDmitry Selyutin <ghostmansd@gmail.com>
Mon, 16 Jan 2023 19:10:44 +0000 (22:10 +0300)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 2 Jun 2023 18:51:16 +0000 (19:51 +0100)
src/openpower/decoder/power_insn.py
src/openpower/sv/trans/pysvp64dis.py
src/openpower/sv/trans/svp64.py

index 5679a8804e9c06a9f55618e1aa8042b161486e40..a87a029f1be4f3402528637962f24d63388ce8ae 100644 (file)
@@ -56,6 +56,7 @@ from openpower.decoder.pseudo.pagereader import ISA as _ISA
 
 @_functools.total_ordering
 class Style(_enum.Enum):
+    LEGACY = _enum.auto()
     SHORT = _enum.auto()
     NORMAL = _enum.auto()
     VERBOSE = _enum.auto()
@@ -1729,13 +1730,6 @@ class WordInstruction(Instruction):
         record = cls.record(db=db, entry=entry)
         insn = cls.integer(value=0)
 
-        opcode = record.section.opcode
-        if opcode is None:
-            opcode = record.ppc.opcode
-        bits = record.section.bitsel
-        for (src, dst) in enumerate(reversed(bits)):
-            insn[dst] = ((opcode.value & (1 << src)) != 0)
-
         for (op_cls, op_kwargs) in record.static_operands:
             operand = op_cls(record=record, **op_kwargs)
             operand.assemble(insn=insn)
@@ -1749,8 +1743,7 @@ class WordInstruction(Instruction):
 
     def disassemble(self, db,
             byteorder="little",
-            style=Style.NORMAL,
-            compatibility=False):
+            style=Style.NORMAL):
         if style <= Style.SHORT:
             blob = ""
         else:
@@ -1763,13 +1756,16 @@ class WordInstruction(Instruction):
             yield f"{blob}.long 0x{int(self):08x}"
             return
 
-        operands = tuple(map(_operator.itemgetter(1),
-            self.dynamic_operands(db=db, style=style)))
-        if operands:
-            operands = ",".join(operands)
-            yield f"{blob}{record.name} {operands}"
+        if style <= Style.LEGACY and record.ppc.unofficial:
+            yield f"{blob}.long 0x{int(self):08x}"
         else:
-            yield f"{blob}{record.name}"
+            operands = tuple(map(_operator.itemgetter(1),
+                self.dynamic_operands(db=db, style=style)))
+            if operands:
+                operands = ",".join(operands)
+                yield f"{blob}{record.name} {operands}"
+            else:
+                yield f"{blob}{record.name}"
 
         if style >= Style.VERBOSE:
             indent = (" " * 4)
@@ -3450,11 +3446,13 @@ class SVP64Instruction(PrefixedInstruction):
         insn.prefix.PO = 0x1
         insn.prefix.id = 0x3
 
+
         return insn
 
     def disassemble(self, db,
             byteorder="little",
             style=Style.NORMAL):
+
         def blob(insn):
             if style <= Style.SHORT:
                 return ""
@@ -3488,9 +3486,15 @@ class SVP64Instruction(PrefixedInstruction):
         if len(operands) > 0: # if any separate with a space
             operands = (" " + operands)
 
-        yield f"{blob_prefix}{name}{specifiers}{operands}"
-        if blob_suffix:
-            yield f"{blob_suffix}"
+        if style <= Style.LEGACY:
+            yield f"{blob_prefix}.long 0x{int(self.prefix):08x}"
+            suffix = WordInstruction.integer(value=int(self.suffix))
+            yield from suffix.disassemble(db=db,
+                byteorder=byteorder, style=style)
+        else:
+            yield f"{blob_prefix}{name}{specifiers}{operands}"
+            if blob_suffix:
+                yield f"{blob_suffix}"
 
         if style >= Style.VERBOSE:
             indent = (" " * 4)
index 203610a3ec5b08f7fc605e0f72bec6b2c25e0291..eedf7b1ecb9c812f50d6344b59ef2afa15e709dc 100644 (file)
@@ -72,7 +72,10 @@ def main():
     parser.add_argument("-v", "--verbose",
         dest="style", default=_Style.NORMAL,
         action="store_const", const=_Style.VERBOSE)
-    parser.add_argument("-l", "--log",
+    parser.add_argument("-l", "--legacy",
+        dest="style", default=_Style.NORMAL,
+        action="store_const", const=_Style.LEGACY)
+    parser.add_argument("-L", "--log",
         action="store_true", default=False)
 
     args = dict(vars(parser.parse_args()))
index 90063f33db42de505862d06801fd122c5dcaed8f..7792a9a3f2e5c6328392ed44660d2ed2f5a46553 100644 (file)
@@ -273,12 +273,7 @@ class SVP64Asm:
         if record is not None:
             insn = WordInstruction.assemble(db=DB,
                 entry=opcode, arguments=fields)
-            yield " ".join((
-                f".long 0x{int(insn):08X}",
-                "#",
-                opcode,
-                ",".join(fields),
-            ))
+            yield from insn.disassemble(db=DB, style=Style.LEGACY)
             return
 
         # identify if is a svp64 mnemonic
@@ -305,10 +300,7 @@ class SVP64Asm:
                 entry=v30b_op_orig,
                 arguments=fields,
                 specifiers=opmodes)
-            prefix = int(insn.prefix)
-            suffix = int(insn.suffix)
-            yield f".long 0x{prefix:08X}"
-            yield from insn.suffix.disassemble(db=DB, style=Style.SHORT)
+            yield from insn.disassemble(db=DB, style=Style.LEGACY)
             return
 
         # look up the 32-bit op (original, with "." if it has it)
@@ -957,12 +949,7 @@ class SVP64Asm:
         if record is not None:
             insn = WordInstruction.assemble(db=DB,
                 entry=opcode, arguments=fields)
-            yield " ".join((
-                f".long 0x{int(insn):08X}",
-                "#",
-                opcode,
-                ",".join(fields),
-            ))
+            yield from insn.disassemble(db=DB, style=Style.LEGACY)
         else:
             if not v30b_op.endswith('.'):
                 v30b_op += rc