aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Chien Peter Lin <peterlin@andestech.com>2024-03-28 11:33:02 +0800
committerAnup Patel <anup@brainfault.org>2024-04-05 18:02:29 +0530
commit29ecda9c2065afd3fb2f8cc465bc096d545d825e (patch)
tree3b2a1bb567576c8eb426abb01c7032001554b094
parent7862c244bce024e921705d7d2e19cf855557d481 (diff)
downloadopensbi-29ecda9c2065afd3fb2f8cc465bc096d545d825e.zip
opensbi-29ecda9c2065afd3fb2f8cc465bc096d545d825e.tar.gz
opensbi-29ecda9c2065afd3fb2f8cc465bc096d545d825e.tar.bz2
sbi: sbi_domain_context: Check privilege spec version before accessing S-mode CSRs
SCOUNTEREN and SENVCFG may not be supported on certain RISC-V core, so check the existence of these CSRs via privilege spec version to prevent illegal instructions. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Signed-off-by: Alvin Chang <alvinga@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
-rwxr-xr-xlib/sbi/sbi_domain_context.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index d6843a6..8daf629 100755
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -55,8 +55,10 @@ static void switch_to_next_domain_context(struct sbi_context *ctx,
ctx->stval = csr_swap(CSR_STVAL, dom_ctx->stval);
ctx->sip = csr_swap(CSR_SIP, dom_ctx->sip);
ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
- ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
- ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
+ ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
+ if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
+ ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
/* Save current trap state and restore target domain's trap state */
trap_regs = (struct sbi_trap_regs *)(csr_read(CSR_MSCRATCH) -