Add support for extended/indexed ld/st
authorMichael Nolan <mtnolan2640@gmail.com>
Mon, 23 Mar 2020 15:46:36 +0000 (11:46 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Mon, 23 Mar 2020 20:01:45 +0000 (16:01 -0400)
src/soc/simulator/internalop_sim.py
src/soc/simulator/test_sim.py

index 2f435dc7c9f46c064d03300a02a6b3a85b113868..cf71670d87ca34013eaf5eeaf4f118941475d51f 100644 (file)
@@ -96,9 +96,13 @@ class InternalOpSimulator:
         addr = self.regfile.read_reg(addr_reg)
         
         imm_ok = yield pdecode2.e.imm_data.ok
+        r2_ok = yield pdecode2.e.read_reg2.ok
         if imm_ok:
             imm = yield pdecode2.e.imm_data.data
             addr += imm
+        elif r2_ok:
+            r2_sel = yield pdecode2.e.read_reg2.data
+            addr += self.regfile.read_reg(r2_sel)
         if internal_op == InternalOp.OP_STORE.value:
             val_reg = yield pdecode2.e.read_reg3.data
             val = self.regfile.read_reg(val_reg)
index 3a5e37b92f1795e885abd82513975527251294ee..94a9f39aa5bf40d85cbe3eda3d6c32b89c8139b1 100644 (file)
@@ -89,6 +89,21 @@ class DecoderTestCase(FHDLTestCase):
              2: 0x5678,
              3: 0x1234})
 
+    def test_ldst_extended(self):
+        lst = ["addi 1, 0, 0x1234",
+               "addi 2, 0, 0x5678",
+               "addi 4, 0, 0x40",
+               "stw  1, 0x40(2)",
+               "lwzx  3, 4, 2"]
+        gen = InstrList(lst)
+
+        simulator = InternalOpSimulator()
+
+        self.run_tst(gen, simulator)
+        simulator.regfile.assert_gprs(
+            {1: 0x1234,
+             2: 0x5678,
+             3: 0x1234})
 
 if __name__ == "__main__":
     unittest.main()