Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #13 from sifive/disable_interrupts
Browse files Browse the repository at this point in the history
riscv: Globally disable interrupts when running algorithms.
  • Loading branch information
timsifive authored Jan 26, 2017
2 parents 193f630 + 5d82a39 commit 9bab078
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/target/riscv/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,19 @@ static int riscv_run_algorithm(struct target *target, int num_mem_params,
}
}


// Disable Interrupts before attempting to run the algorithm.
uint64_t current_mstatus;
uint8_t mstatus_bytes[8];

LOG_DEBUG("Disabling Interrupts");
register_get(&target->reg_cache->reg_list[REG_MSTATUS]);
current_mstatus = buf_get_u64(target->reg_cache->reg_list[REG_MSTATUS].value, 0, info->xlen);
uint64_t ie_mask = MSTATUS_MIE | MSTATUS_HIE | MSTATUS_SIE | MSTATUS_UIE;
buf_set_u64(mstatus_bytes, 0, info->xlen, set_field(current_mstatus, ie_mask, 0));

register_set(&target->reg_cache->reg_list[REG_MSTATUS], mstatus_bytes);

/// Run algorithm
LOG_DEBUG("resume at 0x%x", entry_point);
if (riscv_resume(target, 0, entry_point, 0, 0) != ERROR_OK) {
Expand Down Expand Up @@ -2729,6 +2742,11 @@ static int riscv_run_algorithm(struct target *target, int num_mem_params,
return ERROR_FAIL;
}

// Restore Interrupts
LOG_DEBUG("Restoring Interrupts");
buf_set_u64(mstatus_bytes, 0, info->xlen, current_mstatus);
register_set(&target->reg_cache->reg_list[REG_MSTATUS], mstatus_bytes);

/// Restore registers
uint8_t buf[8];
buf_set_u64(buf, 0, info->xlen, saved_pc);
Expand Down

0 comments on commit 9bab078

Please sign in to comment.