mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 22:43:40 +00:00
runtime/interrupt: add Checkpoint type
This type can be used to jump back to a previous position in a program
from inside an interrupt. This is useful for baremetal systems that
implement wfi but not wfe, and therefore have no easy (race-free) way to
wait until a flag gets changed inside an interrupt. This is an issue on
RISC-V, where this is racy (the interrupt might happen after the check
but before the wfi instruction):
configureInterrupt()
for flag.Load() != 0 {
riscv.Asm("wfi")
}
This commit is contained in:
committed by
Ron Evans
parent
64a30424da
commit
3a2188fc7b
@@ -50,3 +50,12 @@ tinygo_longjmp:
|
||||
lw sp, 0(a0) // jumpSP
|
||||
lw a1, REGSIZE(a0) // jumpPC
|
||||
jr a1
|
||||
|
||||
.section .text.tinygo_checkpointJump
|
||||
.global tinygo_checkpointJump
|
||||
tinygo_checkpointJump:
|
||||
// Note: the code we jump to assumes a0 is non-zero, which is already the
|
||||
// case because that's the stack pointer.
|
||||
mv sp, a0 // jumpSP
|
||||
csrw mepc, a1 // update MEPC value, so we resume there after the mret
|
||||
mret // jump to jumpPC
|
||||
|
||||
Reference in New Issue
Block a user