From 5c2f920cc792d40f449cf596b5729671d0414fa1 Mon Sep 17 00:00:00 2001 From: Andreas Fritiofson Date: Mon, 11 Mar 2013 22:21:13 +0100 Subject: [PATCH] [RFC] target: Move bulk_write_memory to arm7_9 The only remaining user is arm7_9 so remove it from the target API and add it to struct arm7_9_common to support all its variants with minimal changes. Many of the variants are likely not correct in the cache/mmu handling when the bulk write is triggered. This patch does nothing to change that, except for arm946e, where it was easier to do what might be the right thing. Change-Id: Ie73ac07507ff0936fefdb90760046cc8810ed182 Signed-off-by: Andreas Fritiofson Reviewed-on: http://openocd.zylin.com/1220 Tested-by: jenkins Reviewed-by: Spencer Oliver --- src/target/arm720t.c | 4 +--- src/target/arm7_9_common.c | 14 ++++++++++++++ src/target/arm7_9_common.h | 9 +++++++++ src/target/arm7tdmi.c | 5 +++-- src/target/arm920t.c | 15 ++++++++++++--- src/target/arm920t.h | 2 ++ src/target/arm926ejs.c | 14 ++++++++++++-- src/target/arm926ejs.h | 2 ++ src/target/arm946e.c | 4 +--- src/target/arm966e.c | 3 +-- src/target/arm9tdmi.c | 5 +++-- src/target/fa526.c | 5 +++-- src/target/feroceon.c | 8 ++++---- src/target/target.c | 22 +++------------------- src/target/target_type.h | 8 -------- 15 files changed, 70 insertions(+), 50 deletions(-) diff --git a/src/target/arm720t.c b/src/target/arm720t.c index d38fc82b3..619c80a13 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -565,14 +565,12 @@ struct target_type arm720t_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm720t_read_memory, - .write_memory = arm7_9_write_memory, + .write_memory = arm7_9_write_memory_opt, .read_phys_memory = arm720t_read_phys_memory, .write_phys_memory = arm720t_write_phys_memory, .mmu = arm720_mmu, .virt2phys = arm720_virt2phys, - .bulk_write_memory = arm7_9_bulk_write_memory, - .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index 587cb0ee6..6eade96a1 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2469,6 +2469,20 @@ int arm7_9_write_memory(struct target *target, return ERROR_OK; } +int arm7_9_write_memory_opt(struct target *target, + uint32_t address, + uint32_t size, + uint32_t count, + const uint8_t *buffer) +{ + struct arm7_9_common *arm7_9 = target_to_arm7_9(target); + + if (size == 4 && count > 32 && arm7_9->bulk_write_memory) + return arm7_9->bulk_write_memory(target, address, count, buffer); + else + return arm7_9_write_memory(target, address, size, count, buffer); +} + static int dcc_count; static const uint8_t *dcc_buffer; diff --git a/src/target/arm7_9_common.h b/src/target/arm7_9_common.h index 737cbae55..85e5ac045 100644 --- a/src/target/arm7_9_common.h +++ b/src/target/arm7_9_common.h @@ -118,6 +118,13 @@ struct arm7_9_common { void (*pre_restore_context)(struct target *target); /**< Callback function called before restoring the processor context */ + + /** + * Write target memory in multiples of 4 bytes, optimized for + * writing large quantities of data. + */ + int (*bulk_write_memory)(struct target *target, uint32_t address, + uint32_t count, const uint8_t *buffer); }; static inline struct arm7_9_common *target_to_arm7_9(struct target *target) @@ -151,6 +158,8 @@ int arm7_9_read_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); int arm7_9_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); +int arm7_9_write_memory_opt(struct target *target, uint32_t address, + uint32_t size, uint32_t count, const uint8_t *buffer); int arm7_9_bulk_write_memory(struct target *target, uint32_t address, uint32_t count, const uint8_t *buffer); diff --git a/src/target/arm7tdmi.c b/src/target/arm7tdmi.c index 3ef977769..4c7cce19e 100644 --- a/src/target/arm7tdmi.c +++ b/src/target/arm7tdmi.c @@ -648,6 +648,8 @@ int arm7tdmi_init_arch_info(struct target *target, arm7_9->enable_single_step = arm7_9_enable_eice_step; arm7_9->disable_single_step = arm7_9_disable_eice_step; + arm7_9->bulk_write_memory = arm7_9_bulk_write_memory; + arm7_9->post_debug_entry = NULL; arm7_9->pre_restore_context = NULL; @@ -694,8 +696,7 @@ struct target_type arm7tdmi_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm7_9_read_memory, - .write_memory = arm7_9_write_memory, - .bulk_write_memory = arm7_9_bulk_write_memory, + .write_memory = arm7_9_write_memory_opt, .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 41d647336..98bd12f56 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -740,6 +740,17 @@ int arm920t_write_memory(struct target *target, uint32_t address, return ERROR_OK; } +int arm920t_write_memory_opt(struct target *target, uint32_t address, + uint32_t size, uint32_t count, const uint8_t *buffer) +{ + struct arm7_9_common *arm7_9 = target_to_arm7_9(target); + + if (size == 4 && count > 32 && arm7_9->bulk_write_memory) + return arm7_9->bulk_write_memory(target, address, count, buffer); + else + return arm920t_write_memory(target, address, size, count, buffer); +} + /* EXPORTED to FA256 */ int arm920t_soft_reset_halt(struct target *target) { @@ -1697,14 +1708,12 @@ struct target_type arm920t_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm920t_read_memory, - .write_memory = arm920t_write_memory, + .write_memory = arm920t_write_memory_opt, .read_phys_memory = arm920t_read_phys_memory, .write_phys_memory = arm920t_write_phys_memory, .mmu = arm920_mmu, .virt2phys = arm920_virt2phys, - .bulk_write_memory = arm7_9_bulk_write_memory, - .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/arm920t.h b/src/target/arm920t.h index 71876a69b..37745130f 100644 --- a/src/target/arm920t.h +++ b/src/target/arm920t.h @@ -60,6 +60,8 @@ int arm920t_read_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); int arm920t_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); +int arm920t_write_memory_opt(struct target *target, + uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); int arm920t_post_debug_entry(struct target *target); void arm920t_pre_restore_context(struct target *target); int arm920t_get_ttb(struct target *target, uint32_t *result); diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 95930e685..1e0a57902 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -656,6 +656,17 @@ int arm926ejs_write_memory(struct target *target, uint32_t address, return retval; } +int arm926ejs_write_memory_opt(struct target *target, uint32_t address, + uint32_t size, uint32_t count, const uint8_t *buffer) +{ + struct arm7_9_common *arm7_9 = target_to_arm7_9(target); + + if (size == 4 && count > 32 && arm7_9->bulk_write_memory) + return arm7_9->bulk_write_memory(target, address, count, buffer); + else + return arm926ejs_write_memory(target, address, size, count, buffer); +} + static int arm926ejs_write_phys_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer) @@ -808,8 +819,7 @@ struct target_type arm926ejs_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm7_9_read_memory, - .write_memory = arm926ejs_write_memory, - .bulk_write_memory = arm7_9_bulk_write_memory, + .write_memory = arm926ejs_write_memory_opt, .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/arm926ejs.h b/src/target/arm926ejs.h index cc19c9fc5..6dde4c6ff 100644 --- a/src/target/arm926ejs.h +++ b/src/target/arm926ejs.h @@ -50,6 +50,8 @@ int arm926ejs_init_arch_info(struct target *target, int arm926ejs_arch_state(struct target *target); int arm926ejs_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); +int arm926ejs_write_memory_opt(struct target *target, + uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer); int arm926ejs_soft_reset_halt(struct target *target); extern const struct command_registration arm926ejs_command_handlers[]; diff --git a/src/target/arm946e.c b/src/target/arm946e.c index 7ffab7ad5..5c85845d1 100644 --- a/src/target/arm946e.c +++ b/src/target/arm946e.c @@ -504,7 +504,7 @@ int arm946e_write_memory(struct target *target, uint32_t address, /** * Write memory */ - retval = arm7_9_write_memory(target, address, size, count, buffer); + retval = arm7_9_write_memory_opt(target, address, size, count, buffer); if (retval != ERROR_OK) return retval; @@ -764,8 +764,6 @@ struct target_type arm946e_target = { .read_memory = arm946e_read_memory, .write_memory = arm946e_write_memory, - .bulk_write_memory = arm7_9_bulk_write_memory, - .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/arm966e.c b/src/target/arm966e.c index 39653c2ef..6a96ab18f 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -264,8 +264,7 @@ struct target_type arm966e_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm7_9_read_memory, - .write_memory = arm7_9_write_memory, - .bulk_write_memory = arm7_9_bulk_write_memory, + .write_memory = arm7_9_write_memory_opt, .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index c468282bc..d93c15f7c 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -752,6 +752,8 @@ int arm9tdmi_init_arch_info(struct target *target, arm7_9->enable_single_step = arm9tdmi_enable_single_step; arm7_9->disable_single_step = arm9tdmi_disable_single_step; + arm7_9->bulk_write_memory = arm7_9_bulk_write_memory; + arm7_9->post_debug_entry = NULL; arm7_9->pre_restore_context = NULL; @@ -902,8 +904,7 @@ struct target_type arm9tdmi_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm7_9_read_memory, - .write_memory = arm7_9_write_memory, - .bulk_write_memory = arm7_9_bulk_write_memory, + .write_memory = arm7_9_write_memory_opt, .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/fa526.c b/src/target/fa526.c index aeef858e5..a33b4a1c6 100644 --- a/src/target/fa526.c +++ b/src/target/fa526.c @@ -284,6 +284,8 @@ static int fa526_init_arch_info_2(struct target *target, arm7_9->enable_single_step = arm9tdmi_enable_single_step; arm7_9->disable_single_step = arm9tdmi_disable_single_step; + arm7_9->bulk_write_memory = arm7_9_bulk_write_memory; + arm7_9->post_debug_entry = NULL; arm7_9->pre_restore_context = NULL; @@ -366,8 +368,7 @@ struct target_type fa526_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm920t_read_memory, - .write_memory = arm920t_write_memory, - .bulk_write_memory = arm7_9_bulk_write_memory, + .write_memory = arm920t_write_memory_opt, .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/feroceon.c b/src/target/feroceon.c index ab43f3dfc..d3037c543 100644 --- a/src/target/feroceon.c +++ b/src/target/feroceon.c @@ -605,6 +605,8 @@ static void feroceon_common_setup(struct target *target) arm7_9->enable_single_step = feroceon_enable_single_step; arm7_9->disable_single_step = feroceon_disable_single_step; + arm7_9->bulk_write_memory = feroceon_bulk_write_memory; + /* MOE is not implemented */ arm7_9->examine_debug_reason = feroceon_examine_debug_reason; @@ -695,8 +697,7 @@ struct target_type feroceon_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm7_9_read_memory, - .write_memory = arm926ejs_write_memory, - .bulk_write_memory = feroceon_bulk_write_memory, + .write_memory = arm926ejs_write_memory_opt, .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, @@ -733,8 +734,7 @@ struct target_type dragonite_target = { .get_gdb_reg_list = arm_get_gdb_reg_list, .read_memory = arm7_9_read_memory, - .write_memory = arm7_9_write_memory, - .bulk_write_memory = feroceon_bulk_write_memory, + .write_memory = arm7_9_write_memory_opt, .checksum_memory = arm_checksum_memory, .blank_check_memory = arm_blank_check_memory, diff --git a/src/target/target.c b/src/target/target.c index 29a011cea..6aee09832 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -986,12 +986,6 @@ int target_write_phys_memory(struct target *target, return target->type->write_phys_memory(target, address, size, count, buffer); } -static int target_bulk_write_memory_default(struct target *target, - uint32_t address, uint32_t count, const uint8_t *buffer) -{ - return target_write_memory(target, address, 4, count, buffer); -} - int target_add_breakpoint(struct target *target, struct breakpoint *breakpoint) { @@ -1173,9 +1167,6 @@ static int target_init_one(struct command_context *cmd_ctx, if (target->type->write_buffer == NULL) target->type->write_buffer = target_write_buffer_default; - if (target->type->bulk_write_memory == NULL) - target->type->bulk_write_memory = target_bulk_write_memory_default; - if (target->type->get_gdb_fileio_info == NULL) target->type->get_gdb_fileio_info = target_get_gdb_fileio_info_default; @@ -1802,16 +1793,9 @@ static int target_write_buffer_default(struct target *target, uint32_t address, if (size >= 4) { int aligned = size - (size % 4); - /* use bulk writes above a certain limit. This may have to be changed */ - if (aligned > 128) { - retval = target->type->bulk_write_memory(target, address, aligned / 4, buffer); - if (retval != ERROR_OK) - return retval; - } else { - retval = target_write_memory(target, address, 4, aligned / 4, buffer); - if (retval != ERROR_OK) - return retval; - } + retval = target_write_memory(target, address, 4, aligned / 4, buffer); + if (retval != ERROR_OK) + return retval; buffer += aligned; address += aligned; diff --git a/src/target/target_type.h b/src/target/target_type.h index 21439b656..cf81708b8 100644 --- a/src/target/target_type.h +++ b/src/target/target_type.h @@ -130,14 +130,6 @@ struct target_type { int (*write_buffer)(struct target *target, uint32_t address, uint32_t size, const uint8_t *buffer); - /** - * Write target memory in multiples of 4 bytes, optimized for - * writing large quantities of data. Do @b not call this - * function directly, use target_bulk_write_memory() instead. - */ - int (*bulk_write_memory)(struct target *target, uint32_t address, - uint32_t count, const uint8_t *buffer); - int (*checksum_memory)(struct target *target, uint32_t address, uint32_t count, uint32_t *checksum); int (*blank_check_memory)(struct target *target, uint32_t address,