Skip to content

Commit 95c2fba

Browse files
committed
riscv: use MSTATUS.MIE bit instead of MIE to disable interrupts
This should behave the same but is compatible with the ESP32-C3 which lacks the MIE CSR (but does have the MSTATUS CSR).
1 parent 213cdf6 commit 95c2fba

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/device/riscv/riscv.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ func AsmFull(asm string, regs map[string]interface{}) uintptr
2525
func DisableInterrupts() uintptr {
2626
// Note: this can be optimized with a CSRRW instruction, which atomically
2727
// swaps the value and returns the old value.
28-
mask := MIE.Get()
29-
MIE.Set(0)
28+
mask := MSTATUS.Get()
29+
MSTATUS.ClearBits(1 << 3) // clear the MIE bit
3030
return mask
3131
}
3232

3333
// EnableInterrupts enables all interrupts again. The value passed in must be
3434
// the mask returned by DisableInterrupts.
3535
func EnableInterrupts(mask uintptr) {
36-
MIE.Set(mask)
36+
mask &= 1 << 3 // clear all bits except for the MIE bit
37+
MSTATUS.SetBits(mask) // set the MIE bit, if it was previously cleared
3738
}

0 commit comments

Comments
 (0)