[RFC PATCH v4 3/5] lib: sbi: Preserve S/VS indirect CSR selectors
Theodorus Wensan Februanto
theodoruswensanfebruanto025 at gmail.com
Sat Nov 7 15:44:19 PST 2026
Preserve siselect when either Sscsrind or Smaia is available.
When H is implemented, also preserve vsiselect.
This change preserves the selectors only. It does not save
the indirectly selected backing state or IMSIC files.
Link: https://github.com/riscv-software-src/opensbi/issues/433
Signed-off-by: Theodorus Wensan Februanto <theodoruswensanfebruanto025 at gmail.com>
---
lib/sbi/sbi_domain_context.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 9c5c7a7f..b5989516 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -56,6 +56,8 @@ struct hart_context_hext {
unsigned long vstval;
unsigned long vsip;
unsigned long vsatp;
+ /** Virtual supervisor indirect CSR selector */
+ unsigned long vsiselect;
};
/** Context representation for a hart within a domain */
@@ -91,6 +93,10 @@ struct hart_context {
unsigned long srmcfg;
/** Supervisor counter inhibit configuration */
unsigned long scountinhibit;
+ /** Supervisor indirect CSR selector */
+ unsigned long siselect;
+ /** Supervisor control transfer records */
+ struct hart_ctr_context *ctr_ctx;
/** Float context state */
struct sbi_fp_context fp_ctx;
@@ -288,6 +294,13 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
(csr_read64(CSR_MENVCFG) & ENVCFG_CDE))
ctx->scountinhibit = csr_swap(CSR_SCOUNTINHIBIT,
dom_ctx->scountinhibit);
+ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCSRIND) ||
+ has_smaia) {
+ ctx->siselect = csr_swap(CSR_SISELECT, dom_ctx->siselect);
+ if (misa_extension('H'))
+ ctx->hext.vsiselect = csr_swap(CSR_VSISELECT,
+ dom_ctx->hext.vsiselect);
+ }
/* Eager context switch for float */
if (sbi_hart_has_extension(scratch, SBI_HART_EXT_F) ||
--
2.43.0
More information about the opensbi
mailing list