extend debug mode handling
This commit is contained in:
parent
c054d75717
commit
477c530847
@ -188,7 +188,7 @@ enum {
|
|||||||
|
|
||||||
template <typename T> inline bool PTE_TABLE(T PTE) { return (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V); }
|
template <typename T> inline bool PTE_TABLE(T PTE) { return (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V); }
|
||||||
|
|
||||||
enum { PRIV_U = 0, PRIV_S = 1, PRIV_M = 3 };
|
enum { PRIV_U = 0, PRIV_S = 1, PRIV_M = 3, PRIV_D = 4};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ISA_A = 1,
|
ISA_A = 1,
|
||||||
|
@ -1127,6 +1127,7 @@ template <typename BASE, features_e FEAT> uint64_t riscv_hart_m_p<BASE, FEAT>::e
|
|||||||
auto trap_id = bit_sub<0, 16>(flags);
|
auto trap_id = bit_sub<0, 16>(flags);
|
||||||
auto cause = bit_sub<16, 15>(flags);
|
auto cause = bit_sub<16, 15>(flags);
|
||||||
// calculate effective privilege level
|
// calculate effective privilege level
|
||||||
|
unsigned new_priv = PRIV_M;
|
||||||
if (trap_id == 0) { // exception
|
if (trap_id == 0) { // exception
|
||||||
if (cause == 11) cause = 0x8 + PRIV_M; // adjust environment call cause
|
if (cause == 11) cause = 0x8 + PRIV_M; // adjust environment call cause
|
||||||
// store ret addr in xepc register
|
// store ret addr in xepc register
|
||||||
@ -1146,10 +1147,13 @@ template <typename BASE, features_e FEAT> uint64_t riscv_hart_m_p<BASE, FEAT>::e
|
|||||||
csr[mtval] = (instr & 0x3)==3?instr:instr&0xffff;
|
csr[mtval] = (instr & 0x3)==3?instr:instr&0xffff;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
//TODO: implement debug mode behavior
|
if((FEAT & FEAT_DEBUG) && (csr[dcsr] & 0x8000)) {
|
||||||
// csr[dpc] = addr;
|
this->reg.DPC = addr;
|
||||||
// csr[dcsr] = (csr[dcsr] & ~0x1c3) | (1<<6) | PRIV_M; //FIXME: cause should not be 4 (stepi)
|
csr[dcsr] = (csr[dcsr] & ~0x1c3) | (1<<6) | PRIV_M; //FIXME: cause should not be 4 (stepi)
|
||||||
csr[mtval] = addr;
|
new_priv = this->reg.PRIV | PRIV_D;
|
||||||
|
} else {
|
||||||
|
csr[mtval] = addr;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
case 6:
|
case 6:
|
||||||
@ -1182,7 +1186,7 @@ template <typename BASE, features_e FEAT> uint64_t riscv_hart_m_p<BASE, FEAT>::e
|
|||||||
this->reg.NEXT_PC = ivec & ~0x3UL;
|
this->reg.NEXT_PC = ivec & ~0x3UL;
|
||||||
if ((ivec & 0x1) == 1 && trap_id != 0) this->reg.NEXT_PC += 4 * cause;
|
if ((ivec & 0x1) == 1 && trap_id != 0) this->reg.NEXT_PC += 4 * cause;
|
||||||
// reset trap state
|
// reset trap state
|
||||||
this->reg.PRIV = PRIV_M;
|
this->reg.PRIV = new_priv;
|
||||||
this->reg.trap_state = 0;
|
this->reg.trap_state = 0;
|
||||||
std::array<char, 32> buffer;
|
std::array<char, 32> buffer;
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
@ -1296,7 +1296,7 @@ template <typename BASE, features_e FEAT> uint64_t riscv_hart_mu_p<BASE, FEAT>::
|
|||||||
auto cause = bit_sub<16, 15>(flags);
|
auto cause = bit_sub<16, 15>(flags);
|
||||||
if (trap_id == 0 && cause == 11) cause = 0x8 + this->reg.PRIV; // adjust environment call cause
|
if (trap_id == 0 && cause == 11) cause = 0x8 + this->reg.PRIV; // adjust environment call cause
|
||||||
// calculate effective privilege level
|
// calculate effective privilege level
|
||||||
auto new_priv = PRIV_M;
|
unsigned new_priv = PRIV_M;
|
||||||
if (trap_id == 0) { // exception
|
if (trap_id == 0) { // exception
|
||||||
if (this->reg.PRIV != PRIV_M && ((csr[medeleg] >> cause) & 0x1) != 0)
|
if (this->reg.PRIV != PRIV_M && ((csr[medeleg] >> cause) & 0x1) != 0)
|
||||||
new_priv = PRIV_U;
|
new_priv = PRIV_U;
|
||||||
@ -1317,10 +1317,13 @@ template <typename BASE, features_e FEAT> uint64_t riscv_hart_mu_p<BASE, FEAT>::
|
|||||||
csr[utval | (new_priv << 8)] = (instr & 0x3)==3?instr:instr&0xffff;
|
csr[utval | (new_priv << 8)] = (instr & 0x3)==3?instr:instr&0xffff;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
//TODO: implement debug mode behavior
|
if((FEAT & FEAT_DEBUG) && (csr[dcsr] & 0x8000)) {
|
||||||
// csr[dpc] = addr;
|
this->reg.DPC = addr;
|
||||||
// csr[dcsr] = (csr[dcsr] & ~0x1c3) | (1<<6) | PRIV_M; //FIXME: cause should not be 4 (stepi)
|
csr[dcsr] = (csr[dcsr] & ~0x1c3) | (1<<6) | PRIV_M; //FIXME: cause should not be 4 (stepi)
|
||||||
csr[utval | (new_priv << 8)] = addr;
|
new_priv = this->reg.PRIV | PRIV_D;
|
||||||
|
} else {
|
||||||
|
csr[utval | (new_priv << 8)] = addr;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
case 6:
|
case 6:
|
||||||
|
Loading…
Reference in New Issue
Block a user