riscv: Use proper UINT packing and unpacking routines for disabling interrupts before running algorithms.

__archive__
Megan Wachs 2017-01-25 15:23:10 -08:00
parent 5766efe0c3
commit d5892f0ee5
1 changed files with 12 additions and 5 deletions

View File

@ -2698,15 +2698,16 @@ static int riscv_run_algorithm(struct target *target, int num_mem_params,
// Disable Interrupts before attempting to run the algorithm. // Disable Interrupts before attempting to run the algorithm.
// Is it possible/desirable to do this in the calling code instead?
uint64_t current_mstatus; uint64_t current_mstatus;
uint8_t mstatus_bytes[8];
LOG_DEBUG("Disabling Interrupts");
register_get(&target->reg_cache->reg_list[REG_MSTATUS]); register_get(&target->reg_cache->reg_list[REG_MSTATUS]);
current_mstatus = info->mstatus_actual; current_mstatus = buf_get_u64(target->reg_cache->reg_list[REG_MSTATUS].value, 0, info->xlen);
current_mstatus = current_mstatus & ~((uint64_t) 0x8); buf_set_u64(mstatus_bytes, 0, info->xlen, (current_mstatus & (~((uint64_t)MSTATUS_MIE))) );
register_set((&target->reg_cache->reg_list[REG_MSTATUS]), (uint8_t*) &current_mstatus);
info->mstatus_actual = current_mstatus;
register_set(&target->reg_cache->reg_list[REG_MSTATUS], mstatus_bytes);
info->mstatus_actual = current_mstatus & ~MSTATUS_MIE;
/// Run algorithm /// Run algorithm
LOG_DEBUG("resume at 0x%x", entry_point); LOG_DEBUG("resume at 0x%x", entry_point);
@ -2741,6 +2742,12 @@ static int riscv_run_algorithm(struct target *target, int num_mem_params,
return ERROR_FAIL; 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);
info->mstatus_actual = current_mstatus;
/// Restore registers /// Restore registers
uint8_t buf[8]; uint8_t buf[8];
buf_set_u64(buf, 0, info->xlen, saved_pc); buf_set_u64(buf, 0, info->xlen, saved_pc);