Skip to contentSkip to conversation

lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.

PATCH Superseded Pope B.Lei 3 participants 3 messages Apr 9, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Pope B.Lei

author
#0 lore raw

PATCH 1/1 lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.

Although Mstatus.MPV is set, before executing mret, access to VS mode registers should use the actual register addresses, not the pseudonyms of S registers.

---
V1 -> V2: Simplify the if condition
-

 lib/sbi/sbi_hart.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
lib/sbi/sbi_hart.c +11 -4
index 3d13694..ccdd12f 100644
@@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
 	csr_write(CSR_MEPC, next_addr);
 
 	if (next_mode == PRV_S) {
-		csr_write(CSR_STVEC, next_addr);
-		csr_write(CSR_SSCRATCH, 0);
-		csr_write(CSR_SIE, 0);
-		csr_write(CSR_SATP, 0);
+		if (next_virt) {
+		    csr_write(CSR_VSTVEC, next_addr);
+		    csr_write(CSR_VSSCRATCH, 0);
+		    csr_write(CSR_VSIE, 0);
+		    csr_write(CSR_VSATP, 0);
+		} else {
+		    csr_write(CSR_STVEC, next_addr);
+		    csr_write(CSR_SSCRATCH, 0);
+		    csr_write(CSR_SIE, 0);
+		    csr_write(CSR_SATP, 0);
+		}
 	} else if (next_mode == PRV_U) {
 		if (misa_extension('N')) {
 			csr_write(CSR_UTVEC, next_addr);
Signature · 1 line
2.35.2.windows.1
#1 lore raw

PATCH 1/1 lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.

? 2024-04-09???? 17:23 +0800?Pope B.Lei???

Quoted 6 lines

Although Mstatus.MPV is set, before executing mret, access to VS mode registers should use the actual register addresses, not the pseudonyms of S registers.

---

Next time, please remember that v2 is missing from the subject.

otherwise look good to me.

Quoted 35 lines

V1 -> V2: Simplify the if condition
-
?lib/sbi/sbi_hart.c | 15 +++++++++++----
?1 file changed, 11 insertions(+), 4 deletions(-)

lib/sbi/sbi_hart.c +0 -0
index 3d13694..ccdd12f 100644
@@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
 ?	csr_write(CSR_MEPC, next_addr);

?
? if (next_mode == PRV_S) {

lib/sbi/sbi_hart.c +11 -4
-		csr_write(CSR_STVEC, next_addr);
-		csr_write(CSR_SSCRATCH, 0);
-		csr_write(CSR_SIE, 0);
-		csr_write(CSR_SATP, 0);
+		if (next_virt) {
+		??? csr_write(CSR_VSTVEC, next_addr);
+		??? csr_write(CSR_VSSCRATCH, 0);
+		??? csr_write(CSR_VSIE, 0);
+		??? csr_write(CSR_VSATP, 0);
+		} else {
+		??? csr_write(CSR_STVEC, next_addr);
+		??? csr_write(CSR_SSCRATCH, 0);
+		??? csr_write(CSR_SIE, 0);
+		??? csr_write(CSR_SATP, 0);
+		}

? } else if (next_mode == PRV_U) {
? if (misa_extension('N')) {
? csr_write(CSR_UTVEC, next_addr);

Signature · 1 line
2.35.2.windows.1
#2 lore raw

PATCH 1/1 lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.

In reply to Pope B.Lei
Quoted 23 lines · Pope B.Lei

Although Mstatus.MPV is set, before executing mret, access to VS mode registers should use the actual register addresses, not the pseudonyms of S registers.

---
V1 -> V2: Simplify the if condition
-

 lib/sbi/sbi_hart.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
lib/sbi/sbi_hart.c +0 -4
index 3d13694..ccdd12f 100644
@@ -1041,10 +1041,17 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,
 	csr_write(CSR_MEPC, next_addr);
 
 	if (next_mode == PRV_S) {
-		csr_write(CSR_STVEC, next_addr);
-		csr_write(CSR_SSCRATCH, 0);
-		csr_write(CSR_SIE, 0);
-		csr_write(CSR_SATP, 0);

lib/sbi/sbi_hart.c sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1, · line 1053

Quoted 10 lines
lib/sbi/sbi_hart.c +10 -0
+		if (next_virt) {
+		    csr_write(CSR_VSTVEC, next_addr);
+		    csr_write(CSR_VSSCRATCH, 0);
+		    csr_write(CSR_VSIE, 0);
+		    csr_write(CSR_VSATP, 0);
+		} else {
+		    csr_write(CSR_STVEC, next_addr);
+		    csr_write(CSR_SSCRATCH, 0);
+		    csr_write(CSR_SIE, 0);
+		    csr_write(CSR_SATP, 0);

Indentation should use tabs.

Thanks,
drew

Quoted 12 lines
lib/sbi/sbi_hart.c +1 -0
+		}
 	} else if (next_mode == PRV_U) {
 		if (misa_extension('N')) {
 			csr_write(CSR_UTVEC, next_addr);
Signature · 7 lines
2.35.2.windows.1


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