Skip to content

Commit f11cac8

Browse files
spholznico
authored andcommitted
Ports: Cherry-pick an RVVM fix to make it boot serenity guests
Otherwise serenity guests will hang when booted in the RVVM port.
1 parent 6bea755 commit f11cac8

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: LekKit <50500857+LekKit@users.noreply.github.com>
3+
Date: Sun, 24 Mar 2024 23:17:15 +0200
4+
Subject: [PATCH] riscv_csr: Fix dispatch restarting
5+
6+
- Properly check the old value of status CSR to determine if new IRQ bits were set
7+
- Fix build warn with precise FSTATUS
8+
---
9+
src/riscv_csr.c | 7 ++++---
10+
1 file changed, 4 insertions(+), 3 deletions(-)
11+
12+
diff --git a/src/riscv_csr.c b/src/riscv_csr.c
13+
index 55edc0aaeca6ebcc8ab4cafdea08ea5236abd4bd..284e604658416a7e1611c3c06eb0b1a2426362e3 100644
14+
--- a/src/riscv_csr.c
15+
+++ b/src/riscv_csr.c
16+
@@ -77,8 +77,8 @@ static void csr_status_helper(rvvm_hart_t* vm, maxlen_t* dest, maxlen_t mask, ui
17+
{
18+
maxlen_t new_status = *dest;
19+
#ifdef USE_FPU
20+
- bool fpu_was_enabled = bit_cut(vm->csr.status, 13, 2) != FS_OFF;
21+
#ifndef USE_PRECISE_FS
22+
+ bool fpu_was_enabled = bit_cut(vm->csr.status, 13, 2) != FS_OFF;
23+
if (fpu_was_enabled) {
24+
vm->csr.status = bit_replace(vm->csr.status, 13, 2, FS_DIRTY);
25+
}
26+
@@ -117,6 +117,7 @@ static void csr_status_helper(rvvm_hart_t* vm, maxlen_t* dest, maxlen_t mask, ui
27+
}
28+
#endif
29+
csr_helper_masked(&vm->csr.status, dest, mask, op);
30+
+ maxlen_t old_status = *dest;
31+
#ifdef USE_RV64
32+
if (vm->rv64) *dest |= vm->csr.status & 0x3F00000000ULL;
33+
#endif
34+
@@ -127,8 +128,8 @@ static void csr_status_helper(rvvm_hart_t* vm, maxlen_t* dest, maxlen_t mask, ui
35+
riscv_decoder_enable_fpu(vm, fpu_enabled);
36+
}
37+
#endif
38+
- if (bit_cut(vm->csr.status, 0, 4) != bit_cut(new_status, 0, 4)) {
39+
- // IRQ enable bits changed
40+
+ if (bit_cut(new_status, 0, 4) & ~bit_cut(old_status, 0, 4)) {
41+
+ // IRQ enable bits were set
42+
riscv_restart_dispatch(vm);
43+
}
44+
}

Ports/rvvm/patches/ReadMe.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ This problem was also visible in previous v0.5 version of this port,
1717
but back then I thought it's some kind of a temporary problem.
1818
Couldn't reproduce this on any other host OS.
1919

20+
## `0002-riscv_csr-Fix-dispatch-restarting.patch`
21+
22+
riscv_csr: Fix dispatch restarting
23+
24+
- Properly check the old value of status CSR to determine if new IRQ bits were set
25+
- Fix build warn with precise FSTATUS
26+

0 commit comments

Comments
 (0)