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)
1  2 
debug/targets.py
debug/testlib.py

diff --combined debug/targets.py
index 5ac62a83de518f934f89aca4ef7733d38ad53861,043652cdbeca7732298da1ddb26045db232a61a8..f2728d1aed30db7ff7cdecf1f100e026f06d1577
@@@ -68,21 -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):
@@@ -100,7 -99,7 +100,7 @@@ class HiFive1Target(FreedomE300Target)
  class FreedomE300SimTarget(Target):
      name = "freedom-e300-sim"
      xlen = 32
-     timeout_sec = 240
+     timeout_sec = 6000
      ram = 0x80000000
      ram_size = 256 * 1024 * 1024
      instruction_hardware_breakpoint_count = 2
@@@ -120,7 -119,7 +120,7 @@@ class FreedomU500Target(Target)
  class FreedomU500SimTarget(Target):
      name = "freedom-u500-sim"
      xlen = 64
-     timeout_sec = 240
+     timeout_sec = 6000
      ram = 0x80000000
      ram_size = 256 * 1024 * 1024
      instruction_hardware_breakpoint_count = 2
diff --combined debug/testlib.py
index 392772291f2ffa633b38b9d462dcec1005a59941,9889bad15121c9a5b057e02722b373c022b0cb75..71bd60966abdab6cb5ab8298de91e49db3b67418
@@@ -19,8 -19,14 +19,14 @@@ def find_file(path)
      return None
  
  def compile(args, xlen=32): # pylint: disable=redefined-builtin
-     cc = os.path.expandvars("$RISCV/bin/riscv%d-unknown-elf-gcc" % xlen)
+     cc = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gcc")
      cmd = [cc, "-g"]
+     if (xlen == 32):
+         cmd.append("-march=rv32imac")
+         cmd.append("-mabi=ilp32")
+     else:
+         cmd.append("-march=rv64imac")
+         cmd.append("-mabi=lp64")        
      for arg in args:
          found = find_file(arg)
          if found:
@@@ -28,7 -34,7 +34,7 @@@
          else:
              cmd.append(arg)
      process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
-             stderr=subprocess.PIPE)
+                                stderr=subprocess.PIPE)
      stdout, stderr = process.communicate()
      if process.returncode:
          print
@@@ -51,7 -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."""
@@@ -67,9 -73,9 +73,9 @@@
  
          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:
          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()
@@@ -145,11 -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",
              "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()
          messaged = False
          while True:
              log = open(Openocd.logname).read()
-             if "Examined RISCV core" in log:
+             if "OK GO NOW" in log:
                  break
              if not self.process.poll() is None:
                  raise Exception(
              elif matches:
                  [match] = matches
                  return int(match.group('port'))
-             time.sleep(0.1)
+             time.sleep(1)
          raise Exception("Timed out waiting for gdb server to obtain port.")
  
      def __del__(self):
@@@ -280,15 -267,15 +286,15 @@@ class Gdb(object)
          """Wait for prompt."""
          self.child.expect(r"\(gdb\)")
  
-     def command(self, command, timeout=-1):
+     def command(self, command, timeout=6000):
          self.child.sendline(command)
          self.child.expect("\n", timeout=timeout)
          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:
  
      def interrupt(self):
          self.child.send("\003")
-         self.child.expect(r"\(gdb\)", timeout=60)
+         self.child.expect(r"\(gdb\)", timeout=6000)
          return self.child.before.strip()
  
      def x(self, address, size='w'):
          return output
  
      def load(self):
-         output = self.command("load", timeout=60)
+         output = self.command("load", timeout=6000)
          assert "failed" not in  output
          assert "Transfer rate" in output