mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 02:57:46 +00:00
d1fe02df23
This moves all scheduler code into a separate file that is only compiled
when there's a scheduler in use (the tasks or asyncify scheduler, which
are both cooperative). The main goal of this change is to make it easier
to add a new "scheduler" based on OS threads.
It also fixes a few subtle issues with `-gc=none`:
- Gosched() panicked. This is now fixed to just return immediately
(the only logical thing to do when there's only one goroutine).
- Timers aren't supported without a scheduler, but the relevant code
was still present and would happily add a timer to the queue. It
just never ran. So now it exits with a runtime error, similar to any
blocking operation.
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
//go:build tinygo.riscv
|
|
|
|
package runtime
|
|
|
|
import "device/riscv"
|
|
|
|
const deferExtraRegs = 0
|
|
|
|
const callInstSize = 4 // 8 without relaxation, maybe 4 with relaxation
|
|
|
|
// RISC-V has a maximum alignment of 16 bytes (both for RV32 and for RV64).
|
|
// Source: https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf
|
|
func align(ptr uintptr) uintptr {
|
|
return (ptr + 15) &^ 15
|
|
}
|
|
|
|
func getCurrentStackPointer() uintptr {
|
|
return uintptr(stacksave())
|
|
}
|
|
|
|
// The safest thing to do here would just be to disable interrupts for
|
|
// procPin/procUnpin. Note that a global variable is safe in this case, as any
|
|
// access to procPinnedMask will happen with interrupts disabled.
|
|
|
|
var procPinnedMask uintptr
|
|
|
|
//go:linkname procPin sync/atomic.runtime_procPin
|
|
func procPin() {
|
|
procPinnedMask = riscv.DisableInterrupts()
|
|
}
|
|
|
|
//go:linkname procUnpin sync/atomic.runtime_procUnpin
|
|
func procUnpin() {
|
|
riscv.EnableInterrupts(procPinnedMask)
|
|
}
|
|
|
|
func waitForEvents() {
|
|
mask := riscv.DisableInterrupts()
|
|
if runqueue := schedulerRunQueue(); runqueue == nil || !runqueue.Empty() {
|
|
riscv.Asm("wfi")
|
|
}
|
|
riscv.EnableInterrupts(mask)
|
|
}
|