From: Tarek BOCHKATI Date: Fri, 12 Feb 2021 20:12:43 +0000 (+0100) Subject: cortex_m: avoid reading and writing non-existent registers X-Git-Tag: v0.12.0-rc1~876 X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff_plain;h=bc0c9907d6ba9a39a953482a2bb2195504999427 cortex_m: avoid reading and writing non-existent registers Change-Id: Iedc24352c8d3444372da06d00fcec9603540f950 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6059 Tested-by: jenkins Reviewed-by: Antonio Borneo --- diff --git a/src/target/armv7m.c b/src/target/armv7m.c index f14ce0d880..101094a971 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -166,10 +166,10 @@ int armv7m_restore_context(struct target *target) * packing of ARMV7M_PMSK_BPRI_FLTMSK_CTRL! * See also comments in the register table above */ for (i = cache->num_regs - 1; i >= 0; i--) { - if (cache->reg_list[i].dirty) { - armv7m->arm.write_core_reg(target, &cache->reg_list[i], i, - ARM_MODE_ANY, cache->reg_list[i].value); - } + struct reg *r = &cache->reg_list[i]; + + if (r->exist && r->dirty) + armv7m->arm.write_core_reg(target, r, i, ARM_MODE_ANY, r->value); } return ERROR_OK; diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index b998b7ac76..2a973e1f63 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -521,7 +521,7 @@ static int cortex_m_debug_entry(struct target *target) for (i = 0; i < num_regs; i++) { r = &armv7m->arm.core_cache->reg_list[i]; - if (!r->valid) + if (r->exist && !r->valid) arm->read_core_reg(target, r, i, ARM_MODE_ANY); } diff --git a/src/target/hla_target.c b/src/target/hla_target.c index ca8b5874af..9ac3442453 100644 --- a/src/target/hla_target.c +++ b/src/target/hla_target.c @@ -226,7 +226,7 @@ static int adapter_load_context(struct target *target) for (int i = 0; i < num_regs; i++) { struct reg *r = &armv7m->arm.core_cache->reg_list[i]; - if (!r->valid) + if (r->exist && !r->valid) armv7m->arm.read_core_reg(target, r, i, ARM_MODE_ANY); }