|
| 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 | + } |
0 commit comments