From e9de1c77dda6c191cf871d1ad2b43448e83077b7 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Thu, 20 Jul 2017 20:43:18 -0700 Subject: [PATCH] Add back code to clean up triggers in entry.S Then for targets that can't handle this because they don't implement hmode, add a target setting that allows that to be specified. --- debug/gdbserver.py | 9 +++++++++ debug/programs/entry.S | 9 +++++++++ debug/targets.py | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/debug/gdbserver.py b/debug/gdbserver.py index f6c61c3..80985fd 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -329,6 +329,12 @@ class Hwbp1(DebugTest): if self.target.instruction_hardware_breakpoint_count < 1: return 'not_applicable' + if not self.target.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() + self.gdb.hbreak("rot13") # The breakpoint should be hit exactly 2 times. for _ in range(2): @@ -560,6 +566,9 @@ class TriggerStoreAddressInstant(TriggerTest): assertEqual(self.gdb.p("$a0"), self.gdb.p("&data")) class TriggerDmode(TriggerTest): + def early_applicable(self): + return self.target.honors_tdata1_hmode + def check_triggers(self, tdata1_lsbs, tdata2): dmode = 1 << (self.target.xlen-5) diff --git a/debug/programs/entry.S b/debug/programs/entry.S index 302d409..ff8ae30 100755 --- a/debug/programs/entry.S +++ b/debug/programs/entry.S @@ -64,6 +64,15 @@ handle_reset: # initialize stack pointer la sp, stack_top + # Clear all hardware triggers + li t0, ~0 +1: + addi t0, t0, 1 + csrw CSR_TSELECT, t0 + csrw CSR_TDATA1, zero + csrr t1, CSR_TSELECT + beq t0, t1, 1b + # perform the rest of initialization in C j _init diff --git a/debug/targets.py b/debug/targets.py index ae81517..296b0a9 100644 --- a/debug/targets.py +++ b/debug/targets.py @@ -34,6 +34,12 @@ class Target(object): # before starting the test. gdb_setup = [] + # Implements dmode in tdata1 as described in the spec. Targets 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 + # Internal variables: directory = None temporary_files = [] -- 2.30.2