whoops tried doing mtspr priv, it failed but failed by trying to run TRAP
[soc.git] / src / soc / fu / spr / test / test_pipe_caller.py
index 77d0519a3a5bac9ded00dafedf817caa2f34c54f..3ba1ac3dff97afa9ce637a599e5337f27363a174 100644 (file)
@@ -6,10 +6,12 @@ import unittest
 from soc.decoder.isa.caller import ISACaller, special_sprs
 from soc.decoder.power_decoder import (create_pdecode)
 from soc.decoder.power_decoder2 import (PowerDecode2)
-from soc.decoder.power_enums import (XER_bits, Function, InternalOp, CryIn)
+from soc.decoder.power_enums import (XER_bits, Function, MicrOp, CryIn)
 from soc.decoder.selectable_int import SelectableInt
 from soc.simulator.program import Program
 from soc.decoder.isa.all import ISA
+from soc.config.endian import bigendian
+from soc.consts import MSR
 
 
 from soc.fu.test.common import (TestCase, ALUHelpers)
@@ -25,7 +27,8 @@ def get_cu_inputs(dec2, sim):
 
     yield from ALUHelpers.get_sim_int_ra(res, sim, dec2) # RA
     yield from ALUHelpers.get_sim_int_rb(res, sim, dec2) # RB
-    yield from ALUHelpers.get_sim_fast_spr1(res, sim, dec2) # SPR1
+    yield from ALUHelpers.get_sim_slow_spr1(res, sim, dec2) # FAST1
+    yield from ALUHelpers.get_sim_fast_spr1(res, sim, dec2) # FAST1
     yield from ALUHelpers.get_rd_sim_xer_ca(res, sim, dec2) # XER.ca
     yield from ALUHelpers.get_sim_xer_ov(res, sim, dec2) # XER.ov
     yield from ALUHelpers.get_sim_xer_so(res, sim, dec2) # XER.so
@@ -47,8 +50,9 @@ def set_alu_inputs(alu, dec2, sim):
     yield from ALUHelpers.set_xer_ov(alu, dec2, inp)
     yield from ALUHelpers.set_xer_so(alu, dec2, inp)
 
-    # XXX TODO slow spr1
     yield from ALUHelpers.set_fast_spr1(alu, dec2, inp)
+    yield from ALUHelpers.set_slow_spr1(alu, dec2, inp)
+    return inp
 
 
 # This test bench is a bit different than is usual. Initially when I
@@ -77,17 +81,72 @@ class SPRTestCase(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_msr=0):
+        tc = TestCase(prog, self.test_name, initial_regs, initial_sprs,
+                                            msr=initial_msr)
         self.test_data.append(tc)
 
     def test_1_mfspr(self):
         lst = ["mfspr 1, 26", # SRR0
                "mfspr 2, 27",  # SRR1
-               "mfspr 2, 8",] # LR
+               "mfspr 3, 8",  # LR
+               "mfspr 4, 1",] # XER
         initial_regs = [0] * 32
-        initial_sprs = {'SRR0': 0x12345678, 'SRR1': 0x5678, 'LR': 0x1234}
-        self.run_tst_program(Program(lst), initial_regs, initial_sprs)
+        initial_sprs = {'SRR0': 0x12345678, 'SRR1': 0x5678, 'LR': 0x1234,
+                        'XER': 0xe00c0000}
+        self.run_tst_program(Program(lst, bigendian), initial_regs, initial_sprs)
+
+    def test_1_mtspr(self):
+        lst = ["mtspr 26, 1", # SRR0
+               "mtspr 27, 2", # SRR1
+               "mtspr 1, 3",  # XER
+               "mtspr 9, 4",] # CTR
+        initial_regs = [0] * 32
+        initial_regs[1] = 0x129518230011feed
+        initial_regs[2] = 0x123518230011feed
+        initial_regs[3] = 0xe00c0000
+        initial_regs[4] = 0x1010101010101010
+        initial_sprs = {'SRR0': 0x12345678, 'SRR1': 0x5678, 'LR': 0x1234,
+                        'XER': 0x0}
+        self.run_tst_program(Program(lst, bigendian),
+                             initial_regs, initial_sprs)
+
+    def test_2_mtspr_mfspr(self):
+        lst = ["mtspr 26, 1", # SRR0
+               "mtspr 27, 2", # SRR1
+               "mtspr 1, 3",  # XER
+               "mtspr 9, 4",  # CTR
+               "mfspr 2, 26", # SRR0
+               "mfspr 3, 27", # and into reg 2
+               "mfspr 4, 1",  # XER
+               "mfspr 5, 9",] # CTR
+        initial_regs = [0] * 32
+        initial_regs[1] = 0x129518230011feed
+        initial_regs[2] = 0x123518230011feed
+        initial_regs[3] = 0xe00c0000
+        initial_regs[4] = 0x1010101010101010
+        initial_sprs = {'SRR0': 0x12345678, 'SRR1': 0x5678, 'LR': 0x1234,
+                        'XER': 0x0}
+        self.run_tst_program(Program(lst, bigendian),
+                             initial_regs, initial_sprs)
+
+    @unittest.skip("spr does not have TRAP in it. has to be done another way")
+    def test_3_mtspr_priv(self):
+        lst = ["mtspr 26, 1", # SRR0
+               "mtspr 27, 2", # SRR1
+               "mtspr 1, 3",  # XER
+               "mtspr 9, 4",] # CTR
+        initial_regs = [0] * 32
+        initial_regs[1] = 0x129518230011feed
+        initial_regs[2] = 0x123518230011feed
+        initial_regs[3] = 0xe00c0000
+        initial_regs[4] = 0x1010101010101010
+        initial_sprs = {'SRR0': 0x12345678, 'SRR1': 0x5678, 'LR': 0x1234,
+                        'XER': 0x0}
+        msr = 1<<MSR.PR
+        self.run_tst_program(Program(lst, bigendian),
+                             initial_regs, initial_sprs, initial_msr=msr)
 
     def test_ilang(self):
         pspec = SPRPipeSpec(id_wid=2)
