Merge remote-tracking branch 'origin/newprogram' into debug-0.13
authorMegan Wachs <megan@sifive.com>
Mon, 17 Apr 2017 18:34:33 +0000 (11:34 -0700)
committerMegan Wachs <megan@sifive.com>
Mon, 17 Apr 2017 18:34:33 +0000 (11:34 -0700)
debug/Makefile
debug/gdbserver.py
debug/targets.py
debug/targets/spike/openocd.cfg [new file with mode: 0644]
debug/testlib.py
isa/rv64mi/illegal.S

index 56db73178201087e6817e5af7a0d35d0887347d2..79e89cbe397d912d024a26cdb09ddd081491c02f 100644 (file)
@@ -12,7 +12,7 @@ pylint:
        pylint --rcfile=pylint.rc *.py
 
 %.log:
-       $(GDBSERVER_PY) --isolate --$(subst .log,,$@) --cmd $(RISCV_SIM) \
+       $(GDBSERVER_PY) --isolate --$(subst .log,,$@) \
            > $@ 2>&1 || (sed s/^/$@:\ / $@ && false)
 
 clean:
index 3d4533e1393960787ede1ac4c6067d74c5d757be..6690ad92c85f1dfbe6fbc9c614a073478253acac 100755 (executable)
@@ -6,6 +6,7 @@ import random
 import sys
 import tempfile
 import time
+import os
 
 import targets
 import testlib
@@ -571,38 +572,41 @@ class DownloadTest(GdbTest):
     def setup(self):
         # pylint: disable=attribute-defined-outside-init
         length = min(2**20, self.target.ram_size - 2048)
