From 4e3d8df5a8c45c1b3cf3059d0786e947a9f2aba6 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Sun, 13 Dec 2020 20:08:08 -0800 Subject: [PATCH] Preserve abstract s0 write if progbuf excepts. (#615) When a single abstract command writes s0 and executes a program buffer that leads to an exception, the value of s0 should still persist. The fact that it did not masked the following bug in OpenOCD: https://github.com/riscv/riscv-openocd/issues/559 --- riscv/debug_module.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/riscv/debug_module.cc b/riscv/debug_module.cc index 5490d0ed..920166c7 100644 --- a/riscv/debug_module.cc +++ b/riscv/debug_module.cc @@ -661,6 +661,17 @@ bool debug_module_t::perform_abstract_command() return true; } + if (regno == 0x1000 + S0 && write) { + /* + * The exception handler starts out be restoring dscratch to s0, + * which was saved before executing the abstract memory region. Since + * we just wrote s0, also make sure to write that same value to + * dscratch in case an exception occurs in a program buffer that + * might be executed later. + */ + write32(debug_abstract, i++, csrw(S0, CSR_DSCRATCH0)); + } + } else if (regno >= 0x1020 && regno < 0x1040) { unsigned fprnum = regno - 0x1020;