[PATCH v2 5/8] lib: sbi_hart: fix sstateen emulation

Radim Krčmář rkrcmar at ventanamicro.com
Tue Apr 29 07:25:47 PDT 2025


The Sstateen extension defines 4 sstateen registers, but SBI currently
configures the execution environment to throw illegal instruction
exception when accessing sstateen1-3.

SBI should implement all sstateen registers, so delegate the
implementation to hardware by setting the SE bit.

Reviewed-by: Anup Patel <anup at brainfault.org>
Signed-off-by: Radim Krčmář <rkrcmar at ventanamicro.com>
---
v2: Add Reviewed-by [Anup]
---
 lib/sbi/sbi_hart.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c
index bdf66ef767ed..fc37b249b892 100644
--- a/lib/sbi/sbi_hart.c
+++ b/lib/sbi/sbi_hart.c
@@ -111,6 +111,9 @@ static void mstatus_init(struct sbi_scratch *scratch)
 			mstateen_val &= ~SMSTATEEN0_CTR;
 
 		csr_write64(CSR_MSTATEEN0, mstateen_val);
+		csr_write64(CSR_MSTATEEN1, SMSTATEEN_STATEN);
+		csr_write64(CSR_MSTATEEN2, SMSTATEEN_STATEN);
+		csr_write64(CSR_MSTATEEN3, SMSTATEEN_STATEN);
 
 		if (misa_extension('S'))
 			csr_write(CSR_SSTATEEN0, 0);
-- 
2.48.1




More information about the opensbi mailing list