github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/internal/task/task_stack_arm64.S (about) 1 #ifdef __MACH__ 2 .global _tinygo_startTask 3 _tinygo_startTask: 4 #else 5 .section .text.tinygo_startTask 6 .global tinygo_startTask 7 tinygo_startTask: 8 #endif 9 .cfi_startproc 10 // Small assembly stub for starting a goroutine. This is already run on the 11 // new stack, with the callee-saved registers already loaded. 12 // Most importantly, x19 contains the pc of the to-be-started function and 13 // x20 contains the only argument it is given. Multiple arguments are packed 14 // into one by storing them in a new allocation. 15 16 // Indicate to the unwinder that there is nothing to unwind, this is the 17 // root frame. It avoids the following (bogus) error message in GDB: 18 // Backtrace stopped: previous frame identical to this frame (corrupt stack?) 19 .cfi_undefined lr 20 21 // Set the first argument of the goroutine start wrapper, which contains all 22 // the arguments. 23 mov x0, x20 24 25 // Branch to the "goroutine start" function. By using blx instead of bx, 26 // we'll return here instead of tail calling. 27 blr x19 28 29 // After return, exit this goroutine. This is a tail call. 30 #ifdef __MACH__ 31 b _tinygo_pause 32 #else 33 b tinygo_pause 34 #endif 35 .cfi_endproc 36 #ifndef __MACH__ 37 #endif 38 39 40 #ifdef __MACH__ 41 .global _tinygo_swapTask 42 _tinygo_swapTask: 43 #else 44 .global tinygo_swapTask 45 tinygo_swapTask: 46 #endif 47 // This function gets the following parameters: 48 // x0 = newStack uintptr 49 // x1 = oldStack *uintptr 50 51 // Save all callee-saved registers: 52 stp x19, x20, [sp, #-160]! 53 stp x21, x22, [sp, #16] 54 stp x23, x24, [sp, #32] 55 stp x25, x26, [sp, #48] 56 stp x27, x28, [sp, #64] 57 stp x29, x30, [sp, #80] 58 stp d8, d9, [sp, #96] 59 stp d10, d11, [sp, #112] 60 stp d12, d13, [sp, #128] 61 stp d14, d15, [sp, #144] 62 63 // Save the current stack pointer in oldStack. 64 mov x8, sp 65 str x8, [x1] 66 67 // Switch to the new stack pointer. 68 mov sp, x0 69 70 // Restore stack state and return. 71 ldp d14, d15, [sp, #144] 72 ldp d12, d13, [sp, #128] 73 ldp d10, d11, [sp, #112] 74 ldp d8, d9, [sp, #96] 75 ldp x29, x30, [sp, #80] 76 ldp x27, x28, [sp, #64] 77 ldp x25, x26, [sp, #48] 78 ldp x23, x24, [sp, #32] 79 ldp x21, x22, [sp, #16] 80 ldp x19, x20, [sp], #160 81 ret