From: dramforever Date: Sun, 12 Jun 2022 05:57:37 +0000 (+0800) Subject: lib: sbi_trap: Redirect exception based on hedeleg X-Git-Tag: v1.1~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=adc3388d76af18487d8ba4a53a1d1e83655435f3;p=platform%2Fkernel%2Fopensbi.git lib: sbi_trap: Redirect exception based on hedeleg HS-mode software can choose what exceptions to delegate to VS-mode using the hedeleg CSR. Synthetic VS/VU-mode exceptions should also honor hedeleg. They should be redirected to VS-mode if and only if delegated by HS-mode. Signed-off-by: dramforever Reviewed-by: Xiang W Reviewed-by: Anup Patel --- diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 2c509e5..ee3e4e9 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -99,17 +99,14 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, if (prev_mode != PRV_S && prev_mode != PRV_U) return SBI_ENOTSUPP; - /* For certain exceptions from VS/VU-mode we redirect to VS-mode */ + /* If exceptions came from VS/VU-mode, redirect to VS-mode if + * delegated in hedeleg + */ if (misa_extension('H') && prev_virt) { - switch (trap->cause) { - case CAUSE_FETCH_PAGE_FAULT: - case CAUSE_LOAD_PAGE_FAULT: - case CAUSE_STORE_PAGE_FAULT: + if ((trap->cause < __riscv_xlen) && + (csr_read(CSR_HEDELEG) & BIT(trap->cause))) { next_virt = TRUE; - break; - default: - break; - }; + } } /* Update MSTATUS MPV bits */