From 5ab8564ff67583ac8df977bb6efca047b12e0aed Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 22 Mar 2015 14:05:12 -0700 Subject: Clean up handling of lost targets using new exceptions mechanism. --- src/cortexm.c | 17 +++++++++++++++-- src/exception.c | 2 +- src/gdb_main.c | 6 ++++++ src/main.c | 16 ++++++++++++++-- src/platforms/stm32/timing.c | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cortexm.c b/src/cortexm.c index f20f282..f6a0ea3 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -37,6 +37,7 @@ #include "command.h" #include "gdb_packet.h" #include "cortexm.h" +#include "morse.h" #include @@ -57,6 +58,7 @@ const struct command_s cortexm_cmd_list[] = { #define SIGINT 2 #define SIGTRAP 5 #define SIGSEGV 11 +#define SIGLOST 29 static int cortexm_regs_read(struct target_s *target, void *data); static int cortexm_regs_write(struct target_s *target, const void *data); @@ -487,12 +489,23 @@ cortexm_halt_wait(struct target_s *target) uint32_t dhcsr = 0; volatile struct exception e; - TRY_CATCH (e, EXCEPTION_TIMEOUT) { + TRY_CATCH (e, EXCEPTION_ALL) { /* If this times out because the target is in WFI then * the target is still running. */ dhcsr = target_mem_read32(target, CORTEXM_DHCSR); } - if (e.type || !(dhcsr & CORTEXM_DHCSR_S_HALT)) + switch (e.type) { + case EXCEPTION_ERROR: + /* Oh crap, there's no recovery from this... */ + target_list_free(); + morse("TARGET LOST.", 1); + return SIGLOST; + case EXCEPTION_TIMEOUT: + /* Timeout isn't a problem, target could be in WFI */ + return 0; + } + + if (!(dhcsr & CORTEXM_DHCSR_S_HALT)) return 0; /* We've halted. Let's find out why. */ diff --git a/src/exception.c b/src/exception.c index 33e3869..3d43f99 100644 --- a/src/exception.c +++ b/src/exception.c @@ -34,6 +34,6 @@ void raise_exception(uint32_t type, const char *msg) longjmp(e->jmpbuf, type); } } - PLATFORM_FATAL_ERROR(type); + abort(); } diff --git a/src/gdb_main.c b/src/gdb_main.c index 7bb788b..750dfe2 100644 --- a/src/gdb_main.c +++ b/src/gdb_main.c @@ -158,6 +158,12 @@ gdb_main(void) if (sig < 0) break; + /* Target disappeared */ + if (cur_target == NULL) { + gdb_putpacket_f("X%02X", sig); + break; + } + /* Report reason for halt */ if(target_check_hw_wp(cur_target, &watch_addr)) { /* Watchpoint hit */ diff --git a/src/main.c b/src/main.c index 60db15c..d1b3c86 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,9 @@ #include "jtagtap.h" #include "jtag_scan.h" #include "target.h" +#include "exception.h" +#include "gdb_packet.h" +#include "morse.h" int main(int argc, char **argv) @@ -39,9 +42,18 @@ main(int argc, char **argv) (void) argv; platform_init(); #endif - PLATFORM_SET_FATAL_ERROR_RECOVERY(); - gdb_main(); + while (true) { + volatile struct exception e; + TRY_CATCH(e, EXCEPTION_ALL) { + gdb_main(); + } + if (e.type == EXCEPTION_ERROR) { + gdb_putpacketz("EFF"); + target_list_free(); + morse("TARGET LOST.", 1); + } + } /* Should never get here */ return 0; diff --git a/src/platforms/stm32/timing.c b/src/platforms/stm32/timing.c index cac22ca..55a217a 100644 --- a/src/platforms/stm32/timing.c +++ b/src/platforms/stm32/timing.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ #include "general.h" +#include "morse.h" #include #include -- cgit v1.2.3