github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/internal/task/task_stack_esp8266.S (about) 1 //go:build tinygo 2 3 .section .text.tinygo_startTask,"ax",@progbits 4 .global tinygo_startTask 5 .type tinygo_startTask, %function 6 tinygo_startTask: 7 // Small assembly stub for starting a goroutine. This is already run on the 8 // new stack, with the callee-saved registers already loaded. 9 // Most importantly, r4 contains the pc of the to-be-started function and r5 10 // contains the only argument it is given. Multiple arguments are packed 11 // into one by storing them in a new allocation. 12 13 // Set the first argument of the goroutine start wrapper, which contains all 14 // the arguments. 15 mov.n a2, a13 16 17 // Branch to the "goroutine start" function. 18 callx0 a12 19 20 // After return, exit this goroutine. This is a tail call. 21 call0 tinygo_pause 22 .size tinygo_startTask, .-tinygo_startTask 23 24 .global tinygo_swapTask 25 .type tinygo_swapTask, %function 26 tinygo_swapTask: 27 // This function gets the following parameters: 28 // a2 = newStack uintptr 29 // a3 = oldStack *uintptr 30 // Note: 31 // a0 is the return address 32 // a1 is the stack pointer (sp) 33 34 // Save all callee-saved registers: 35 addi sp, sp, -20 36 s32i.n a12, sp, 0 37 s32i.n a13, sp, 4 38 s32i.n a14, sp, 8 39 s32i.n a15, sp, 12 40 s32i.n a0, sp, 16 41 42 // Save the current stack pointer in oldStack. 43 s32i.n sp, a3, 0 44 45 // Switch to the new stack pointer. 46 mov.n sp, a2 47 48 // Load state from new task and branch to the previous position in the 49 // program. 50 l32i.n a12, sp, 0 51 l32i.n a13, sp, 4 52 l32i.n a14, sp, 8 53 l32i.n a15, sp, 12 54 l32i.n a0, sp, 16 55 addi sp, sp, 20 56 ret.n