From df325cc8a104285179e75f130c52301f7887714d Mon Sep 17 00:00:00 2001 From: linzhida Date: Wed, 6 Nov 2024 17:03:01 +0800 Subject: [PATCH] fix(gva): fix gva bit set/clear logic in mstatus/hstatus. --- src/isa/riscv64/system/intr.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/isa/riscv64/system/intr.c b/src/isa/riscv64/system/intr.c index c525f795..accbd209 100644 --- a/src/isa/riscv64/system/intr.c +++ b/src/isa/riscv64/system/intr.c @@ -179,9 +179,10 @@ word_t raise_intr(word_t NO, vaddr_t epc) { trap_pc = get_trap_pc(vstvec->val, vscause->val); } else if(delegS && !s_EX_DT){ - int v = (mstatus->mprv)? mstatus->mpv : cpu.v; - hstatus->gva = (NO == EX_IGPF || NO == EX_LGPF || NO == EX_SGPF || - ((v || hld_st_temp) && ((0 <= NO && NO <= 7 && NO != 2) || NO == EX_IPF || NO == EX_LPF || NO == EX_SPF))); + bool v = mstatus->mprv && mstatus->mpv && (mstatus->mpp != MODE_M); + hstatus->gva = (NO == EX_IAM || NO == EX_IAF || NO == EX_BP || NO == EX_IPF) && cpu.v || + (NO == EX_LAM || NO == EX_LAF || NO == EX_SAM || NO == EX_SAF || NO == EX_LPF || NO == EX_SPF) && (hld_st_temp || cpu.v || v) || + (NO == EX_IGPF || NO == EX_LGPF || NO == EX_SGPF); hstatus->spv = cpu.v; if(cpu.v){ hstatus->spvp = cpu.mode; @@ -243,9 +244,10 @@ word_t raise_intr(word_t NO, vaddr_t epc) { trap_pc = get_trap_pc(stvec->val, scause->val); } else if((delegM || vs_EX_DT || s_EX_DT) && !m_EX_DT){ #ifdef CONFIG_RVH - int v = (mstatus->mprv)? mstatus->mpv : cpu.v; - mstatus->gva = (NO == EX_IGPF || NO == EX_LGPF || NO == EX_SGPF || - ((v || hld_st_temp) && ((0 <= NO && NO <= 7 && NO != 2) || NO == EX_IPF || NO == EX_LPF || NO == EX_SPF))); + bool v = mstatus->mprv && mstatus->mpv && (mstatus->mpp != MODE_M); + mstatus->gva = (NO == EX_IAM || NO == EX_IAF || NO == EX_BP || NO == EX_IPF) && cpu.v || + (NO == EX_LAM || NO == EX_LAF || NO == EX_SAM || NO == EX_SAF || NO == EX_LPF || NO == EX_SPF) && (hld_st_temp || cpu.v || v) || + (NO == EX_IGPF || NO == EX_LGPF || NO == EX_SGPF) mstatus->mpv = cpu.v; cpu.v = 0;set_sys_state_flag(SYS_STATE_FLUSH_TCACHE); #endif