Skip to content

Commit d8969fe

Browse files
committed
Merge branch 'bugfix/corrupted_scratch_reg' into 'master'
esp32: Fixes scratch register corruption See merge request idf/openocd-esp32!36
2 parents f842a59 + fb7a6f6 commit d8969fe

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/target/esp108.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,16 @@ int esp108_write_dirty_registers(struct target *target)
263263
uint32_t regval, windowbase;
264264
struct esp108_common *esp108=(struct esp108_common*)target->arch_info;
265265
struct reg *reg_list=esp108->core_cache->reg_list;
266+
bool scratch_reg_dirty = false;
266267

267268
LOG_DEBUG("%s: %s", target->cmd_name, __FUNCTION__);
268269

269270
//We need to write the dirty registers in the cache list back to the processor.
270271
//Start by writing the SFR/user registers.
271272
for (i=0; i<XT_NUM_REGS; i++) {
272273
if (reg_list[i].dirty) {
273-
if (esp108_regs[i].type==XT_REG_SPECIAL || esp108_regs[i].type==XT_REG_USER) {
274+
if (esp108_regs[i].type==XT_REG_SPECIAL || esp108_regs[i].type==XT_REG_USER || esp108_regs[i].type==XT_REG_FR) {
275+
scratch_reg_dirty = true;
274276
regval=esp108_reg_get(&reg_list[i]);
275277
LOG_DEBUG("%s: Writing back reg %s val %08X", target->cmd_name, esp108_regs[i].name, regval);
276278
esp108_queue_nexus_reg_write(target, NARADR_DDR, regval);
@@ -286,6 +288,9 @@ int esp108_write_dirty_registers(struct target *target)
286288
}
287289
}
288290
}
291+
if (scratch_reg_dirty) {
292+
esp108_mark_register_dirty(target, XT_REG_IDX_A3);
293+
}
289294

290295
//Grab the windowbase, we need it.
291296
windowbase=esp108_reg_get(&reg_list[XT_REG_IDX_WINDOWBASE]);

src/target/esp32.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static int esp32_fetch_all_regs(struct target *target)
171171
for (i = 0; i < XT_NUM_REGS; i++) {
172172
if (regReadable(esp32_regs[i].flags, cpenable) && (esp32_regs[i].type == XT_REG_SPECIAL || esp32_regs[i].type == XT_REG_USER)) {
173173
if (esp32_regs[i].type == XT_REG_USER) {
174-
esp108_queue_exec_ins(target, XT_INS_RUR(esp32_regs[i].reg_num, XT_REG_A3));
174+
esp108_queue_exec_ins(esp32->esp32_targets[c], XT_INS_RUR(esp32_regs[i].reg_num, XT_REG_A3));
175175
}
176176
else if (esp32_regs[i].type == XT_REG_FR) {
177177
esp108_queue_exec_ins(esp32->esp32_targets[c], XT_INS_RFR(esp32_regs[i].reg_num, XT_REG_A3));
@@ -242,14 +242,16 @@ static int esp32_write_dirty_registers(struct target *target, struct reg *reg_li
242242
int i, j;
243243
int res;
244244
uint32_t regval, windowbase;
245+
bool scratch_reg_dirty = false;
245246

246247
LOG_DEBUG("%s: %s", target->cmd_name, __FUNCTION__);
247248

248249
//We need to write the dirty registers in the cache list back to the processor.
249250
//Start by writing the SFR/user registers.
250251
for (i=0; i<XT_NUM_REGS; i++) {
251252
if (reg_list[i].dirty) {
252-
if (esp32_regs[i].type==XT_REG_SPECIAL || esp32_regs[i].type==XT_REG_USER) {
253+
if (esp32_regs[i].type==XT_REG_SPECIAL || esp32_regs[i].type==XT_REG_USER || esp32_regs[i].type==XT_REG_FR) {
254+
scratch_reg_dirty = true;
253255
regval=esp108_reg_get(&reg_list[i]);
254256
LOG_DEBUG("%s: Writing back reg %s val %08X", target->cmd_name, esp32_regs[i].name, regval);
255257
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
265267
}
266268
}
267269
}
270+
if (scratch_reg_dirty) {
271+
esp32_mark_register_dirty(reg_list, XT_REG_IDX_A3);
272+
}
268273

269274
//Grab the windowbase, we need it.
270275
windowbase=esp108_reg_get(&reg_list[XT_REG_IDX_WINDOWBASE]);

0 commit comments

Comments
 (0)