+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(self.server.gdb_ports, gdb_cmd,
+ timeout=self.target.timeout_sec, binary=self.binary)
+ else:
+ self.gdb = Gdb(self.server.gdb_ports,
+ timeout=self.target.timeout_sec, binary=self.binary)
+
+ self.logs += self.gdb.lognames()
+ self.gdb.connect()
+
+ self.gdb.global_command("set remotetimeout %d" %
+ self.target.timeout_sec)
+
+ for cmd in self.target.gdb_setup:
+ self.gdb.command(cmd)
+
+ self.gdb.select_hart(self.hart)
+
+ # FIXME: OpenOCD doesn't handle PRIV now
+ #self.gdb.p("$priv=3")
+
+ def postMortem(self):
+ if not self.gdb:
+ return
+ self.gdb.interrupt()
+ self.gdb.command("info registers all", timeout=10)
+
+ 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):
+ for hart in self.target.harts:
+ self.gdb.select_hart(hart)
+
+ hart.misa = self.gdb.p("$misa")
+
+ txt = "RV"
+ misa_xlen = 0
+ if ((hart.misa & 0xFFFFFFFF) >> 30) == 1:
+ misa_xlen = 32
+ elif ((hart.misa & 0xFFFFFFFFFFFFFFFF) >> 62) == 2:
+ misa_xlen = 64
+ elif ((hart.misa & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) >> 126) == 3:
+ misa_xlen = 128
+ else:
+ raise TestFailed("Couldn't determine XLEN from $misa (0x%x)" %
+ self.hart.misa)
+
+ if misa_xlen != hart.xlen:
+ raise TestFailed("MISA reported XLEN of %d but we were "\
+ "expecting XLEN of %d\n" % (misa_xlen, hart.xlen))
+
+ txt += ("%d" % misa_xlen)
+
+ for i in range(26):
+ if hart.misa & (1<<i):
+ txt += chr(i + ord('A'))
+ print txt,
+