1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This provides a simplified version of getcontext and
6 // setcontext. They are like the corresponding functions
7 // in libc, but we only save/restore the callee-save
8 // registers and PC, SP. Unlike the libc functions, we
9 // don't save/restore the signal masks and floating point
12 #if defined(__x86_64__) && defined(__linux__) && !defined(__CET__)
23 .globl __go_getcontext
26 movq %rbx, RBX_OFF(%rdi)
27 movq %rbp, RBP_OFF(%rdi)
28 movq %r12, R12_OFF(%rdi)
29 movq %r13, R13_OFF(%rdi)
30 movq %r14, R14_OFF(%rdi)
31 movq %r15, R15_OFF(%rdi)
33 movq (%rsp), %rax // return PC
34 movq %rax, PC_OFF(%rdi)
35 leaq 8(%rsp), %rax // the SP before pushing return PC
36 movq %rax, SP_OFF(%rdi)
40 .globl __go_setcontext
43 movq RBX_OFF(%rdi), %rbx
44 movq RBP_OFF(%rdi), %rbp
45 movq R12_OFF(%rdi), %r12
46 movq R13_OFF(%rdi), %r13
47 movq R14_OFF(%rdi), %r14
48 movq R15_OFF(%rdi), %r15
49 movq SP_OFF(%rdi), %rsp
50 movq PC_OFF(%rdi), %rdx
54 .globl __go_makecontext
59 // Align the SP, and push a dummy return address.
64 movq %rdx, SP_OFF(%rdi)
65 movq %rsi, PC_OFF(%rdi)
69 .section .note.GNU-split-stack,"",@progbits
70 .section .note.GNU-no-split-stack,"",@progbits
74 .section .note.GNU-stack,"",@progbits