* Don't use MMU in M mode - https://github.com/riscv/riscv-openocd/issues/474

* Updated code based on feedback from @timsifive
riscv
Tommy Murphy 2020-05-26 18:33:30 +01:00 committed by GitHub
parent 4f9e2d7171
commit 95a8cd9b5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 3 deletions

View File

@ -1383,15 +1383,34 @@ static int riscv_mmu(struct target *target, int *enabled)
if (riscv_rtos_enabled(target)) if (riscv_rtos_enabled(target))
riscv_set_current_hartid(target, target->rtos->current_thread - 1); riscv_set_current_hartid(target, target->rtos->current_thread - 1);
riscv_reg_t value; /* Don't use MMU in explicit or effective M (machine) mode */
if (riscv_get_register(target, &value, GDB_REGNO_SATP) != ERROR_OK) { riscv_reg_t priv;
if (riscv_get_register(target, &priv, GDB_REGNO_PRIV) != ERROR_OK) {
LOG_ERROR("Failed to read priv register.");
return ERROR_FAIL;
}
riscv_reg_t mstatus;
if (riscv_get_register(target, &mstatus, GDB_REGNO_MSTATUS) != ERROR_OK) {
LOG_ERROR("Failed to read mstatus register.");
return ERROR_FAIL;
}
if ((get_field(mstatus, MSTATUS_MPRV) ? get_field(mstatus, MSTATUS_MPP) : priv) == PRV_M) {
LOG_DEBUG("SATP/MMU ignored in Machine mode (mstatus=0x%" PRIx64 ").", mstatus);
*enabled = 0;
return ERROR_OK;
}
riscv_reg_t satp;
if (riscv_get_register(target, &satp, GDB_REGNO_SATP) != ERROR_OK) {
LOG_DEBUG("Couldn't read SATP."); LOG_DEBUG("Couldn't read SATP.");
/* If we can't read SATP, then there must not be an MMU. */ /* If we can't read SATP, then there must not be an MMU. */
*enabled = 0; *enabled = 0;
return ERROR_OK; return ERROR_OK;
} }
if (get_field(value, RISCV_SATP_MODE(riscv_xlen(target))) == SATP_MODE_OFF) { if (get_field(satp, RISCV_SATP_MODE(riscv_xlen(target))) == SATP_MODE_OFF) {
LOG_DEBUG("MMU is disabled."); LOG_DEBUG("MMU is disabled.");
*enabled = 0; *enabled = 0;
} else { } else {