From bced97cce95a31987f18674bb022e6d263b4f29c Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Sun, 2 Oct 2022 09:30:50 +0200 Subject: [PATCH] target/armv7m: prevent storing invalid register armv7m_start_algorithm() stored all non-debug execution registers from register cache without checking validity. Check if the register cache is valid. Try to read from CPU if not valid. Issue a warning if register read fails. Change-Id: I365f86d65243230cf521b13909575e5986a87a50 Signed-off-by: Tomas Vanek Reviewed-on: https://review.openocd.org/c/openocd/+/7240 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Jonathan Bell --- src/target/armv7m.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/target/armv7m.c b/src/target/armv7m.c index 2db2ce2dd..6f6a170b7 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -528,11 +528,14 @@ 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->valid) + armv7m_get_core_reg(reg); - armv7m_algorithm_info->context[i] = buf_get_u32( - armv7m->arm.core_cache->reg_list[i].value, - 0, - 32); + if (!reg->valid) + LOG_TARGET_WARNING(target, "Storing invalid register %s", reg->name); + + armv7m_algorithm_info->context[i] = buf_get_u32(reg->value, 0, 32); } for (int i = 0; i < num_mem_params; i++) {