aboutsummaryrefslogtreecommitdiff
path: root/src/cortexm.c
diff options
context:
space:
mode:
authorGareth McMullin2015-03-08 12:55:59 -0700
committerGareth McMullin2015-03-19 07:48:47 -0700
commitc2462a6788c119edd9995fa46f1316a9c0431e0b (patch)
treeef75072d2228b362f535efcf3839b7d56aa3253a /src/cortexm.c
parente380ced5171dc3c9098005924f61051a43b79428 (diff)
Add cortexm generic stub call, and use in stm32f1 driver.
Diffstat (limited to 'src/cortexm.c')
-rw-r--r--src/cortexm.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/cortexm.c b/src/cortexm.c
index 4bfb4d9..0327edc 100644
--- a/src/cortexm.c
+++ b/src/cortexm.c
@@ -603,6 +603,35 @@ static int cortexm_fault_unwind(struct target_s *target)
return 0;
}
+int cortexm_run_stub(struct target_s *target, uint32_t loadaddr,
+ const uint16_t *stub, uint32_t stublen,
+ uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3)
+{
+ uint32_t regs[target->regs_size / 4];
+
+ memset(regs, 0, sizeof(regs));
+ regs[0] = r0;
+ regs[1] = r1;
+ regs[2] = r2;
+ regs[3] = r3;
+ regs[15] = loadaddr;
+ regs[16] = 0x1000000;
+ regs[19] = 0;
+
+ target_mem_write(target, loadaddr, stub, stublen);
+ cortexm_regs_write(target, regs);
+
+ if (target_check_error(target))
+ return -1;
+
+ /* Execute the stub */
+ cortexm_halt_resume(target, 0);
+ while (!cortexm_halt_wait(target))
+ ;
+
+ return 0;
+}
+
/* The following routines implement hardware breakpoints.
* The Flash Patch and Breakpoint (FPB) system is used. */
@@ -648,7 +677,6 @@ cortexm_clear_hw_bp(struct target_s *target, uint32_t addr)
return 0;
}
-
/* The following routines implement hardware watchpoints.
* The Data Watch and Trace (DWT) system is used. */