cortex_m: avoid reading and writing non-existent registers
[fw/openocd] / src / target / armv7m.c
index f14ce0d880ae83c490ea9d705c24ee0fdcd42961..101094a971bd7dd79756d03011897a6608ba32d7 100644 (file)
@@ -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;