From 8ddb186b35267e90832deb2db4b0c58f77de4b87 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 8 Mar 2015 15:02:38 -0700 Subject: Allow stub to return an error code. --- src/cortexm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/cortexm.c') diff --git a/src/cortexm.c b/src/cortexm.c index 0327edc..a129a3c 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -60,6 +60,7 @@ const struct command_s cortexm_cmd_list[] = { static int cortexm_regs_read(struct target_s *target, void *data); static int cortexm_regs_write(struct target_s *target, const void *data); static int cortexm_pc_write(struct target_s *target, const uint32_t val); +static uint32_t cortexm_pc_read(struct target_s *target); static void cortexm_reset(struct target_s *target); static int cortexm_halt_wait(struct target_s *target); @@ -216,6 +217,7 @@ cortexm_probe(struct target_s *target) target->regs_read = cortexm_regs_read; target->regs_write = cortexm_regs_write; target->pc_write = cortexm_pc_write; + target->pc_read = cortexm_pc_read; target->reset = cortexm_reset; target->halt_request = cortexm_halt_request; @@ -629,7 +631,12 @@ int cortexm_run_stub(struct target_s *target, uint32_t loadaddr, while (!cortexm_halt_wait(target)) ; - return 0; + uint32_t pc = cortexm_pc_read(target); + uint16_t bkpt_instr = target_mem_read16(target, pc); + if (bkpt_instr >> 8 != 0xbe) + return -2; + + return bkpt_instr & 0xff; } /* The following routines implement hardware breakpoints. -- cgit v1.2.3