-        download_c = tempfile.NamedTemporaryFile(prefix="download_",
-                suffix=".c")
-        download_c.write("#include <stdint.h>\n")
-        download_c.write(
+        self.download_c = tempfile.NamedTemporaryFile(prefix="download_",
+                suffix=".c", delete=False)
+        self.download_c.write("#include <stdint.h>\n")
+        self.download_c.write(
                 "unsigned int crc32a(uint8_t *message, unsigned int size);\n")
-        download_c.write("uint32_t length = %d;\n" % length)
-        download_c.write("uint8_t d[%d] = {\n" % length)
+        self.download_c.write("uint32_t length = %d;\n" % length)
+        self.download_c.write("uint8_t d[%d] = {\n" % length)
         self.crc = 0
+        assert length % 16 == 0
         for i in range(length / 16):
-            download_c.write("  /* 0x%04x */ " % (i * 16))
+            self.download_c.write("  /* 0x%04x */ " % (i * 16))
             for _ in range(16):
                 value = random.randrange(1<<8)
-                download_c.write("%d, " % value)
+                self.download_c.write("0x%02x, " % value)
                 self.crc = binascii.crc32("%c" % value, self.crc)
-            download_c.write("\n")
-        download_c.write("};\n")
-        download_c.write("uint8_t *data = &d[0];\n")
-        download_c.write("uint32_t main() { return crc32a(data, length); }\n")
-        download_c.flush()
+            self.download_c.write("\n")
+        self.download_c.write("};\n")
+        self.download_c.write("uint8_t *data = &d[0];\n")
+        self.download_c.write(
+                "uint32_t main() { return crc32a(data, length); }\n")
+        self.download_c.flush()
 
         if self.crc < 0:
             self.crc += 2**32
 
-        self.binary = self.target.compile(download_c.name,
+        self.binary = self.target.compile(self.download_c.name,
                 "programs/checksum.c")
         self.gdb.command("file %s" % self.binary)
 
     def test(self):
         self.gdb.load()
         self.gdb.command("b _exit")
-        self.gdb.c()
+        self.gdb.c(timeout=60)
         assertEqual(self.gdb.p("status"), self.crc)
+        os.unlink(self.download_c.name)
 
 class MprvTest(GdbTest):
     compile_args = ("programs/mprv.S", )
index 043652cdbeca7732298da1ddb26045db232a61a8..f2728d1aed30db7ff7cdecf1f100e026f06d1577 100644 (file)
@@ -68,20 +68,21 @@ class SpikeTarget(Target):
     ram_size = 5 * 1024 * 1024
     instruction_hardware_breakpoint_count = 4
     reset_vector = 0x1000
+    openocd_config = "targets/%s/openocd.cfg" % directory
 
 class Spike64Target(SpikeTarget):
     name = "spike64"
     xlen = 64
     use_fpu = True
 
-    def server(self):
+    def target(self):
         return testlib.Spike(self.cmd, halted=True)
 
 class Spike32Target(SpikeTarget):
     name = "spike32"
     xlen = 32
 
-    def server(self):
+    def target(self):
         return testlib.Spike(self.cmd, halted=True, xlen=32)
 
 class FreedomE300Target(Target):
diff --git a/debug/targets/spike/openocd.cfg b/debug/targets/spike/openocd.cfg
new file mode 100644 (file)
index 0000000..5389da8
--- /dev/null
@@ -0,0 +1,17 @@
+adapter_khz     10000
+
+interface remote_bitbang
+remote_bitbang_host $::env(REMOTE_BITBANG_HOST)
+remote_bitbang_port $::env(REMOTE_BITBANG_PORT)
+
+set _CHIPNAME riscv
+jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x10e31913
+
+set _TARGETNAME $_CHIPNAME.cpu
+target create $_TARGETNAME riscv -chain-position $_TARGETNAME
+
+gdb_report_data_abort enable
+
+init
+
+halt
index 9889bad15121c9a5b057e02722b373c022b0cb75..71bd60966abdab6cb5ab8298de91e49db3b67418 100644 (file)
@@ -57,7 +57,7 @@ def unused_port():
 class Spike(object):
     logname = "spike.log"
 
-    def __init__(self, cmd, binary=None, halted=False, with_gdb=True,
+    def __init__(self, cmd, binary=None, halted=False, with_jtag_gdb=True,
             timeout=None, xlen=64):
         """Launch spike. Return tuple of its process and the port it's running
         on."""
@@ -73,9 +73,9 @@ class Spike(object):
 
         if halted:
             cmd.append('-H')
-        if with_gdb:
-            self.port = unused_port()
-            cmd += ['--gdb-port', str(self.port)]
+        if with_jtag_gdb:
+            cmd += ['--rbb-port', '0']
+            os.environ['REMOTE_BITBANG_HOST'] = 'localhost'
         cmd.append("-m32")
         cmd.append('pk')
         if binary:
@@ -86,6 +86,19 @@ class Spike(object):
         self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                 stdout=logfile, stderr=logfile)
 
+        if with_jtag_gdb:
+            self.port = None
+            for _ in range(30):
+                m = re.search(r"Listening for remote bitbang connection on "
+                        r"port (\d+).", open(self.logname).read())
+                if m:
+                    self.port = int(m.group(1))
+                    os.environ['REMOTE_BITBANG_PORT'] = m.group(1)
+                    break
+                time.sleep(0.11)
+            assert self.port, "Didn't get spike message about bitbang " \
+                    "connection"
+
     def __del__(self):
         try:
             self.process.kill()
@@ -138,15 +151,11 @@ class Openocd(object):
         if cmd:
             cmd = shlex.split(cmd)
         else:
-            cmd = ["openocd"]
-        if config:
-            cmd += ["-f", find_file(config)]
-        if debug:
-            cmd.append("-d")
+            cmd = ["openocd", "-d"]
 
         # This command needs to come before any config scripts on the command
         # line, since they are executed in order.
-        cmd[1:1] = [
+        cmd += [
             # Tell OpenOCD to bind gdb to an unused, ephemeral port.
             "--command",
             "gdb_port 0",
@@ -159,6 +168,16 @@ class Openocd(object):
             "telnet_port disabled",
         ]
 
+        if config:
+            f = find_file(config)
+            if f is None:
+                print("Unable to read file " + config)
+                exit(1)
+
+            cmd += ["-f", f]
+        if debug:
+            cmd.append("-d")
+
         logfile = open(Openocd.logname, "w")
         logfile.write("+ %s\n" % " ".join(cmd))
         logfile.flush()
@@ -273,9 +292,9 @@ class Gdb(object):
         self.child.expect(r"\(gdb\)", timeout=timeout)
         return self.child.before.strip()
 
-    def c(self, wait=True):
+    def c(self, wait=True, timeout=-1):
         if wait:
-            output = self.command("c")
+            output = self.command("c", timeout=timeout)
             assert "Continuing" in output
             return output
         else:
index 30105e68d61df08741e14d560e35fb736bb150e3..a1b445f0df08c7b3b47ab9b9fe41d62f4e115d08 100644 (file)
@@ -21,6 +21,15 @@ bad2:
   .word 0
   j fail
 
+  # Skip the rest of the test if S-mode is not present.
+  li t0, MSTATUS_MPP
+  csrc mstatus, t0
+  li t1, (MSTATUS_MPP & -MSTATUS_MPP) * PRV_S
+  csrs mstatus, t1
+  csrr t2, mstatus
+  and t2, t2, t0
+  bne t1, t2, pass
+
   # Test vectored interrupts if they are supported.
 test_vectored_interrupts:
   csrwi mip, MIP_SSIP
@@ -33,23 +42,18 @@ test_vectored_interrupts:
   csrsi mstatus, MSTATUS_MIE
 1:
   j 1b
-
 msip:
   csrw mtvec, s0
 
-  # Skip the rest of the test if S-mode is not present.
-  li t0, MSTATUS_MPP
-  csrc mstatus, t0
-  li t1, (MSTATUS_MPP & -MSTATUS_MPP) * PRV_S
-  csrs mstatus, t1
-  csrr t2, mstatus
-  and t2, t2, t0
-  bne t1, t2, pass
-
   # Delegate supervisor software interrupts so WFI won't stall.
   csrwi mideleg, MIP_SSIP
+  # Enter supervisor mode.
   la t0, 1f
   csrw mepc, t0
+  li t0, MSTATUS_MPP
+  csrc mstatus, t0
+  li t1, (MSTATUS_MPP & -MSTATUS_MPP) * PRV_S
+  csrs mstatus, t1
   mret
 
 1: