2018-11-20 04:59:10 -05:00
|
|
|
;;
|
2018-11-20 05:16:29 -05:00
|
|
|
;; This file is part of the "Coroutine" project and released under the MIT License.
|
2018-11-20 04:59:10 -05:00
|
|
|
;;
|
|
|
|
;; Created by Samuel Williams on 10/5/2018.
|
2019-12-27 18:41:47 -05:00
|
|
|
;; Copyright, 2018, by Samuel Williams.
|
2018-11-20 04:59:10 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
coroutine_transfer proc
|
2018-11-20 05:17:39 -05:00
|
|
|
; Save the thread information block:
|
2018-11-20 05:17:44 -05:00
|
|
|
push qword ptr gs:[8]
|
|
|
|
push qword ptr gs:[16]
|
2018-11-20 05:17:39 -05:00
|
|
|
|
|
|
|
; Save caller registers:
|
2018-11-20 04:59:10 -05:00
|
|
|
push rbp
|
|
|
|
push rbx
|
|
|
|
push rdi
|
|
|
|
push rsi
|
|
|
|
push r12
|
|
|
|
push r13
|
|
|
|
push r14
|
|
|
|
push r15
|
2018-11-20 05:17:00 -05:00
|
|
|
|
2018-11-20 05:17:44 -05:00
|
|
|
movaps [rsp - 24], xmm6
|
|
|
|
movaps [rsp - 40], xmm7
|
|
|
|
movaps [rsp - 56], xmm8
|
|
|
|
movaps [rsp - 72], xmm9
|
|
|
|
movaps [rsp - 88], xmm10
|
|
|
|
movaps [rsp - 104], xmm11
|
|
|
|
movaps [rsp - 120], xmm12
|
|
|
|
movaps [rsp - 136], xmm13
|
|
|
|
movaps [rsp - 152], xmm14
|
|
|
|
movaps [rsp - 168], xmm15
|
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; Save caller stack pointer:
|
2018-11-20 05:17:12 -05:00
|
|
|
mov [rcx], rsp
|
2018-11-20 05:17:00 -05:00
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; Restore callee stack pointer:
|
2018-11-20 04:59:10 -05:00
|
|
|
mov rsp, [rdx]
|
|
|
|
|
2018-11-20 05:17:44 -05:00
|
|
|
movaps xmm15, [rsp - 168]
|
|
|
|
movaps xmm14, [rsp - 152]
|
|
|
|
movaps xmm13, [rsp - 136]
|
|
|
|
movaps xmm12, [rsp - 120]
|
|
|
|
movaps xmm11, [rsp - 104]
|
|
|
|
movaps xmm10, [rsp - 88]
|
|
|
|
movaps xmm9, [rsp - 72]
|
|
|
|
movaps xmm8, [rsp - 56]
|
|
|
|
movaps xmm7, [rsp - 40]
|
|
|
|
movaps xmm6, [rsp - 24]
|
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; Restore callee stack:
|
2018-11-20 04:59:10 -05:00
|
|
|
pop r15
|
|
|
|
pop r14
|
|
|
|
pop r13
|
|
|
|
pop r12
|
|
|
|
pop rsi
|
|
|
|
pop rdi
|
|
|
|
pop rbx
|
|
|
|
pop rbp
|
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; Restore the thread information block:
|
2018-11-20 05:17:44 -05:00
|
|
|
pop qword ptr gs:[16]
|
|
|
|
pop qword ptr gs:[8]
|
2018-11-20 05:17:39 -05:00
|
|
|
|
|
|
|
; Put the first argument into the return value:
|
2018-11-20 04:59:10 -05:00
|
|
|
mov rax, rcx
|
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; We pop the return address and jump to it:
|
2018-11-20 04:59:10 -05:00
|
|
|
ret
|
|
|
|
coroutine_transfer endp
|
|
|
|
|
2018-11-20 05:17:44 -05:00
|
|
|
coroutine_trampoline proc
|
|
|
|
; Do not remove this. This forces 16-byte alignment when entering the coroutine.
|
|
|
|
ret
|
|
|
|
coroutine_trampoline endp
|
|
|
|
|
2018-11-20 04:59:10 -05:00
|
|
|
end
|