aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/device
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-09-28 00:04:25 +0200
committerRon Evans <[email protected]>2021-10-04 21:27:00 +0200
commitb31d24138831f328cc43fbb94b935b3264399578 (patch)
treec62722976d7fd05d550952674563adb0c40d9228 /src/device
parenta6246e60f3d9bd54095e1a28baca2d799cd1cb15 (diff)
downloadtinygo-b31d24138831f328cc43fbb94b935b3264399578.tar.gz
tinygo-b31d24138831f328cc43fbb94b935b3264399578.zip
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).
Diffstat (limited to 'src/device')
-rw-r--r--src/device/riscv/riscv.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/device/riscv/riscv.go b/src/device/riscv/riscv.go
index e4f9254b7..b621a17c4 100644
--- a/src/device/riscv/riscv.go
+++ b/src/device/riscv/riscv.go
@@ -25,13 +25,14 @@ func AsmFull(asm string, regs map[string]interface{}) uintptr
func DisableInterrupts() uintptr {
// Note: this can be optimized with a CSRRW instruction, which atomically
// swaps the value and returns the old value.
- mask := MIE.Get()
- MIE.Set(0)
+ mask := MSTATUS.Get()
+ MSTATUS.ClearBits(1 << 3) // clear the MIE bit
return mask
}
// EnableInterrupts enables all interrupts again. The value passed in must be
// the mask returned by DisableInterrupts.
func EnableInterrupts(mask uintptr) {
- MIE.Set(mask)
+ mask &= 1 << 3 // clear all bits except for the MIE bit
+ MSTATUS.SetBits(mask) // set the MIE bit, if it was previously cleared
}