From fb7a6f6f4532b21138aa601e838af7de833894a2 Mon Sep 17 00:00:00 2001 From: Alexey Gerenkov Date: Wed, 18 Apr 2018 12:28:21 +0300 Subject: [PATCH] esp32: Fixes scracth register corruption Fixes for the following bugs are incuded: - Scratch register A3 was corrupted when special, user or floating point dirty registers are written back to the processors. - esp32 dual core target was fetching user registers from PRO CPU instead of APP one Closes https://github.com/espressif/openocd-esp32/issues/27 --- src/target/esp108.c | 7 ++++++- src/target/esp32.c | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/target/esp108.c b/src/target/esp108.c index 69fe3115b5..d71f1144db 100644 --- a/src/target/esp108.c +++ b/src/target/esp108.c @@ -263,6 +263,7 @@ int esp108_write_dirty_registers(struct target *target) uint32_t regval, windowbase; struct esp108_common *esp108=(struct esp108_common*)target->arch_info; struct reg *reg_list=esp108->core_cache->reg_list; + bool scratch_reg_dirty = false; LOG_DEBUG("%s: %s", target->cmd_name, __FUNCTION__); @@ -270,7 +271,8 @@ int esp108_write_dirty_registers(struct target *target) //Start by writing the SFR/user registers. for (i=0; icmd_name, esp108_regs[i].name, regval); esp108_queue_nexus_reg_write(target, NARADR_DDR, regval); @@ -286,6 +288,9 @@ int esp108_write_dirty_registers(struct target *target) } } } + if (scratch_reg_dirty) { + esp108_mark_register_dirty(target, XT_REG_IDX_A3); + } //Grab the windowbase, we need it. windowbase=esp108_reg_get(®_list[XT_REG_IDX_WINDOWBASE]); diff --git a/src/target/esp32.c b/src/target/esp32.c index 0a078f882a..d787911d7b 100755 --- a/src/target/esp32.c +++ b/src/target/esp32.c @@ -171,7 +171,7 @@ static int esp32_fetch_all_regs(struct target *target) for (i = 0; i < XT_NUM_REGS; i++) { if (regReadable(esp32_regs[i].flags, cpenable) && (esp32_regs[i].type == XT_REG_SPECIAL || esp32_regs[i].type == XT_REG_USER)) { if (esp32_regs[i].type == XT_REG_USER) { - esp108_queue_exec_ins(target, XT_INS_RUR(esp32_regs[i].reg_num, XT_REG_A3)); + esp108_queue_exec_ins(esp32->esp32_targets[c], XT_INS_RUR(esp32_regs[i].reg_num, XT_REG_A3)); } else if (esp32_regs[i].type == XT_REG_FR) { esp108_queue_exec_ins(esp32->esp32_targets[c], XT_INS_RFR(esp32_regs[i].reg_num, XT_REG_A3)); @@ -242,6 +242,7 @@ static int esp32_write_dirty_registers(struct target *target, struct reg *reg_li int i, j; int res; uint32_t regval, windowbase; + bool scratch_reg_dirty = false; LOG_DEBUG("%s: %s", target->cmd_name, __FUNCTION__); @@ -249,7 +250,8 @@ static int esp32_write_dirty_registers(struct target *target, struct reg *reg_li //Start by writing the SFR/user registers. for (i=0; icmd_name, esp32_regs[i].name, regval); esp108_queue_nexus_reg_write(target, NARADR_DDR, regval); @@ -265,6 +267,9 @@ static int esp32_write_dirty_registers(struct target *target, struct reg *reg_li } } } + if (scratch_reg_dirty) { + esp32_mark_register_dirty(reg_list, XT_REG_IDX_A3); + } //Grab the windowbase, we need it. windowbase=esp108_reg_get(®_list[XT_REG_IDX_WINDOWBASE]);