Skip to content

Commit

Permalink
Enable HwbpManual
Browse files Browse the repository at this point in the history
Signed-off-by: 梁镇 <[email protected]>
Change-Id: I2ee8718f03d6e381369b7d3bb0222563789ed525
  • Loading branch information
lz-bro committed May 7, 2024
1 parent 67e7759 commit 4f5c95e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
35 changes: 19 additions & 16 deletions debug/gdbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -630,8 +629,9 @@ 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)
def MCONTROL_DMODE(xlen):
return 1<<((xlen)-5)
def MCONTROL_MASKMAX(xlen):
Expand Down Expand Up @@ -677,15 +677,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
Expand All @@ -697,7 +700,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")
Expand All @@ -710,6 +713,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")
Expand Down Expand Up @@ -1396,8 +1400,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)
Expand Down
6 changes: 0 additions & 6 deletions debug/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ class Hart:
# defined. Defaults to <name>.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
Expand Down

0 comments on commit 4f5c95e

Please sign in to comment.