Fix test_instant_halt.
[riscv-tests.git] / debug / gdbserver.py
index 652ad3366752ef2b2bfba8d2a84d8c92409e235c..6b7ac030b3f78239ff5ed324aa253036cbe1b25f 100755 (executable)
@@ -10,6 +10,26 @@ import time
 import random
 import binascii
 
+MSTATUS_UIE = 0x00000001
+MSTATUS_SIE = 0x00000002
+MSTATUS_HIE = 0x00000004
+MSTATUS_MIE = 0x00000008
+MSTATUS_UPIE = 0x00000010
+MSTATUS_SPIE = 0x00000020
+MSTATUS_HPIE = 0x00000040
+MSTATUS_MPIE = 0x00000080
+MSTATUS_SPP = 0x00000100
+MSTATUS_HPP = 0x00000600
+MSTATUS_MPP = 0x00001800
+MSTATUS_FS = 0x00006000
+MSTATUS_XS = 0x00018000
+MSTATUS_MPRV = 0x00020000
+MSTATUS_PUM = 0x00040000
+MSTATUS_MXR = 0x00080000
+MSTATUS_VM = 0x1F000000
+MSTATUS32_SD = 0x80000000
+MSTATUS64_SD = 0x8000000000000000
+
 def ihex_line(address, record_type, data):
     assert len(data) < 128
     line = ":%02X%04X%02X" % (len(data), address, record_type)
@@ -89,6 +109,8 @@ class SimpleMemoryTest(DeleteServer):
         self.gdb.command("target extended-remote localhost:%d" % self.server.port)
 
     def access_test(self, size, data_type):
+        self.assertEqual(self.gdb.p("sizeof(%s)" % data_type),
+                size)
         a = 0x86753095555aaaa & ((1<<(size*8))-1)
         b = 0xdeadbeef12345678 & ((1<<(size*8))-1)
         self.gdb.p("*((%s*)0x%x) = 0x%x" % (data_type, target.ram, a))
@@ -103,7 +125,7 @@ class SimpleMemoryTest(DeleteServer):
         self.access_test(2, 'short')
 
     def test_32(self):
-        self.access_test(4, 'long')
+        self.access_test(4, 'int')
 
     def test_64(self):
         self.access_test(8, 'long long')
@@ -121,7 +143,7 @@ class SimpleMemoryTest(DeleteServer):
 
         self.gdb.command("restore write.ihex 0x%x" % target.ram)
         for offset in range(0, length, 19*4) + [length-4]:
-            value = self.gdb.p("*((long*)0x%x)" % (target.ram + offset))
+            value = self.gdb.p("*((int*)0x%x)" % (target.ram + offset))
             written = ord(data[offset]) | \
                     (ord(data[offset+1]) << 8) | \
                     (ord(data[offset+2]) << 16) | \
@@ -143,11 +165,11 @@ class InstantHaltTest(DeleteServer):
         self.gdb.command("target extended-remote localhost:%d" % self.server.port)
 
     def test_instant_halt(self):
-        self.assertEqual(0x1000, self.gdb.p("$pc"))
-        # For some reason instret resets to 0.
-        self.assertLess(self.gdb.p("$instret"), 8)
-        self.gdb.stepi()
-        self.assertNotEqual(0x1000, self.gdb.p("$pc"))
+        self.assertEqual(target.reset_vector, self.gdb.p("$pc"))
+        # mcycle and minstret have no defined reset value.
+        mstatus = self.gdb.p("$mstatus")
+        self.assertEqual(mstatus & (MSTATUS_MIE | MSTATUS_MPRV |
+            MSTATUS_VM), 0)
 
     def test_change_pc(self):
         """Change the PC right as we come out of reset."""
@@ -238,6 +260,9 @@ class DebugTest(DeleteServer):
         self.exit()
 
     def test_hwbp_1(self):
+        if target.instruction_hardware_breakpoint_count < 1:
+            return
+
         self.gdb.hbreak("rot13")
         # The breakpoint should be hit exactly 2 times.
         for i in range(2):
@@ -248,6 +273,9 @@ class DebugTest(DeleteServer):
         self.exit()
 
     def test_hwbp_2(self):
+        if target.instruction_hardware_breakpoint_count < 2:
+            return
+
         self.gdb.hbreak("main")
         self.gdb.hbreak("rot13")
         # We should hit 3 breakpoints.
@@ -450,6 +478,8 @@ class Spike64Target(Target):
     xlen = 64
     ram = 0x80010000
     ram_size = 5 * 1024 * 1024
+    instruction_hardware_breakpoint_count = 0
+    reset_vector = 0x1000
 
     def server(self):
         return testlib.Spike(parsed.cmd, halted=True)
@@ -460,6 +490,8 @@ class Spike32Target(Target):
     xlen = 32
     ram = 0x80010000
     ram_size = 5 * 1024 * 1024
+    instruction_hardware_breakpoint_count = 0
+    reset_vector = 0x1000
 
     def server(self):
         return testlib.Spike(parsed.cmd, halted=True, xlen=32)
@@ -469,6 +501,7 @@ class MicroSemiTarget(Target):
     xlen = 32
     ram = 0x80000000
     ram_size = 16 * 1024
+    instruction_hardware_breakpoint_count = 2
 
     def server(self):
         return testlib.Openocd(cmd=parsed.cmd,