Skip to contentSkip to conversation

lib: sbi_hart: Enable hcontext and scontext

PATCH New Nylon Chen 2 participants 3 messages Feb 10, 2023 – Feb 27, 2023 RISC-V

lore
Share & tools
lore

Nylon Chen

author
#0 lore raw

PATCH 1/1 lib: sbi_hart: Enable hcontext and scontext

According to the description in "riscv-state-enable[0]", to access h/scontext in S-Mode, we need to enable the 57th bit.

If it is not enabled, an "illegal instruction" error will occur.

---
 include/sbi/riscv_encoding.h | 2 ++
 lib/sbi/sbi_hart.c           | 1 +
 2 files changed, 3 insertions(+)
include/sbi/riscv_encoding.h +2 -0
index b0f08c8..4ebed97 100644
@@ -736,6 +736,8 @@
 #define SMSTATEEN0_CS			(_ULL(1) << SMSTATEEN0_CS_SHIFT)
 #define SMSTATEEN0_FCSR_SHIFT		1
 #define SMSTATEEN0_FCSR			(_ULL(1) << SMSTATEEN0_FCSR_SHIFT)
+#define SMSTATEEN0_CONTEXT_SHIFT	57
+#define SMSTATEEN0_CONTEXT		(_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)
 #define SMSTATEEN0_IMSIC_SHIFT		58
 #define SMSTATEEN0_IMSIC		(_ULL(1) << SMSTATEEN0_IMSIC_SHIFT)
 #define SMSTATEEN0_AIA_SHIFT		59
lib/sbi/sbi_hart.c +1 -0
index 02ce991..5e06918 100644
@@ -90,6 +90,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
 		mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32;
 #endif
 		mstateen_val |= SMSTATEEN_STATEN;
+		mstateen_val |= SMSTATEEN0_CONTEXT;
 		mstateen_val |= SMSTATEEN0_HSENVCFG;
 
 		if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA))
Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/1 lib: sbi_hart: Enable hcontext and scontext

Quoted 10 lines · Nylon Chen

According to the description in "riscv-state-enable[0]", to access h/scontext in S-Mode, we need to enable the 57th bit.

If it is not enabled, an "illegal instruction" error will occur.

Looks good to me.

Regards,
Anup

Quoted 38 lines
---
 include/sbi/riscv_encoding.h | 2 ++
 lib/sbi/sbi_hart.c           | 1 +
 2 files changed, 3 insertions(+)
include/sbi/riscv_encoding.h +2 -0
index b0f08c8..4ebed97 100644
@@ -736,6 +736,8 @@
 #define SMSTATEEN0_CS                  (_ULL(1) << SMSTATEEN0_CS_SHIFT)
 #define SMSTATEEN0_FCSR_SHIFT          1
 #define SMSTATEEN0_FCSR                        (_ULL(1) << SMSTATEEN0_FCSR_SHIFT)
+#define SMSTATEEN0_CONTEXT_SHIFT       57
+#define SMSTATEEN0_CONTEXT             (_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)
 #define SMSTATEEN0_IMSIC_SHIFT         58
 #define SMSTATEEN0_IMSIC               (_ULL(1) << SMSTATEEN0_IMSIC_SHIFT)
 #define SMSTATEEN0_AIA_SHIFT           59
lib/sbi/sbi_hart.c +1 -1
index 02ce991..5e06918 100644
@@ -90,6 +90,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
                mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32;
 #endif
                mstateen_val |= SMSTATEEN_STATEN;
+               mstateen_val |= SMSTATEEN0_CONTEXT;
                mstateen_val |= SMSTATEEN0_HSENVCFG;
 
                if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA))
--

2.36.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Applied
#2 lore raw

PATCH 1/1 lib: sbi_hart: Enable hcontext and scontext

In reply to Nylon Chen
Quoted 10 lines · Nylon Chen

According to the description in "riscv-state-enable[0]", to access h/scontext in S-Mode, we need to enable the 57th bit.

If it is not enabled, an "illegal instruction" error will occur.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 38 lines
---
 include/sbi/riscv_encoding.h | 2 ++
 lib/sbi/sbi_hart.c           | 1 +
 2 files changed, 3 insertions(+)
include/sbi/riscv_encoding.h +2 -0
index b0f08c8..4ebed97 100644
@@ -736,6 +736,8 @@
 #define SMSTATEEN0_CS                  (_ULL(1) << SMSTATEEN0_CS_SHIFT)
 #define SMSTATEEN0_FCSR_SHIFT          1
 #define SMSTATEEN0_FCSR                        (_ULL(1) << SMSTATEEN0_FCSR_SHIFT)
+#define SMSTATEEN0_CONTEXT_SHIFT       57
+#define SMSTATEEN0_CONTEXT             (_ULL(1) << SMSTATEEN0_CONTEXT_SHIFT)
 #define SMSTATEEN0_IMSIC_SHIFT         58
 #define SMSTATEEN0_IMSIC               (_ULL(1) << SMSTATEEN0_IMSIC_SHIFT)
 #define SMSTATEEN0_AIA_SHIFT           59
lib/sbi/sbi_hart.c +1 -1
index 02ce991..5e06918 100644
@@ -90,6 +90,7 @@ static void mstatus_init(struct sbi_scratch *scratch)
                mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32;
 #endif
                mstateen_val |= SMSTATEEN_STATEN;
+               mstateen_val |= SMSTATEEN0_CONTEXT;
                mstateen_val |= SMSTATEEN0_HSENVCFG;
 
                if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMAIA))
--

2.36.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi