From 5ee2425151112bd7d17afc6321a1fbf9efd21116 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 8 Oct 2018 15:47:09 -0700 Subject: Tweak debug tests to run out of flash. Not all tests pass when run out of flash yet, but it's getting a lot closer. The ones still failing on HiFive1-flash are: DebugSymbols, Hwbp2, InstantHaltTest, TriggerDmode, TriggerLoadAddressInstant, and TriggerStoreAddressInstant. --- debug/gdbserver.py | 15 +++++++++------ debug/programs/debug.c | 5 ++++- debug/programs/regs.S | 1 + debug/testlib.py | 4 +++- 4 files changed, 17 insertions(+), 8 deletions(-) (limited to 'debug') diff --git a/debug/gdbserver.py b/debug/gdbserver.py index b6e7cf9..783fdc7 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -921,9 +921,12 @@ class RegsTest(GdbSingleHartTest): compile_args = ("programs/regs.S", ) def setup(self): self.gdb.load() - self.gdb.b("main") + main_bp = self.gdb.b("main") + output = self.gdb.c() + assertIn("Breakpoint ", output) + assertIn("main", output) + self.gdb.command("delete %d" % main_bp) self.gdb.b("handle_trap") - self.gdb.c() class WriteGprs(RegsTest): def test(self): @@ -932,16 +935,16 @@ class WriteGprs(RegsTest): self.gdb.p("$pc=write_regs") for i, r in enumerate(regs): self.gdb.p("$%s=%d" % (r, (0xdeadbeef< Date: Wed, 10 Oct 2018 09:40:40 -0700 Subject: Almost all tests pass with HiFive1-flash Only TriggerDmode still fails. --- debug/gdbserver.py | 15 ++++++++++++--- debug/programs/trigger.S | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'debug') diff --git a/debug/gdbserver.py b/debug/gdbserver.py index 783fdc7..fbd8ce2 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -433,12 +433,14 @@ class DebugExit(DebugTest): class DebugSymbols(DebugTest): def test(self): - self.gdb.b("main") - self.gdb.b("rot13") + bp = self.gdb.b("main") output = self.gdb.c() assertIn(", main ", output) + self.gdb.command("delete %d" % bp) + bp = self.gdb.b("rot13") output = self.gdb.c() assertIn(", rot13 ", output) + self.gdb.command("delete %d" % bp) class DebugBreakpoint(DebugTest): def test(self): @@ -462,6 +464,7 @@ class Hwbp1(DebugTest): self.gdb.b("main") self.gdb.c() + self.gdb.command("delete") self.gdb.hbreak("rot13") # The breakpoint should be hit exactly 2 times. for _ in range(2): @@ -469,6 +472,7 @@ class Hwbp1(DebugTest): self.gdb.p("$pc") assertRegexpMatches(output, r"[bB]reakpoint") assertIn("rot13 ", output) + self.gdb.b("_exit") self.exit() class Hwbp2(DebugTest): @@ -476,6 +480,7 @@ class Hwbp2(DebugTest): if self.hart.instruction_hardware_breakpoint_count < 2: return 'not_applicable' + self.gdb.command("delete") self.gdb.hbreak("main") self.gdb.hbreak("rot13") # We should hit 3 breakpoints. @@ -484,6 +489,8 @@ class Hwbp2(DebugTest): self.gdb.p("$pc") assertRegexpMatches(output, r"[bB]reakpoint") assertIn("%s " % expected, output) + self.gdb.command("delete") + self.gdb.b("_exit") self.exit() class TooManyHwbp(DebugTest): @@ -799,11 +806,13 @@ class TriggerTest(GdbSingleHartTest): compile_args = ("programs/trigger.S", ) def setup(self): self.gdb.load() - self.gdb.b("_exit") self.gdb.b("main") self.gdb.c() + self.gdb.command("delete") def exit(self): + self.gdb.command("delete") + self.gdb.b("_exit") output = self.gdb.c() assertIn("Breakpoint", output) assertIn("_exit", output) diff --git a/debug/programs/trigger.S b/debug/programs/trigger.S index 13f0449..2ccfd21 100644 --- a/debug/programs/trigger.S +++ b/debug/programs/trigger.S @@ -93,7 +93,7 @@ read_triggers: 1: SREG zero, 0(a0) ret - .data + .section .data .align 3 data: .word 0x40 .word 0x41 -- cgit v1.1 From b3c5d7a07f2a08d11f316c39d6cce5374cdcbfd3 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Wed, 31 Oct 2018 14:31:21 -0700 Subject: Fix remaining tests to work from flash: TriggerDmode, ProgramHwWatchpoint, ProgramSwWatchpoint. --- debug/gdbserver.py | 16 ++++++++++++---- debug/testlib.py | 7 +++++-- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'debug') diff --git a/debug/gdbserver.py b/debug/gdbserver.py index fbd8ce2..d2d4dbc 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -311,9 +311,10 @@ class ProgramTest(GdbSingleHartTest): def setup(self): self.gdb.load() - self.gdb.b("_exit") def exit(self, expected_result=10): + self.gdb.command("delete") + self.gdb.b("_exit") output = self.gdb.c() assertIn("Breakpoint", output) assertIn("_exit", output) @@ -321,10 +322,11 @@ class ProgramTest(GdbSingleHartTest): class ProgramHwWatchpoint(ProgramTest): def test(self): - self.gdb.b("main") + mainbp = self.gdb.b("main") output = self.gdb.c() assertIn("Breakpoint", output) assertIn("main", output) + self.gdb.command("delete %d" % mainbp) self.gdb.watch("counter == 5") # Watchpoint hits when counter becomes 5. output = self.gdb.c() @@ -498,7 +500,7 @@ class TooManyHwbp(DebugTest): for i in range(30): self.gdb.hbreak("*rot13 + %d" % (i * 4)) - output = self.gdb.c() + output = self.gdb.c(checkOutput=False) assertIn("Cannot insert hardware breakpoint", output) # Clean up, otherwise the hardware breakpoints stay set and future # tests may fail. @@ -916,15 +918,21 @@ class TriggerDmode(TriggerTest): return triggers def test(self): + # If we want this test to run from flash, we can't have any software + # breakpoints set. + self.gdb.command("hbreak write_load_trigger") - self.gdb.b("clear_triggers") self.gdb.p("$pc=write_store_trigger") output = self.gdb.c() assertIn("write_load_trigger", output) self.check_triggers((1<<6) | (1<<1), 0xdeadbee0) + self.gdb.command("delete") + self.gdb.command("hbreak clear_triggers") output = self.gdb.c() assertIn("clear_triggers", output) self.check_triggers((1<<6) | (1<<0), 0xfeedac00) + self.gdb.command("delete") + self.exit() class RegsTest(GdbSingleHartTest): compile_args = ("programs/regs.S", ) diff --git a/debug/testlib.py b/debug/testlib.py index fa79abe..184bc85 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -463,7 +463,7 @@ class Gdb(object): self.select_child(child) self.command(command) - def c(self, wait=True, async=False): + def c(self, wait=True, async=False, checkOutput=True): """ Dumb c command. In RTOS mode, gdb will resume all harts. @@ -477,7 +477,9 @@ class Gdb(object): ops = 10 if wait: output = self.command("c%s" % async, ops=ops) - assert "Continuing" in output + if checkOutput: + assert "Continuing" in output + assert "Could not insert hardware" not in output return output else: self.active_child.sendline("c%s" % async) @@ -902,6 +904,7 @@ class GdbTest(BaseTest): if not self.gdb: return self.gdb.interrupt() + self.gdb.command("info breakpoints") self.gdb.command("disassemble", ops=20) self.gdb.command("info registers all", ops=100) self.gdb.command("flush regs") -- cgit v1.1 From 8312d916002aae641cb845c0c6591bbab03b2c92 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Wed, 31 Oct 2018 14:33:27 -0700 Subject: Add HiFive1-flash target configuration. --- debug/targets/SiFive/HiFive1-flash.lds | 44 ++++++++++++++++++++++++++++++++++ debug/targets/SiFive/HiFive1-flash.py | 15 ++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 debug/targets/SiFive/HiFive1-flash.lds create mode 100644 debug/targets/SiFive/HiFive1-flash.py (limited to 'debug') diff --git a/debug/targets/SiFive/HiFive1-flash.lds b/debug/targets/SiFive/HiFive1-flash.lds new file mode 100644 index 0000000..e4074be --- /dev/null +++ b/debug/targets/SiFive/HiFive1-flash.lds @@ -0,0 +1,44 @@ +OUTPUT_ARCH( "riscv" ) + +MEMORY +{ + flash (rxl) : ORIGIN = 0x20400000, LENGTH = 128K + ram (wx) : ORIGIN = 0x80000000, LENGTH = 16K +} + +SECTIONS +{ + flash_text : { + *(.text.entry) + *(.text) + } >flash + + /* data segment */ + .data : { *(.data) } >ram + + .sdata : { + __global_pointer$ = . + 0x800; + *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) + *(.srodata*) + *(.sdata .sdata.* .gnu.linkonce.s.*) + } >ram + + /* bss segment */ + __bss_start = .; + .sbss : { + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + } >ram + .bss : { *(.bss) } >ram + __bss_end = .; + + __malloc_start = .; + . = . + 512; + + /* End of uninitalized data segement */ + _end = .; +} + +ENTRY(_start) + +ASSERT(_end < 0x80004000, "program is too large") diff --git a/debug/targets/SiFive/HiFive1-flash.py b/debug/targets/SiFive/HiFive1-flash.py new file mode 100644 index 0000000..06dfcfc --- /dev/null +++ b/debug/targets/SiFive/HiFive1-flash.py @@ -0,0 +1,15 @@ +import targets + +# Like HiFive1, but put code in flash + +class HiFive1FlashHart(targets.Hart): + xlen = 32 + ram = 0x80000000 + ram_size = 16 * 1024 + instruction_hardware_breakpoint_count = 2 + misa = 0x40001105 + link_script_path = "HiFive1-flash.lds" + +class HiFive1Flash(targets.Target): + harts = [HiFive1FlashHart()] + openocd_config_path = "HiFive1.cfg" -- cgit v1.1 From cfab417615b101e1834fe56bcfe9b11b91a6eaea Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 12 Nov 2018 14:07:26 -0800 Subject: Simpler/more idiomatic way to keep string on stack --- debug/programs/debug.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'debug') diff --git a/debug/programs/debug.c b/debug/programs/debug.c index 44b4b51..8a4aa73 100644 --- a/debug/programs/debug.c +++ b/debug/programs/debug.c @@ -53,12 +53,9 @@ int main() volatile int i = 0; int j = 0; - static char fox[43]; + char fox[] = "The quick brown fox jumps of the lazy dog."; unsigned int checksum = 0; - /* fox needs to be writable, but the string could be in ROM. */ - strcpy(fox, "The quick brown fox jumps of the lazy dog."); - start: while (i) j++; -- cgit v1.1