set SPRs inside qemu run_program
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 27 May 2021 17:32:07 +0000 (18:32 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 27 May 2021 17:32:07 +0000 (18:32 +0100)
src/openpower/decoder/isa/pypowersim.py
src/openpower/simulator/qemu.py

index 50d6024e2335157ce46c72a6fe070b262c65f34a..5a4d3e6d6de51c5a9a3c95624e6fc4223365f118 100644 (file)
@@ -88,8 +88,8 @@ def read_entries(fname, listqty=None):
 
     return result
 
-def qemu_register_compare(sim, qemu, regs, fprs):
-    qpc, qxer, qcr = qemu.get_pc(), qemu.get_xer(), qemu.get_cr()
+def qemu_register_compare(sim, q, regs, fprs):
+    qpc, qxer, qcr, qlr = q.get_pc(), q.get_xer(), q.get_cr(), q.get_lr()
     sim_cr = sim.cr.value
     sim_pc = sim.pc.CIA.value
     sim_xer = sim.spr['XER'].value
@@ -102,14 +102,14 @@ def qemu_register_compare(sim, qemu, regs, fprs):
     print("sim xer", hex(sim_xer))
     #self.assertEqual(qpc, sim_pc)
     for reg in regs:
-        qemu_val = qemu.get_gpr(reg)
+        qemu_val = q.get_gpr(reg)
         sim_val = sim.gpr(reg).value
         if qemu_val != sim_val:
             log("expect gpr %d %x got %x" % (reg, qemu_val, sim_val))
         #self.assertEqual(qemu_val, sim_val,
         #                 "expect %x got %x" % (qemu_val, sim_val))
     for fpr in fprs:
-        qemu_val = qemu.get_fpr(fpr)
+        qemu_val = q.get_fpr(fpr)
         sim_val = sim.fpr(fpr).value
         if qemu_val != sim_val:
             log("expect fpr %d %x got %x" % (fpr, qemu_val, sim_val))
@@ -133,14 +133,7 @@ def run_tst(args, generator, qemu,
         log("qemu program", generator.binfile.name)
         qemu = run_program(generator, initial_mem=mem, 
                 bigendian=False, start_addr=initial_pc,
-                continuous_run=False)
-        # 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)
+                continuous_run=False, initial_sprs=initial_sprs)
         if initial_regs is not None:
             for reg, val in enumerate(initial_regs):
                 qemu.set_gpr(reg, val)
index 28042d0b9329f18f3acf73173f4b8788e5470178..2f77b9fc6879d223611c80e9797c24d0e2dfeaa5 100644 (file)
@@ -218,7 +218,7 @@ class QemuController:
 
 def run_program(program, initial_mem=None, extra_break_addr=None,
                 bigendian=False, start_addr=0x20000000, init_endian=True,
-                continuous_run=True):
+                continuous_run=True, initial_sprs=None):
     q = QemuController(program.binfile.name, bigendian)
     q.connect()
     q.set_endian(init_endian)  # easier to set variables this way
@@ -246,6 +246,15 @@ def run_program(program, initial_mem=None, extra_break_addr=None,
     q.set_cr(0)
     # delete the previous breakpoint so loops don't screw things up
     q.delete_breakpoint()
+
+    # can't do many of these - lr, ctr, etc. etc. later, just LR for now
+    if initial_sprs:
+        lr = initial_sprs.get('lr', None)
+        if lr is None:
+            lr = initial_sprs.get('LR', None)
+        if lr is not None:
+            q.set_lr(lr)
+
     # allow run to end
     q.break_address(start_addr + program.size())
     # or to trap (not ideal)