add disassembly dump and set_lr to qemu
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 27 May 2021 17:25:50 +0000 (18:25 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 27 May 2021 17:25:50 +0000 (18:25 +0100)
src/openpower/decoder/isa/pypowersim.py
src/openpower/simulator/qemu.py

index b32815dd8bd58bfd0647c38f2a67860e6ac62519..50d6024e2335157ce46c72a6fe070b262c65f34a 100644 (file)
@@ -134,7 +134,13 @@ def run_tst(args, generator, qemu,
         qemu = run_program(generator, initial_mem=mem, 
                 bigendian=False, start_addr=initial_pc,
                 continuous_run=False)
-        # TODO: SPRs.  how??
+        # TODO: SPRs.  how?? sigh, by cheating
+        if initial_sprs:
+            lr = initial_sprs.get('lr', None)
+            if lr is None:
+                lr = initial_sprs.get('LR', None)
+            if lr is not None:
+                qemu.set_lr(lr)
         if initial_regs is not None:
             for reg, val in enumerate(initial_regs):
                 qemu.set_gpr(reg, val)
index b775c26c076243a933a9712214367165a0a4834f..28042d0b9329f18f3acf73173f4b8788e5470178 100644 (file)
@@ -168,6 +168,10 @@ class QemuController:
         self._rcache_trash('x 66')
         self.gdb_eval('$cr=%d' % cr)
 
+    def set_lr(self, lr):
+        self._rcache_trash('x 67')
+        self.gdb_eval('$lr=%d' % lr)
+
     def step(self):
         self._rcache_trash()
         return self.gdb.write('-exec-step-instruction')
@@ -186,6 +190,11 @@ class QemuController:
         self.qemu_popen.stdout.close()
         self.qemu_popen.stdin.close()
 
+    def disasm(self, start, end):
+        res = self.gdb.write('-data-disassemble -s "%d" -e "%d" -- 0' % \
+                        (start, end))
+        return res[0]['payload']['asm_insns']
+
     def upload_mem(self, initial_mem, skip_zeros=False):
         if isinstance(initial_mem, tuple):
             addr, mem = initial_mem # assume 8-byte width
@@ -247,7 +256,9 @@ def run_program(program, initial_mem=None, extra_break_addr=None,
     if continuous_run:
         q.gdb_continue()
     q.set_endian(bigendian)
-
+    d = q.disasm(start_addr, start_addr + program.size())
+    for line in d:
+        print ("qemu disasm", line)
     return q