aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGareth McMullin2015-03-22 14:05:12 -0700
committerGareth McMullin2015-03-22 14:05:12 -0700
commit5ab8564ff67583ac8df977bb6efca047b12e0aed (patch)
treed81f92777aa968cce6f674e747e747fee9be0a9a /src
parent588bad34ba2386737bec4bf4daf50633b0a8fe98 (diff)
Clean up handling of lost targets using new exceptions mechanism.
Diffstat (limited to 'src')
-rw-r--r--src/cortexm.c17
-rw-r--r--src/exception.c2
-rw-r--r--src/gdb_main.c6
-rw-r--r--src/main.c16
-rw-r--r--src/platforms/stm32/timing.c1
5 files changed, 37 insertions, 5 deletions
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 <unistd.h>
@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "general.h"
+#include "morse.h"
#include <libopencm3/cm3/systick.h>
#include <libopencm3/cm3/scb.h>