aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/cortexm.h12
-rw-r--r--src/include/lpc_common.h68
-rw-r--r--src/include/target.h61
3 files changed, 124 insertions, 17 deletions
diff --git a/src/include/cortexm.h b/src/include/cortexm.h
index f7396bf..de57112 100644
--- a/src/include/cortexm.h
+++ b/src/include/cortexm.h
@@ -143,6 +143,18 @@
#define CORTEXM_DWT_FUNC_FUNC_WRITE (6 << 0)
#define CORTEXM_DWT_FUNC_FUNC_ACCESS (7 << 0)
+#define REG_SP 13
+#define REG_LR 14
+#define REG_PC 15
+#define REG_XPSR 16
+#define REG_MSP 17
+#define REG_PSP 18
+#define REG_SPECIAL 19
+
+#define ARM_THUMB_BREAKPOINT 0xBE00
+
+#define CORTEXM_TOPT_INHIBIT_SRST (1 << 2)
+
bool cortexm_attach(target *t);
void cortexm_detach(target *t);
void cortexm_halt_resume(target *t, bool step);
diff --git a/src/include/lpc_common.h b/src/include/lpc_common.h
new file mode 100644
index 0000000..4886156
--- /dev/null
+++ b/src/include/lpc_common.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2015 Gareth McMullin <gareth@blacksphere.co.nz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LPC_COMMON_H
+#define __LPC_COMMON_H
+
+enum iap_cmd {
+ IAP_CMD_INIT = 49,
+ IAP_CMD_PREPARE = 50,
+ IAP_CMD_PROGRAM = 51,
+ IAP_CMD_ERASE = 52,
+ IAP_CMD_BLANKCHECK = 53,
+ IAP_CMD_SET_ACTIVE_BANK = 60,
+};
+
+enum iap_status {
+ IAP_STATUS_CMD_SUCCESS = 0,
+ IAP_STATUS_INVALID_COMMAND = 1,
+ IAP_STATUS_SRC_ADDR_ERROR = 2,
+ IAP_STATUS_DST_ADDR_ERROR = 3,
+ IAP_STATUS_SRC_ADDR_NOT_MAPPED = 4,
+ IAP_STATUS_DST_ADDR_NOT_MAPPED = 5,
+ IAP_STATUS_COUNT_ERROR = 6,
+ IAP_STATUS_INVALID_SECTOR = 7,
+ IAP_STATUS_SECTOR_NOT_BLANK = 8,
+ IAP_STATUS_SECTOR_NOT_PREPARED = 9,
+ IAP_STATUS_COMPARE_ERROR = 10,
+ IAP_STATUS_BUSY = 11,
+};
+
+/* CPU Frequency */
+#define CPU_CLK_KHZ 12000
+
+struct lpc_flash {
+ struct target_flash f;
+ uint8_t base_sector;
+ uint8_t bank;
+ /* Info filled in by specific driver */
+ void (*wdt_kick)(target *t);
+ uint32_t iap_entry;
+ uint32_t iap_ram;
+ uint32_t iap_msp;
+};
+
+struct lpc_flash *lpc_add_flash(target *t, uint32_t addr, size_t length);
+enum iap_status lpc_iap_call(struct lpc_flash *f, enum iap_cmd cmd, ...);
+int lpc_flash_erase(struct target_flash *f, uint32_t addr, size_t len);
+int lpc_flash_write(struct target_flash *f,
+ uint32_t dest, const void *src, size_t len);
+
+#endif
+
diff --git a/src/include/target.h b/src/include/target.h
index 940a360..f86714b 100644
--- a/src/include/target.h
+++ b/src/include/target.h
@@ -95,14 +95,10 @@ target *target_attach(target *t, target_destroy_callback destroy_cb);
/* Flash memory access functions */
-#define target_flash_erase(target, addr, len) \
- (target)->flash_erase((target), (addr), (len))
-
-#define target_flash_write(target, dest, src, len) \
- (target)->flash_write((target), (dest), (src), (len))
-
-#define target_flash_done(target) \
- ((target)->flash_done ? (target)->flash_done(target) : 0)
+int target_flash_erase(target *t, uint32_t addr, size_t len);
+int target_flash_write(target *t,
+ uint32_t dest, const void *src, size_t len);
+int target_flash_done(target *t);
/* Host I/O */
#define target_hostio_reply(target, recode, errcode) \
@@ -112,12 +108,39 @@ target *target_attach(target *t, target_destroy_callback destroy_cb);
#define target_regs_size(target) \
((target)->regs_size)
-#define target_mem_map(target) \
- ((target)->xml_mem_map ? (target)->xml_mem_map : "")
-
#define target_tdesc(target) \
((target)->tdesc ? (target)->tdesc : "")
+struct target_ram {
+ uint32_t start;
+ uint32_t length;
+ struct target_ram *next;
+};
+
+struct target_flash;
+typedef int (*flash_erase_func)(struct target_flash *f, uint32_t addr, size_t len);
+typedef int (*flash_write_func)(struct target_flash *f, uint32_t dest,
+ const void *src, size_t len);
+typedef int (*flash_done_func)(struct target_flash *f);
+struct target_flash {
+ uint32_t start;
+ uint32_t length;
+ uint32_t blocksize;
+ flash_erase_func erase;
+ flash_write_func write;
+ flash_done_func done;
+ target *t;
+ struct target_flash *next;
+ int align;
+ uint8_t erased;
+
+ /* For buffered flash */
+ size_t buf_size;
+ flash_write_func write_buf;
+ uint32_t buf_addr;
+ void *buf;
+};
+
struct target_s {
/* Notify controlling debugger if target is lost */
target_destroy_callback destroy_callback;
@@ -158,12 +181,10 @@ struct target_s {
unsigned target_options;
uint32_t idcode;
- /* Flash memory access functions */
- const char *xml_mem_map;
- int (*flash_erase)(target *t, uint32_t addr, size_t len);
- int (*flash_write)(target *t, uint32_t dest,
- const uint8_t *src, size_t len);
- int (*flash_done)(target *t);
+ /* Target memory map */
+ char *dyn_mem_map;
+ struct target_ram *ram;
+ struct target_flash *flash;
/* Host I/O support */
void (*hostio_reply)(target *t, int32_t retcode, uint32_t errcode);
@@ -190,6 +211,12 @@ extern bool connect_assert_srst;
target *target_new(unsigned size);
void target_list_free(void);
void target_add_commands(target *t, const struct command_s *cmds, const char *name);
+void target_add_ram(target *t, uint32_t start, uint32_t len);
+void target_add_flash(target *t, struct target_flash *f);
+const char *target_mem_map(target *t);
+int target_flash_write_buffered(struct target_flash *f,
+ uint32_t dest, const void *src, size_t len);
+int target_flash_done_buffered(struct target_flash *f);
static inline uint32_t target_mem_read32(target *t, uint32_t addr)
{