allow Mem in Simulator to be initialised
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 6 Jun 2020 16:13:50 +0000 (17:13 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sat, 6 Jun 2020 16:13:50 +0000 (17:13 +0100)
src/soc/decoder/isa/caller.py
src/soc/fu/compunits/test/test_compunit.py
src/soc/fu/compunits/test/test_ldst_compunit.py
src/soc/fu/ldst/test/test_pipe_caller.py
src/soc/fu/test/common.py

index 299b74c0e136a65a0f1a68955e6ccda786e2cf99..525b2b70bf351488ed39fe08341f7133c0795294 100644 (file)
@@ -31,10 +31,13 @@ def create_args(reglist, extra=None):
 
 class Mem:
 
-    def __init__(self, bytes_per_word=8):
+    def __init__(self, bytes_per_word=8, initial_mem=None):
         self.mem = {}
         self.bytes_per_word = bytes_per_word
         self.word_log2 = math.ceil(math.log2(bytes_per_word))
+        if initial_mem:
+            for addr, (val, width) in initial_mem.items():
+                self.st(addr, val, width)
 
     def _get_shifter_mask(self, width, remainder):
         shifter = ((self.bytes_per_word - width) - remainder) * \
@@ -168,9 +171,14 @@ class SPR(dict):
 class ISACaller:
     # decoder2 - an instance of power_decoder2
     # regfile - a list of initial values for the registers
-    def __init__(self, decoder2, regfile, initial_sprs={}, initial_cr=0):
+    def __init__(self, decoder2, regfile, initial_sprs=None, initial_cr=0,
+                       initial_mem=None):
+        if initial_sprs is None:
+            initial_sprs = {}
+        if initial_mem is None:
+            initial_mem = {}
         self.gpr = GPR(decoder2, regfile)
-        self.mem = Mem()
+        self.mem = Mem(initial_mem=initial_mem)
         self.pc = PC()
         self.spr = SPR(decoder2, initial_sprs)
         # TODO, needed here:
index d823340220c4efaf440e2abbad5d5a2c27e6cd44..69c9d0fc61d43df97f3fe92b2a44de12cace36e5 100644 (file)
@@ -198,6 +198,10 @@ class TestRunner(FHDLTestCase):
                     yield from self.iodef.check_cu_outputs(res, pdecode2,
                                                             sim, code)
 
+                    # sigh.  hard-coded.  test memory
+                    if self.funit == Function.LDST:
+                        print ("mem dump", sim.mem.mem)
+
         sim.add_sync_process(process)
 
         name = self.funit.name.lower()
index 525f88a1eab12e72c44a7ccd3d15a9a2f8d73c47..c91b2e5de8badcdd6e229a7958bd890a95acac02 100644 (file)
@@ -22,6 +22,7 @@ class LDSTTestRunner(TestRunner):
         """naming (res) must conform to LDSTFunctionUnit output regspec
         """
 
+        print ("check cu outputs", res)
         # RT
         out_reg_valid = yield dec2.e.write_reg.ok
         if out_reg_valid:
index 9f2f0c09ba5cc7df6ba937c06655680b5fbd8f2c..adceb4cff3c036a148a19c3426a2921b8a04078f 100644 (file)
@@ -56,11 +56,22 @@ class LDSTTestCase(FHDLTestCase):
         super().__init__(name)
         self.test_name = name
 
-    def run_tst_program(self, prog, initial_regs=None, initial_sprs=None):
-        tc = TestCase(prog, self.test_name, initial_regs, initial_sprs)
+    def run_tst_program(self, prog, initial_regs=None,
+                        initial_sprs=None, initial_mem=None):
+        tc = TestCase(prog, self.test_name, initial_regs, initial_sprs,
+                      mem=initial_mem)
         self.test_data.append(tc)
 
-    def test_load_store(self):
+    def test_1_load(self):
+        lst = ["lwz 3, 0(1)"]
+        initial_regs = [0] * 32
+        initial_regs[1] = 0x0004
+        initial_regs[2] = 0x0008
+        initial_mem = {0x0004: (0x1234, 4)}
+        self.run_tst_program(Program(lst), initial_regs,
+                             initial_mem=initial_mem)
+
+    def tst_2_load_store(self):
         lst = ["stw 2, 0(1)",
                "lwz 3, 0(1)"]
         initial_regs = [0] * 32
@@ -68,11 +79,3 @@ class LDSTTestCase(FHDLTestCase):
         initial_regs[2] = 0x0008
         self.run_tst_program(Program(lst), initial_regs)
 
-    def test_ilang(self):
-        pspec = LDSTPipeSpec(id_wid=2)
-        alu = LDSTBasePipe(pspec)
-        vl = rtlil.convert(alu, ports=alu.ports())
-        with open("ldst_pipeline.il", "w") as f:
-            f.write(vl)
-
-
index bd8a35a5c9e0ba83f8e7b51b49367b0a39803a25..246a51e100367f3f786a220a4a688441051c22af 100644 (file)
@@ -1,5 +1,6 @@
 class TestCase:
-    def __init__(self, program, name, regs=None, sprs=None, cr=0):
+    def __init__(self, program, name, regs=None, sprs=None, cr=0, mem=None):
+
         self.program = program
         self.name = name
 
@@ -7,7 +8,9 @@ class TestCase:
             regs = [0] * 32
         if sprs is None:
             sprs = {}
+        if mem is None:
+            mem = {}
         self.regs = regs
         self.sprs = sprs
         self.cr = cr
-
+        self.mem = mem