From 69391878535ec584a472475ee9767b6beaaa138c Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Tue, 18 Oct 2022 22:00:18 +0200 Subject: [PATCH] target/armv7m: prevent saving and restoring non existent regs armv7m_start_algorithm() saves register values to arch_info->context. armv7m_wait_algorithm() restores register values from arch_info->context. Exclude registers with flag exist = false from both loops. While on it refactor the register restore: introduce 'struct reg' pointer and dereference it instead of numerous accesses by a full path from armv7m pointer. Change-Id: I1600084db84809ee13bcf8e7828b79f8c9ff9077 Signed-off-by: Tomas Vanek Reviewed-on: https://review.openocd.org/c/openocd/+/7276 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/armv7m.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/target/armv7m.c b/src/target/armv7m.c index d9d01923a2..d28702dd7b 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -529,6 +529,9 @@ int armv7m_start_algorithm(struct target *target, /* Store all non-debug execution registers to armv7m_algorithm_info context */ for (unsigned i = 0; i < armv7m->arm.core_cache->num_regs; i++) { struct reg *reg = &armv7m->arm.core_cache->reg_list[i]; + if (!reg->exist) + continue; + if (!reg->valid) armv7m_get_core_reg(reg); @@ -688,16 +691,19 @@ int armv7m_wait_algorithm(struct target *target, } for (int i = armv7m->arm.core_cache->num_regs - 1; i >= 0; i--) { + struct reg *reg = &armv7m->arm.core_cache->reg_list[i]; + if (!reg->exist) + continue; + uint32_t regvalue; - regvalue = buf_get_u32(armv7m->arm.core_cache->reg_list[i].value, 0, 32); + regvalue = buf_get_u32(reg->value, 0, 32); if (regvalue != armv7m_algorithm_info->context[i]) { LOG_DEBUG("restoring register %s with value 0x%8.8" PRIx32, - armv7m->arm.core_cache->reg_list[i].name, - armv7m_algorithm_info->context[i]); - buf_set_u32(armv7m->arm.core_cache->reg_list[i].value, + reg->name, armv7m_algorithm_info->context[i]); + buf_set_u32(reg->value, 0, 32, armv7m_algorithm_info->context[i]); - armv7m->arm.core_cache->reg_list[i].valid = true; - armv7m->arm.core_cache->reg_list[i].dirty = true; + reg->valid = true; + reg->dirty = true; } } -- 2.30.2