Add in _reg and immediate support
authorMichael Nolan <mtnolan2640@gmail.com>
Sun, 5 Apr 2020 19:11:49 +0000 (15:11 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Sun, 5 Apr 2020 19:13:45 +0000 (15:13 -0400)
src/soc/decoder/isa/caller.py
src/soc/decoder/isa/test_caller.py

index bd9469888754ac2883d378e38eac273f323db3e6..835c9b48e011ee160cc1ae252e8d375fccdb7bb7 100644 (file)
@@ -124,8 +124,10 @@ class ISACaller:
         self.mem.memassign(ea, sz, val)
 
     def prep_namespace(self):
         self.mem.memassign(ea, sz, val)
 
     def prep_namespace(self):
-        si = yield self.decoder.SI
-        self.namespace['SI'] = SelectableInt(si, bits=16)
+        for name in ['SI', 'UI', 'D', 'BD']:
+            signal = getattr(self.decoder, name)
+            val = yield signal
+            self.namespace[name] = SelectableInt(val, bits=signal.width)
 
     def call(self, name):
         yield from self.prep_namespace()
 
     def call(self, name):
         yield from self.prep_namespace()
@@ -137,17 +139,22 @@ class ISACaller:
         inputs = []
         for name in input_names:
             regnum = yield getattr(self.decoder, name)
         inputs = []
         for name in input_names:
             regnum = yield getattr(self.decoder, name)
+            regname = "_" + name
+            self.namespace[regname] = regnum
             print('reading reg %d' % regnum)
             inputs.append(self.gpr(regnum))
         print(inputs)
         results = function(self, *inputs)
         print(results)
 
             print('reading reg %d' % regnum)
             inputs.append(self.gpr(regnum))
         print(inputs)
         results = function(self, *inputs)
         print(results)
 
-        output_names = create_args(write_regs)
-        for name, output in zip(output_names, results):
-            regnum = yield getattr(self.decoder, name)
-            print('writing reg %d' % regnum)
-            self.gpr[regnum] = output.narrow(64)
+        if write_regs:
+            output_names = create_args(write_regs)
+            for name, output in zip(output_names, results):
+                regnum = yield getattr(self.decoder, name)
+                print('writing reg %d' % regnum)
+                if isinstance(output, int):
+                    output = SelectableInt(output, 64)
+                self.gpr[regnum] = output
 
 
 def inject():
 
 
 def inject():
index aa6f23ae90f0fe318d06a99717fc9c48a5780a5c..d0a97df64bb2fdbabf873274f2339caf30d879c7 100644 (file)
@@ -69,6 +69,16 @@ class DecoderTestCase(FHDLTestCase):
             print(sim.gpr(1))
             self.assertEqual(sim.gpr(1), SelectableInt(0x5555, 64))
 
             print(sim.gpr(1))
             self.assertEqual(sim.gpr(1), SelectableInt(0x5555, 64))
 
+    def test_load_store(self):
+        lst = ["addi 1, 0, 0x0010",
+               "addi 2, 0, 0x1234",
+               "stw 2, 0(1)",
+               "lwz 3, 0(1)"]
+        with Program(lst) as program:
+            sim = self.run_test_program(program)
+            print(sim.gpr(1))
+            self.assertEqual(sim.gpr(3), SelectableInt(0x1234, 64))
+
     def run_test_program(self, prog, initial_regs=[0] * 32):
         simulator = self.run_tst(prog, initial_regs)
         simulator.gpr.dump()
     def run_test_program(self, prog, initial_regs=[0] * 32):
         simulator = self.run_tst(prog, initial_regs)
         simulator.gpr.dump()