Skip to content

Commit 29ecda9

Browse files
lyctwavpatel
authored andcommitted
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>
1 parent 7862c24 commit 29ecda9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/sbi/sbi_domain_context.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ static void switch_to_next_domain_context(struct sbi_context *ctx,
5555
ctx->stval = csr_swap(CSR_STVAL, dom_ctx->stval);
5656
ctx->sip = csr_swap(CSR_SIP, dom_ctx->sip);
5757
ctx->satp = csr_swap(CSR_SATP, dom_ctx->satp);
58-
ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
59-
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
58+
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10)
59+
ctx->scounteren = csr_swap(CSR_SCOUNTEREN, dom_ctx->scounteren);
60+
if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12)
61+
ctx->senvcfg = csr_swap(CSR_SENVCFG, dom_ctx->senvcfg);
6062

6163
/* Save current trap state and restore target domain's trap state */
6264
trap_regs = (struct sbi_trap_regs *)(csr_read(CSR_MSCRATCH) -

0 commit comments

Comments
 (0)