add get_fpregs stub function to HDLstate
[soc.git] / src / soc / simple / test / teststate.py
index 9d7f8e994dff9359f199bf4a70459d25dff5d042..f95370d0c984f68f77de51d5bfc5e11b60b6a892 100644 (file)
@@ -1,55 +1,29 @@
-from openpower.decoder.power_enums import XER_bits
-
-
-class SimState:
-    def __init__(self, sim):
-        self.sim = sim
+""" Power ISA test API
 
-    def get_intregs(self):
-        if False:
-            yield
-        self.intregs = []
-        for i in range(32):
-            simregval = self.sim.gpr[i].asint()
-            self.intregs.append(simregval)
-        print("class sim int regs", list(map(hex, self.intregs)))
+This module implements the creation, inspection and comparison
+of test states for TestIssuer HDL
 
-    def get_crregs(self):
-        if False:
-            yield
-        self.crregs = []
-        for i in range(8):
-            cri = self.sim.crl[7 - i].get_range().value
-            self.crregs.append(cri)
-        print("class sim cr regs", list(map(hex, self.crregs)))
-
-    def get_xregs(self):
-        if False:
-            yield
-        self.xregs = []
-        self.so = self.sim.spr['XER'][XER_bits['SO']].value
-        self.ov = self.sim.spr['XER'][XER_bits['OV']].value
-        self.ov32 = self.sim.spr['XER'][XER_bits['OV32']].value
-        self.ca = self.sim.spr['XER'][XER_bits['CA']].value
-        self.ca32 = self.sim.spr['XER'][XER_bits['CA32']].value
-        self.ov = self.ov | (self.ov32 << 1)
-        self.ca = self.ca | (self.ca32 << 1)
-        self.xregs.extend((self.so, self.ov, self.ca))
-        print("class sim xregs", list(map(hex, self.xregs)))
-
-    def get_pc(self):
-        if False:
-            yield
-        self.pcl = []
-        self.pc = self.sim.pc.CIA.value
-        self.pcl.append(self.pc)
-        print("class sim pc", hex(self.pc))
+"""
 
+from openpower.decoder.power_enums import XER_bits
+from openpower.util import log
+from openpower.test.state import (State, state_add, state_factory,
+                                  TestState,)
+from soc.fu.compunits.test.test_compunit import get_l0_mem
 
-class HDLState:
+class HDLState(State):
+    """HDLState: Obtains registers and memory from an nmigen simulator
+    object by implementing State class methods.
+    """
     def __init__(self, core):
+        super().__init__()
         self.core = core
 
+    def get_fpregs(self):
+        self.fpregs = []
+        for i in range(32):
+            self.fpregs.append(0)
+
     def get_intregs(self):
         self.intregs = []
         for i in range(32):
@@ -58,14 +32,14 @@ class HDLState:
             else:
                 rval = yield self.core.regs.int.memory._array[i]
             self.intregs.append(rval)
-        print("class hdl int regs", list(map(hex, self.intregs)))
+        log("class hdl int regs", list(map(hex, self.intregs)))
 
     def get_crregs(self):
         self.crregs = []
         for i in range(8):
-            rval = yield self.core.regs.cr.regs[i].reg
+            rval = yield self.core.regs.cr.regs[7-i].reg
             self.crregs.append(rval)
-        print("class hdl cr regs", list(map(hex, self.crregs)))
+        log("class hdl cr regs", list(map(hex, self.crregs)))
 
     def get_xregs(self):
         self.xregs = []
@@ -74,11 +48,27 @@ class HDLState:
         self.ov = yield self.xr.regs[self.xr.OV].reg
         self.ca = yield self.xr.regs[self.xr.CA].reg
         self.xregs.extend((self.so, self.ov, self.ca))
-        print("class hdl xregs", list(map(hex, self.xregs)))
+        log("class hdl xregs", list(map(hex, self.xregs)))
 
     def get_pc(self):
         self.pcl = []
         self.state = self.core.regs.state
+        # relies on the state.r_port being permanently held as PC
         self.pc = yield self.state.r_ports['cia'].o_data
         self.pcl.append(self.pc)
-        print("class hdl pc", hex(self.pc))
+        log("class hdl pc", hex(self.pc))
+
+    def get_mem(self):
+        self.mem = {}
+        # get the underlying HDL-simulated memory from the L0CacheBuffer
+        if hasattr(self.core, "icache"):
+            # err temporarily ignore memory
+            return # XXX have to work out how to deal with wb_get
+        hdlmem = get_l0_mem(self.core.l0)
+        for i in range(hdlmem.depth):
+            value = yield hdlmem._array[i] # should not really do this
+            self.mem[i*8] = value
+
+
+# add to State Factory
+state_add('hdl', HDLState)