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.
This commit is contained in:
Ayke van Laethem
2020-09-24 23:56:48 +02:00
committed by Ron Evans
parent bb58783158
commit abb09e869e
9 changed files with 169 additions and 268 deletions
+11 -2
View File
@@ -2,7 +2,16 @@
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.
//export tinygo_getSystemStackPointer
func getSystemStackPointer() uintptr
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
}