Skip to content

Commit

Permalink
esp32: Fixes scracth register corruption
Browse files Browse the repository at this point in the history
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 #27
  • Loading branch information
gerekon committed Apr 18, 2018
1 parent f842a59 commit fb7a6f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/target/esp108.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,16 @@ 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__);

//We need to write the dirty registers in the cache list back to the processor.
//Start by writing the SFR/user registers.
for (i=0; i<XT_NUM_REGS; i++) {
if (reg_list[i].dirty) {
if (esp108_regs[i].type==XT_REG_SPECIAL || esp108_regs[i].type==XT_REG_USER) {
if (esp108_regs[i].type==XT_REG_SPECIAL || esp108_regs[i].type==XT_REG_USER || esp108_regs[i].type==XT_REG_FR) {
scratch_reg_dirty = true;
regval=esp108_reg_get(&reg_list[i]);
LOG_DEBUG("%s: Writing back reg %s val %08X", target->cmd_name, esp108_regs[i].name, regval);
esp108_queue_nexus_reg_write(target, NARADR_DDR, regval);
Expand All @@ -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(&reg_list[XT_REG_IDX_WINDOWBASE]);
Expand Down
9 changes: 7 additions & 2 deletions src/target/esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -242,14 +242,16 @@ 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__);

//We need to write the dirty registers in the cache list back to the processor.
//Start by writing the SFR/user registers.
for (i=0; i<XT_NUM_REGS; i++) {
if (reg_list[i].dirty) {
if (esp32_regs[i].type==XT_REG_SPECIAL || esp32_regs[i].type==XT_REG_USER) {
if (esp32_regs[i].type==XT_REG_SPECIAL || esp32_regs[i].type==XT_REG_USER || esp32_regs[i].type==XT_REG_FR) {
scratch_reg_dirty = true;
regval=esp108_reg_get(&reg_list[i]);
LOG_DEBUG("%s: Writing back reg %s val %08X", target->cmd_name, esp32_regs[i].name, regval);
esp108_queue_nexus_reg_write(target, NARADR_DDR, regval);
Expand All @@ -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(&reg_list[XT_REG_IDX_WINDOWBASE]);
Expand Down

0 comments on commit fb7a6f6

Please sign in to comment.