2018-11-20 12:59:10 +03:00
|
|
|
##
|
2018-11-20 13:16:29 +03:00
|
|
|
## This file is part of the "Coroutine" project and released under the MIT License.
|
2018-11-20 12:59:10 +03:00
|
|
|
##
|
|
|
|
## Created by Samuel Williams on 10/5/2018.
|
2019-12-28 02:41:47 +03:00
|
|
|
## Copyright, 2018, by Samuel Williams.
|
2018-11-20 12:59:10 +03:00
|
|
|
##
|
|
|
|
|
2019-05-16 12:58:17 +03:00
|
|
|
#define TOKEN_PASTE(x,y) x##y
|
|
|
|
#define PREFIXED_SYMBOL(prefix,name) TOKEN_PASTE(prefix,name)
|
|
|
|
|
2018-11-20 12:59:10 +03:00
|
|
|
.text
|
|
|
|
|
2019-05-16 12:58:17 +03:00
|
|
|
.globl PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer)
|
|
|
|
PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer):
|
2018-11-20 12:59:10 +03:00
|
|
|
|
2023-08-25 04:28:33 +03:00
|
|
|
# Make space on the stack for 6 registers:
|
|
|
|
subq $48, %rsp
|
|
|
|
|
|
|
|
# Save caller state:
|
|
|
|
movq %rbp, 40(%rsp)
|
|
|
|
movq %rbx, 32(%rsp)
|
|
|
|
movq %r12, 24(%rsp)
|
|
|
|
movq %r13, 16(%rsp)
|
|
|
|
movq %r14, 8(%rsp)
|
|
|
|
movq %r15, (%rsp)
|
|
|
|
|
|
|
|
# Save caller stack pointer:
|
2018-11-20 12:59:10 +03:00
|
|
|
movq %rsp, (%rdi)
|
2018-11-20 13:17:00 +03:00
|
|
|
|
2023-08-25 04:28:33 +03:00
|
|
|
# Restore callee stack pointer:
|
2018-11-20 12:59:10 +03:00
|
|
|
movq (%rsi), %rsp
|
2018-11-20 13:17:00 +03:00
|
|
|
|
2019-06-24 14:54:19 +03:00
|
|
|
# Restore callee state
|
2023-08-25 04:28:33 +03:00
|
|
|
movq 40(%rsp), %rbp
|
|
|
|
movq 32(%rsp), %rbx
|
|
|
|
movq 24(%rsp), %r12
|
|
|
|
movq 16(%rsp), %r13
|
|
|
|
movq 8(%rsp), %r14
|
|
|
|
movq (%rsp), %r15
|
|
|
|
|
|
|
|
# Adjust stack pointer back:
|
|
|
|
addq $48, %rsp
|
|
|
|
|
|
|
|
# Put the first argument into the return value:
|
2018-11-20 12:59:23 +03:00
|
|
|
movq %rdi, %rax
|
2018-11-20 13:17:00 +03:00
|
|
|
|
2018-11-20 12:59:10 +03:00
|
|
|
# We pop the return address and jump to it
|
|
|
|
ret
|
2018-11-24 14:35:34 +03:00
|
|
|
|
2021-03-05 01:12:58 +03:00
|
|
|
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(__ELF__)
|
2018-11-24 14:35:34 +03:00
|
|
|
.section .note.GNU-stack,"",%progbits
|
|
|
|
#endif
|