From 785eee0d8cdfad335f116aaa79ee49f695dbda7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E9=95=87?= Date: Fri, 1 Mar 2024 10:45:28 +0800 Subject: [PATCH] Enable HwbpManual MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 梁镇 Change-Id: I2ee8718f03d6e381369b7d3bb0222563789ed525 --- debug/gdbserver.py | 36 ++++++++++++++++++++---------------- debug/targets.py | 6 ------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/debug/gdbserver.py b/debug/gdbserver.py index 5450adb1e..6cdaee390 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -613,11 +613,10 @@ def early_applicable(self): return self.hart.instruction_hardware_breakpoint_count > 0 def test(self): - if not self.hart.honors_tdata1_hmode: - # Run to main before setting the breakpoint, because startup code - # will otherwise clear the trigger that we set. - self.gdb.b("main") - self.gdb.c() + # Run to main before setting the breakpoint, because startup code + # will otherwise clear the trigger that we set. + self.gdb.b("main") + self.gdb.c() self.gdb.command("delete") self.gdb.hbreak("rot13") @@ -630,8 +629,10 @@ def test(self): self.gdb.b("_exit") self.exit() -def MCONTROL_TYPE(xlen): - return 0xf<<((xlen)-4) +def MCONTROL_TYPE(version, xlen): + if version == 0x3: + return 0x6<<((xlen)-4) + return 0x2<<((xlen)-4) def MCONTROL_DMODE(xlen): return 1<<((xlen)-5) def MCONTROL_MASKMAX(xlen): @@ -677,15 +678,18 @@ def early_applicable(self): self.hart.instruction_hardware_breakpoint_count >= 1 def test(self): - if not self.hart.honors_tdata1_hmode: - # Run to main before setting the breakpoint, because startup code - # will otherwise clear the trigger that we set. - self.gdb.b("main") - self.gdb.c() + # Run to main before setting the breakpoint, because startup code + # will otherwise clear the trigger that we set. + self.gdb.b("main") + self.gdb.c() self.gdb.command("delete") #self.gdb.hbreak("rot13") - tdata1 = MCONTROL_DMODE(self.hart.xlen) + xlen = self.hart.xlen + dmstatus = self.gdb.command("monitor riscv dmi_read 0x11") + dmstatus_version = int(dmstatus, 16) & 0xf + tdata1 = MCONTROL_TYPE(dmstatus_version, xlen) + tdata1 |= MCONTROL_DMODE(xlen) tdata1 = set_field(tdata1, MCONTROL_ACTION, MCONTROL_ACTION_DEBUG_MODE) tdata1 = set_field(tdata1, MCONTROL_MATCH, MCONTROL_MATCH_EQUAL) tdata1 |= MCONTROL_M | MCONTROL_S | MCONTROL_U | MCONTROL_EXECUTE @@ -697,7 +701,7 @@ def test(self): if value != tselect: raise TestNotApplicable self.gdb.p(f"$tdata1=0x{tdata1:x}") - value = self.gdb.p("$tselect") + value = self.gdb.p("$tdata1") if value == tdata1: break self.gdb.p("$tdata1=0") @@ -710,6 +714,7 @@ def test(self): self.gdb.p("$pc") assertRegex(output, r"[bB]reakpoint") assertIn("rot13 ", output) + self.gdb.stepi() self.gdb.p("$tdata2=&crc32a") self.gdb.c() before = self.gdb.p("$pc") @@ -1396,8 +1401,7 @@ def test(self): class TriggerDmode(TriggerTest): def early_applicable(self): - return self.hart.honors_tdata1_hmode and \ - self.hart.instruction_hardware_breakpoint_count > 0 + return self.hart.instruction_hardware_breakpoint_count > 0 def check_triggers(self, tdata1_lsbs, tdata2): dmode = 1 << (self.hart.xlen-5) diff --git a/debug/targets.py b/debug/targets.py index bb7a5cf15..ff861e6df 100644 --- a/debug/targets.py +++ b/debug/targets.py @@ -19,12 +19,6 @@ class Hart: # defined. Defaults to .lds. link_script_path = None - # Implements dmode in tdata1 as described in the spec. Harts that need - # this value set to False are not compliant with the spec (but still usable - # as long as running code doesn't try to mess with triggers set by an - # external debugger). - honors_tdata1_hmode = True - # Address where a r/w/x block of RAM starts, together with its size. ram = None ram_size = None