tinygo/src/runtime/scheduler_tasks.go
Ayke van Laethem abb09e869e runtime, internal/task: refactor to simplify stack switching
The Cortex-M target isn't much changed, but much of the logic for the
AVR stack switcher that was previously in assembly has now been moved to
Go to make it more maintainable and in fact smaller in code size. Three
functions (tinygo_getCurrentStackPointer, tinygo_switchToTask,
tinygo_switchToScheduler) have been changed to one: tinygo_swapTask.

This reduction in assembly code should make the code more maintainable
and should make it easier to port stack switching to other
architectures.

I've also moved the assembly files to src/internal/task, which seems
like a more appropriate location to me.
2020-12-05 09:02:11 +01:00

17 строки
443 Б
Go

// +build scheduler.tasks
package runtime
import "internal/task"
// getSystemStackPointer returns the current stack pointer of the system stack.
// This is not necessarily the same as the current stack pointer.
func getSystemStackPointer() uintptr {
// TODO: this always returns the correct stack on Cortex-M, so don't bother
// comparing against 0.
sp := task.SystemStack()
if sp == 0 {
sp = getCurrentStackPointer()
}
return sp
}