Skip to content

Commit 6dd13e0

Browse files
SFangYyyaozhicheng
andauthored
fix(pdb): resolve API incompatibility with difftest update (#5314)
This PR cherry-picks commit `5d8095a` from master and updates the code to adapt to the API changes. --------- Co-authored-by: Zhicheng Yao <yaozhicheng@ict.ac.cn>
1 parent 8ec8419 commit 6dd13e0

File tree

3 files changed

+172
-8
lines changed

3 files changed

+172
-8
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ huancun/ @linjuanZ
3737

3838
src/main/scala/top/ @Tang-Haojin
3939

40+
scripts/Makefile.pdb @yaozhicheng @forever043 @SFangYy @Tang-Haojin
4041
scripts/pdb-run.py @yaozhicheng @forever043 @SFangYy @Tang-Haojin
41-
scripts/xspdb/ @yaozhicheng @forever043 @SFangYy @Tang-Haojin
42+
scripts/xspdb/ @yaozhicheng @SFangYy

scripts/xspdb/xscmd/cmd_difftest.py

Lines changed: 169 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ def api_init_ref(self, force=False):
7070
self.df.finish_device()
7171
self.df.GoldenMemFinish()
7272
self.df.difftest_finish()
73-
self.df.difftest_init()
73+
self.api_init_mem()
74+
self.df.difftest_init(True, self.exec_bin_file)
7475
self.difftest_stat = self.df.GetDifftest(0).dut
7576
self.df.init_device()
76-
self.df.GoldenMemInit()
77-
self.df.init_nemuproxy(0)
7877
self.difftest_ref_is_inited = True
7978
return True
8079

@@ -185,14 +184,14 @@ def do_xpc(self, a):
185184

186185
def api_istep_update_commit_pc(self):
187186
old_p = self.condition_instrunct_istep.get("pc_old_list")
188-
new_P = self.condition_instrunct_istep.get("pc_lst_list")
189-
if not (old_p and new_P):
187+
new_p = self.condition_instrunct_istep.get("pc_lst_list")
188+
if not (old_p and new_p):
190189
self.istep_last_commit_pc = []
191190
else:
192191
self.istep_last_commit_pc = []
193192
for i in range(8):
194193
old_pc = int.from_bytes(old_p[i].AsBytes(), byteorder='little', signed=False)
195-
new_pc = int.from_bytes(new_P[i].AsBytes(), byteorder='little', signed=False)
194+
new_pc = int.from_bytes(new_p[i].AsBytes(), byteorder='little', signed=False)
196195
if old_pc != new_pc:
197196
self.istep_last_commit_pc.append(new_pc)
198197

@@ -326,3 +325,167 @@ def api_difftest_get_instance(self, instance=0):
326325
"""
327326
return self.df.GetDifftest(instance)
328327

328+
def do_xdifftest_turn_on(self, arg):
329+
"""Turn on the difftest diff
330+
331+
Args:
332+
arg (string): Turn on or off
333+
"""
334+
if arg.strip() == "on":
335+
self.api_set_difftest_diff(True)
336+
elif arg.strip() == "off":
337+
self.api_set_difftest_diff(False)
338+
else:
339+
error("usage: xdifftest_turn_on <on|off>")
340+
341+
def complete_xdifftest_turn_on(self, text, line, begidx, endidx):
342+
return [x for x in ["on", "off"] if x.startswith(text)] if text else ["on", "off"]
343+
344+
def do_xdifftest_turn_on_with_ref(self, arg):
345+
"""Turn on the difftest diff with reference so
346+
Args:
347+
arg (string): ref so path
348+
"""
349+
if self.difftest_ref_is_inited:
350+
error("difftest reference already inited")
351+
return
352+
if not arg.strip():
353+
error("difftest ref so path not found\n usage: xdifftest_turn_on_with_ref <path>")
354+
return
355+
if not self.api_load_ref_so(arg):
356+
error(f"load difftest ref so {arg} failed")
357+
return
358+
self.api_set_difftest_diff(True)
359+
360+
def complete_xdifftest_turn_on_with_ref(self, text, line, begidx, endidx):
361+
return self.api_complite_localfile(text)
362+
363+
def do_xexpdiffstate(self, var):
364+
"""Set a variable to difftest_stat
365+
366+
Args:
367+
var (string): Variable name
368+
"""
369+
self.curframe.f_locals[var] = self.difftest_stat
370+
371+
def do_xwatch_commit_pc(self, arg):
372+
"""Watch commit PC
373+
374+
Args:
375+
arg (address): PC address
376+
"""
377+
if arg.strip() == "update":
378+
checker = self.condition_watch_commit_pc.get("checker")
379+
if checker:
380+
checker.Reset()
381+
return
382+
try:
383+
address = int(arg, 0)
384+
except Exception as e:
385+
error(f"convert {arg} to number fail: {str(e)}")
386+
return
387+
388+
if not self.condition_watch_commit_pc.get("checker"):
389+
checker = self.xsp.ComUseCondCheck(self.dut.xclock)
390+
cmtpccmp = self.xsp.ComUseRangeCheck(6, 8);
391+
self.condition_watch_commit_pc["checker"] = checker
392+
self.condition_watch_commit_pc["cmtpcmp"] = cmtpccmp
393+
394+
checker = self.condition_watch_commit_pc["checker"]
395+
if "watch_pc_0x%x_0"%address not in checker.ListCondition():
396+
cmtpccmp = self.condition_watch_commit_pc["cmtpcmp"]
397+
target_pc = self.xsp.ComUseDataArray(8)
398+
target_pc.FromBytes(address.to_bytes(8, byteorder='little', signed=False))
399+
pc_lst_list = [self.xsp.ComUseDataArray(self.difftest_stat.get_commit(i).get_pc_address(), 8) for i in range(8)]
400+
for i, lpc in enumerate(pc_lst_list):
401+
checker.SetCondition("watch_pc_0x%x_%d" % (address, i), lpc.BaseAddr(), target_pc.BaseAddr(), self.xsp.ComUseCondCmp_GE, 8,
402+
0, 0, 1, cmtpccmp.GetArrayCmp(), cmtpccmp.CSelf())
403+
checker.SetMaxCbs(1)
404+
self.condition_watch_commit_pc["0x%x"%address] = {"pc_lst_list": pc_lst_list, "target_pc": target_pc}
405+
else:
406+
error(f"watch_commit_pc 0x{address:x} already exists")
407+
return
408+
cb_key = "watch_commit_pc"
409+
self.dut.xclock.RemoveStepRisCbByDesc(cb_key)
410+
self.dut.xclock.StepRis(checker.GetCb(), checker.CSelf(), cb_key)
411+
message(f"watch commit pc: 0x{address:x}")
412+
413+
def do_xunwatch_commit_pc(self, arg):
414+
"""Unwatch commit PC
415+
416+
Args:
417+
arg (address): PC address
418+
"""
419+
try:
420+
address = int(arg, 0)
421+
except Exception as e:
422+
error(f"convert {arg} to number fail: {str(e)}")
423+
return
424+
checker = self.condition_watch_commit_pc.get("checker")
425+
if not checker:
426+
error("watch_commit_pc.checker not found")
427+
return
428+
if "watch_pc_0x%x_0"%address not in checker.ListCondition():
429+
error(f"watch_commit_pc 0x{address:x} not found")
430+
return
431+
key = "0x%x"%address
432+
if key in self.condition_watch_commit_pc:
433+
# remove cached entry for this watch target if present
434+
self.condition_watch_commit_pc.pop(key, None)
435+
for i in range(8):
436+
checker.RemoveCondition("watch_pc_0x%x_%d" % (address, i))
437+
if len(checker.ListCondition()) < 1:
438+
self.dut.xclock.RemoveStepRisCbByDesc("watch_commit_pc")
439+
assert "watch_commit_pc" not in self.dut.xclock.ListSteRisCbDesc()
440+
self.condition_watch_commit_pc.clear()
441+
message("No commit pc to watch, remove checker")
442+
443+
def do_xdifftest_display(self, arg):
444+
"""Display the difftest status
445+
446+
Args:
447+
arg (number): difftest instance to display, default is 0
448+
"""
449+
instance = 0
450+
if arg.strip():
451+
try:
452+
instance = int(arg)
453+
except Exception as e:
454+
error(f"convert {arg} to number fail: {str(e)}\n usage: xdifftest_display [instance]")
455+
return
456+
if not self.difftest_ref_is_inited:
457+
error("difftest reference not inited")
458+
return
459+
x = self.api_difftest_get_instance(instance)
460+
if x:
461+
x.display()
462+
else:
463+
error(f"difftest instance {instance} not found")
464+
465+
def do_xdifftest_pmem_base_first_instr_address(self, arg):
466+
"""Display or set PMEM_BASE, FIRST_INST_ADDRESS
467+
468+
Args:
469+
PMEM_BASE (int): PMEM_BASE value default None
470+
FIRST_INST_ADDRESS (int): FIRST_INST_ADDRESS value default None
471+
"""
472+
a, b = None, None
473+
str_usage = "usage xdifftest_pmem_base_first_instr_address [PMEM_BASE FIRST_INST_ADDRESS]"
474+
if arg.strip():
475+
args = arg.split()
476+
if len(args) != 2:
477+
error(str_usage)
478+
return
479+
try:
480+
a, b = int(args[0], 0), int(args[1], 0)
481+
except Exception as e:
482+
error("Error: %s\n%s"%(e, str_usage))
483+
return
484+
x, y = self.api_update_pmem_base_and_first_inst_addr(a, b)
485+
if (a is not None) and (b is not None):
486+
message("PMEM_BASE = %s, FIRST_INST_ADDRESS = %s" % (hex(x), hex(y)))
487+
elif (a and a != x) or (b and b != y):
488+
error("Set PMEM_BASE(%s != %s), FIRST_INST_ADDRESS(%s != %s) fail!" % (a, x, b, y))
489+
else:
490+
message("PMEM_BASE = %s, FIRST_INST_ADDRESS = %s" % (hex(x), hex(y)))
491+
error(str_usage)

scripts/xspdb/xspdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(self, dut, default_file=None,
8484
self.df.InitFlash("")
8585
self.xspdb_init_bin = "xspdb_flash_init.bin"
8686
self.flash_bin_file = None
87-
self.df.difftest_init(True, self.mem_size)
87+
self.df.difftest_init(False, self.mem_size)
8888
self.difftest_stat = df.GetDifftest(0).dut
8989
self.difftest_flash = df.GetFlash()
9090
self.register_map = OrderedDict()

0 commit comments

Comments
 (0)