aboutsummaryrefslogtreecommitdiff
path: root/src/cortexm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cortexm.c')
-rw-r--r--src/cortexm.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/cortexm.c b/src/cortexm.c
index a129a3c..f6a0ea3 100644
--- a/src/cortexm.c
+++ b/src/cortexm.c
@@ -29,6 +29,7 @@
* There are way too many magic numbers used here.
*/
#include "general.h"
+#include "exception.h"
#include "jtagtap.h"
#include "jtag_scan.h"
#include "adiv5.h"
@@ -36,6 +37,7 @@
#include "command.h"
#include "gdb_packet.h"
#include "cortexm.h"
+#include "morse.h"
#include <unistd.h>
@@ -56,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);
@@ -467,12 +470,15 @@ cortexm_reset(struct target_s *target)
static void
cortexm_halt_request(struct target_s *target)
{
- ADIv5_AP_t *ap = adiv5_target_ap(target);
-
- ap->dp->allow_timeout = false;
- target_mem_write32(target, CORTEXM_DHCSR,
- CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_C_HALT |
- CORTEXM_DHCSR_C_DEBUGEN);
+ volatile struct exception e;
+ TRY_CATCH (e, EXCEPTION_TIMEOUT) {
+ target_mem_write32(target, CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY |
+ CORTEXM_DHCSR_C_HALT |
+ CORTEXM_DHCSR_C_DEBUGEN);
+ }
+ if (e.type) {
+ gdb_out("Timeout sending interrupt, is target in WFI?\n");
+ }
}
static int
@@ -480,10 +486,27 @@ cortexm_halt_wait(struct target_s *target)
{
ADIv5_AP_t *ap = adiv5_target_ap(target);
struct cortexm_priv *priv = ap->priv;
- if (!(target_mem_read32(target, CORTEXM_DHCSR) & CORTEXM_DHCSR_S_HALT))
+
+ uint32_t dhcsr = 0;
+ volatile struct exception e;
+ 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);
+ }
+ 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;
+ }
- ap->dp->allow_timeout = false;
+ if (!(dhcsr & CORTEXM_DHCSR_S_HALT))
+ return 0;
/* We've halted. Let's find out why. */
uint32_t dfsr = target_mem_read32(target, CORTEXM_DFSR);
@@ -543,7 +566,6 @@ void cortexm_halt_resume(struct target_s *target, bool step)
}
target_mem_write32(target, CORTEXM_DHCSR, dhcsr);
- ap->dp->allow_timeout = true;
}
static int cortexm_fault_unwind(struct target_s *target)