diff mbox series

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

Message ID 20250429142549.3673976-7-rkrcmar@ventanamicro.com
State New
Headers show
Series Reset more security-related CSRs | expand

Commit Message

Radim Krčmář April 29, 2025, 2:25 p.m. UTC
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@brainfault.org>
Signed-off-by: Radim Krčmář <rkrcmar@ventanamicro.com>
---
v2: Add Reviewed-by [Anup]
---
 lib/sbi/sbi_hart.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

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);