Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gva): fix gva bit set/clear logic in mstatus/hstatus. #642

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/isa/riscv64/local-include/intr.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum {

word_t raise_intr(word_t NO, vaddr_t epc);
#define return_on_mem_ex() do { if (cpu.mem_exception != MEM_OK) return; } while (0)
word_t gen_gva(word_t NO, bool is_hls, bool is_mem_access_virtual);
bool intr_deleg_S(word_t exceptionNO);
bool intr_deleg_VS(word_t exceptionNO);

Expand Down
15 changes: 9 additions & 6 deletions src/isa/riscv64/system/intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ void update_mmu_state();
trap_info_t trapInfo = {};

#ifdef CONFIG_RVH
word_t gen_gva(word_t NO, bool is_hls, bool is_mem_access_virtual) {
return ((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) && (is_hls || cpu.v || is_mem_access_virtual)) ||
(NO == EX_IGPF || NO == EX_LGPF || NO == EX_SGPF);
}

bool intr_deleg_S(word_t exceptionNO) {
bool isNMI = MUXDEF(CONFIG_RV_SMRNMI, cpu.hasNMI && (exceptionNO & INTR_BIT), false);
word_t deleg = (exceptionNO & INTR_BIT ? mideleg->val : medeleg->val);
Expand Down Expand Up @@ -179,9 +185,7 @@ 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)));
hstatus->gva = gen_gva(NO, hld_st_temp, false);
hstatus->spv = cpu.v;
if(cpu.v){
hstatus->spvp = cpu.mode;
Expand Down Expand Up @@ -243,9 +247,8 @@ 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 is_mem_access_virtual = mstatus->mprv && mstatus->mpv && (mstatus->mpp != MODE_M);
mstatus->gva = gen_gva(NO, hld_st_temp, is_mem_access_virtual);
mstatus->mpv = cpu.v;
cpu.v = 0;set_sys_state_flag(SYS_STATE_FLUSH_TCACHE);
#endif
Expand Down