@@ -128,11 +187,13 @@ class TestRunner(FHDLTestCase):
                 program = test.program
                 self.subTest(test.name)
                 sim = ISA(pdecode2, test.regs, test.sprs, test.cr,
-                                test.mem, test.msr)
+                                test.mem, test.msr,
+                                bigendian=bigendian)
                 gen = program.generate_instructions()
                 instructions = list(zip(gen, program.assembly.splitlines()))
 
                 pc = sim.pc.CIA.value
+                msr = sim.msr.value
                 index = pc//4
                 while index < len(instructions):
                     ins, code = instructions[index]
@@ -147,7 +208,8 @@ class TestRunner(FHDLTestCase):
                         print ("before: so/ov/32", so, ov, ov32)
 
                     # ask the decoder to decode this binary data (endian'd)
-                    yield pdecode2.dec.bigendian.eq(0)  # little / big?
+                    yield pdecode2.dec.bigendian.eq(bigendian)  # little / big?
+                    yield pdecode2.msr.eq(msr) # set MSR in pdecode2
                     yield instruction.eq(ins)          # raw binary instr.
                     yield Settle()
 
@@ -159,13 +221,14 @@ class TestRunner(FHDLTestCase):
                     spr_out = yield pdecode2.e.write_spr.data
                     print ("dec2 spr/fast in", fast_out, spr_out)
 
-                    fn_unit = yield pdecode2.e.fn_unit
+                    fn_unit = yield pdecode2.e.do.fn_unit
                     self.assertEqual(fn_unit, Function.SPR.value)
-                    yield from set_alu_inputs(alu, pdecode2, sim)
+                    alu_o = yield from set_alu_inputs(alu, pdecode2, sim)
                     yield
                     opname = code.split(' ')[0]
                     yield from sim.call(opname)
                     pc = sim.pc.CIA.value
+                    msr = sim.msr.value
                     index = pc//4
                     print("pc after %08x" % (pc))
 
@@ -184,7 +247,7 @@ class TestRunner(FHDLTestCase):
 
     def check_alu_outputs(self, alu, dec2, sim, code):
 
-        rc = yield dec2.e.rc.data
+        rc = yield dec2.e.do.rc.data
         cridx_ok = yield dec2.e.write_cr.ok
         cridx = yield dec2.e.write_cr.data
 
@@ -197,6 +260,7 @@ class TestRunner(FHDLTestCase):
 
         yield from ALUHelpers.get_int_o(res, alu, dec2)
         yield from ALUHelpers.get_fast_spr1(res, alu, dec2)
+        yield from ALUHelpers.get_slow_spr1(res, alu, dec2)
         yield from ALUHelpers.get_xer_ov(res, alu, dec2)
         yield from ALUHelpers.get_xer_ca(res, alu, dec2)
         yield from ALUHelpers.get_xer_so(res, alu, dec2)
@@ -204,16 +268,20 @@ class TestRunner(FHDLTestCase):
         print ("output", res)
 
         yield from ALUHelpers.get_sim_int_o(sim_o, sim, dec2)
-        yield from ALUHelpers.get_wr_sim_cr_a(sim_o, sim, dec2)
-        yield from ALUHelpers.get_sim_xer_ov(sim_o, sim, dec2)
+        yield from ALUHelpers.get_wr_sim_xer_so(sim_o, sim, alu, dec2)
+        yield from ALUHelpers.get_wr_sim_xer_ov(sim_o, sim, alu, dec2)
         yield from ALUHelpers.get_wr_sim_xer_ca(sim_o, sim, dec2)
         yield from ALUHelpers.get_wr_fast_spr1(sim_o, sim, dec2)
+        yield from ALUHelpers.get_wr_slow_spr1(sim_o, sim, dec2)
+
+        print ("sim output", sim_o)
 
         ALUHelpers.check_xer_ov(self, res, sim_o, code)
         ALUHelpers.check_xer_ca(self, res, sim_o, code)
+        ALUHelpers.check_xer_so(self, res, sim_o, code)
         ALUHelpers.check_int_o(self, res, sim_o, code)
         ALUHelpers.check_fast_spr1(self, res, sim_o, code)
-        ALUHelpers.check_xer_so(self, res, sim_o, code)
+        ALUHelpers.check_slow_spr1(self, res, sim_o, code)
 
 
 if __name__ == "__main__":