+gdb_cmd = None
+class GdbTest(BaseTest):
+ def __init__(self, target, hart=None):
+ BaseTest.__init__(self, target, hart=hart)
+ self.gdb = None
+
+ def classSetup(self):
+ BaseTest.classSetup(self)
+
+ if gdb_cmd:
+ self.gdb = Gdb(gdb_cmd)
+ else:
+ self.gdb = Gdb()
+
+ self.logs.append(self.gdb.logname)
+
+ if self.binary:
+ self.gdb.command("file %s" % self.binary)
+ if self.target:
+ self.gdb.command("set arch riscv:rv%d" % self.hart.xlen)
+ self.gdb.command("set remotetimeout %d" % self.target.timeout_sec)
+ if self.server.port:
+ self.gdb.command(
+ "target extended-remote localhost:%d" % self.server.port)
+ self.gdb.select_hart(self.hart)
+
+ for cmd in self.target.gdb_setup:
+ self.gdb.command(cmd)
+
+ # FIXME: OpenOCD doesn't handle PRIV now
+ #self.gdb.p("$priv=3")
+
+ def classTeardown(self):
+ del self.gdb
+ BaseTest.classTeardown(self)
+
+class GdbSingleHartTest(GdbTest):
+ def classSetup(self):
+ GdbTest.classSetup(self)
+
+ for hart in self.target.harts:
+ # Park all harts that we're not using in a safe place.
+ if hart != self.hart:
+ self.gdb.select_hart(hart)
+ self.gdb.p("$pc=loop_forever")
+ self.gdb.select_hart(self.hart)
+
+class ExamineTarget(GdbTest):
+ def test(self):
+ self.target.misa = self.gdb.p("$misa")
+
+ txt = "RV"
+ if (self.target.misa >> 30) == 1:
+ txt += "32"
+ elif (self.target.misa >> 62) == 2:
+ txt += "64"
+ elif (self.target.misa >> 126) == 3:
+ txt += "128"
+ else:
+ raise TestFailed("Couldn't determine XLEN from $misa (0x%x)" %
+ self.target.misa)
+
+ for i in range(26):
+ if self.target.misa & (1<<i):
+ txt += chr(i + ord('A'))
+ print txt,
+