mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
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>
This commit is contained in:

committed by
Anup Patel

parent
7862c244bc
commit
29ecda9c20
@@ -55,7 +55,9 @@ static void switch_to_next_domain_context(struct sbi_context *ctx,
|
|||||||
ctx->stval = csr_swap(CSR_STVAL, dom_ctx->stval);
|
ctx->stval = csr_swap(CSR_STVAL, dom_ctx->stval);
|
||||||
ctx->sip = csr_swap(CSR_SIP, dom_ctx->sip);
|
ctx->sip = csr_swap(CSR_SIP, dom_ctx->sip);
|
||||||
ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
|
ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
|
||||||
|
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
|
||||||
ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
|
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);
|
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
|
||||||
|
|
||||||
/* Save current trap state and restore target domain's trap state */
|
/* Save current trap state and restore target domain's trap state */
|
||||||
|
Reference in New Issue
Block a user