return None
def compile(args, xlen=32):
- """Compile a single .c file into a binary."""
- dst = os.path.splitext(args[0])[0]
cc = os.path.expandvars("$RISCV/bin/riscv%d-unknown-elf-gcc" % xlen)
- cmd = [cc, "-g", "-o", dst]
+ cmd = [cc, "-g"]
for arg in args:
found = find_file(arg)
if found:
cmd = " ".join(cmd)
result = os.system(cmd)
assert result == 0, "%r failed" % cmd
- return dst
def unused_port():
# http://stackoverflow.com/questions/2838244/get-open-tcp-port-in-python/2838309#2838309
return port
class Spike(object):
- def __init__(self, cmd, binary=None, halted=False, with_gdb=True, timeout=None):
+ def __init__(self, cmd, binary=None, halted=False, with_gdb=True, timeout=None,
+ xlen=64):
"""Launch spike. Return tuple of its process and the port it's running on."""
if cmd:
cmd = shlex.split(cmd)
else:
cmd = ["spike"]
- #cmd.append("-l") #<<<
+ if (xlen == 32):
+ cmd += ["--isa", "RV32"]
if timeout:
cmd = ["timeout", str(timeout)] + cmd
cmd.append(binary)
logfile = open("spike.log", "w")
logfile.write("+ %s\n" % " ".join(cmd))
+ logfile.flush()
self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile,
stderr=logfile)
return self.process.wait(*args, **kwargs)
class Openocd(object):
- def __init__(self, cmd=None, config=None, debug=True):
+ def __init__(self, cmd=None, config=None, debug=False):
if cmd:
cmd = shlex.split(cmd)
else:
if debug:
cmd.append("-d")
logfile = open("openocd.log", "w")
+ logfile.write("+ %s\n" % " ".join(cmd))
self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile,
stderr=logfile)
# TODO: Pick a random port
pass
class Gdb(object):
- def __init__(self):
- path = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")
- self.child = pexpect.spawn(path)
+ def __init__(self,
+ cmd=os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")):
+ self.child = pexpect.spawn(cmd)
self.child.logfile = file("gdb.log", "w")
+ self.child.logfile.write("+ %s\n" % cmd)
self.wait()
+ self.command("set confirm off")
self.command("set width 0")
self.command("set height 0")
# Force consistency.
return output
def load(self):
- output = self.command("load", timeout=120)
+ output = self.command("load", timeout=60)
assert "failed" not in output
assert "Transfer rate" in output
assert "not defined" not in output
assert "Breakpoint" in output
return output
+
+ def hbreak(self, location):
+ output = self.command("hbreak %s" % location)
+ assert "not defined" not in output
+ assert "Hardware assisted breakpoint" in output
+ return output