Skip to content

Commit

Permalink
target/armv7m: prevent storing invalid register
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-on: https://review.openocd.org/c/openocd/+/7240
Tested-by: jenkins
Reviewed-by: Antonio Borneo <[email protected]>
Reviewed-by: Jonathan Bell <[email protected]>
  • Loading branch information
tom-van authored and borneoa committed Oct 8, 2022
1 parent dce9a03 commit bced97c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/target/armv7m.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit bced97c

Please sign in to comment.