github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/device/riscv/riscv.go (about) 1 package riscv 2 3 // Run the given assembly code. The code will be marked as having side effects, 4 // as it doesn't produce output and thus would normally be eliminated by the 5 // optimizer. 6 func Asm(asm string) 7 8 // Run the given inline assembly. The code will be marked as having side 9 // effects, as it would otherwise be optimized away. The inline assembly string 10 // recognizes template values in the form {name}, like so: 11 // 12 // arm.AsmFull( 13 // "st {value}, {result}", 14 // map[string]interface{}{ 15 // "value": 1 16 // "result": &dest, 17 // }) 18 // 19 // You can use {} in the asm string (which expands to a register) to set the 20 // return value. 21 func AsmFull(asm string, regs map[string]interface{}) uintptr 22 23 // DisableInterrupts disables all interrupts, and returns the old interrupt 24 // state. 25 func DisableInterrupts() uintptr { 26 // Note: this can be optimized with a CSRRW instruction, which atomically 27 // swaps the value and returns the old value. 28 mask := MSTATUS.Get() 29 MSTATUS.ClearBits(1 << 3) // clear the MIE bit 30 return mask 31 } 32 33 // EnableInterrupts enables all interrupts again. The value passed in must be 34 // the mask returned by DisableInterrupts. 35 func EnableInterrupts(mask uintptr) { 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 38 }