Do a better job checking CSR functionality.
authorTim Newsome <tim@sifive.com>
Thu, 17 Mar 2016 19:51:58 +0000 (12:51 -0700)
committerTim Newsome <tim@sifive.com>
Mon, 23 May 2016 19:12:10 +0000 (12:12 -0700)
tests/gdbserver.py
tests/regs.s
tests/testlib.py

index 16af626a90722b29d662888afd69bbf2c4f20536..b5363e644c340edfcd194b2e3ea75d6b937b3fdd 100755 (executable)
@@ -53,7 +53,9 @@ class DebugTest(unittest.TestCase):
                 self.assertIn(reg, output)
         # mcpuid is one of the few registers that should have the high bit set
         # (for rv64).
-        self.assertRegexpMatches(output, ".*mcpuid *0x80")
+        # Leave this commented out until gdb and spike agree on the encoding of
+        # mcpuid (which is going to be renamed to misa in any case).
+        #self.assertRegexpMatches(output, ".*mcpuid *0x80")
 
         # The time register should always be changing.
         last_time = None
@@ -85,15 +87,18 @@ class RegsTest(unittest.TestCase):
 
         self.gdb.command("p $pc=write_regs")
         for i, r in enumerate(regs):
-            self.gdb.command("p $%s=%d" % (r, i*0xdeadbeef+17))
+            self.gdb.command("p $%s=%d" % (r, (0xdeadbeef<<i)+17))
         self.gdb.command("p $a0=data")
         self.gdb.command("b all_done")
         output = self.gdb.command("c")
         self.assertIn("Breakpoint 1", output)
 
+        # Just to get this data in the log.
+        self.gdb.command("x/30gx data")
+        self.gdb.command("info registers")
         for n in range(len(regs)):
             self.assertEqual(self.gdb.x("data+%d" % (8*n), 'g'),
-                    n*0xdeadbeef+17)
+                    (0xdeadbeef<<n)+17)
 
     def test_write_csrs(self):
         # As much a test of gdb as of the simulator.
@@ -104,5 +109,15 @@ class RegsTest(unittest.TestCase):
         self.gdb.stepi()
         self.assertEqual(self.gdb.p("$mscratch"), 123)
 
+        self.gdb.command("p $fflags=9")
+        self.gdb.command("p $pc=write_regs")
+        self.gdb.command("p $a0=data")
+        self.gdb.command("b all_done")
+        self.gdb.command("c")
+
+        self.assertEqual(9, self.gdb.p("$fflags"))
+        self.assertEqual(9, self.gdb.p("$x1"))
+        self.assertEqual(9, self.gdb.p("$csr1"))
+
 if __name__ == '__main__':
     unittest.main()
index b0d641d9d937963cf14a7222d9d20bd17c3f9b27..e6456e14111a329aabedc4a4467f90d98c8ccf74 100644 (file)
@@ -3,7 +3,6 @@ main:
         j       main
 
 write_regs:
-        la      a0, data
         sd      x1, 0(a0)
         sd      x2, 8(a0)
         sd      x3, 16(a0)
@@ -35,6 +34,8 @@ write_regs:
         sd      x30, 224(a0)
         sd      x31, 232(a0)
 
+        csrr    x1, 1   # fflags
+
 all_done:
         j       all_done
 
index d41c150a72866e56cd8a41e3c2d561ba6eafbfc3..2590f4643f6a9373ada16d2fe92353f0410471b4 100644 (file)
@@ -54,7 +54,7 @@ class Gdb(object):
 
     def x(self, address, size='w'):
         output = self.command("x/%s %s" % (size, address))
-        value = int(output.split(':')[1].strip())
+        value = int(output.split(':')[1].strip(), 0)
         return value
 
     def p(self, obj):