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
|
|
|
;;
|
|
|
|
|
2018-11-28 04:04:39 +03:00
|
|
|
.386
|
2018-11-20 12:59:10 +03:00
|
|
|
.model flat
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
2018-11-20 13:17:44 +03:00
|
|
|
assume fs:nothing
|
|
|
|
|
2018-11-20 12:59:10 +03:00
|
|
|
; Using fastcall is a big win (and it's the same has how x64 works).
|
|
|
|
; In coroutine transfer, the arguments are passed in ecx and edx. We don't need
|
|
|
|
; to touch these in order to pass them to the destination coroutine.
|
|
|
|
|
|
|
|
@coroutine_transfer@8 proc
|
2018-11-20 13:17:39 +03:00
|
|
|
; Save the thread information block:
|
|
|
|
push fs:[0]
|
|
|
|
push fs:[4]
|
|
|
|
push fs:[8]
|
|
|
|
|
|
|
|
; Save caller registers:
|
2018-11-20 12:59:10 +03:00
|
|
|
push ebp
|
|
|
|
push ebx
|
|
|
|
push edi
|
|
|
|
push esi
|
2018-11-20 13:17:00 +03:00
|
|
|
|
2018-11-20 13:17:39 +03:00
|
|
|
; Save caller stack pointer:
|
2018-11-20 12:59:10 +03:00
|
|
|
mov dword ptr [ecx], esp
|
2018-11-20 13:17:00 +03:00
|
|
|
|
2018-11-20 13:17:39 +03:00
|
|
|
; Restore callee stack pointer:
|
2018-11-20 12:59:10 +03:00
|
|
|
mov esp, dword ptr [edx]
|
|
|
|
|
2018-11-20 13:17:39 +03:00
|
|
|
; Restore callee stack:
|
2018-11-20 12:59:10 +03:00
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
pop ebp
|
|
|
|
|
2018-11-20 13:17:39 +03:00
|
|
|
; Restore the thread information block:
|
|
|
|
pop fs:[8]
|
|
|
|
pop fs:[4]
|
|
|
|
pop fs:[0]
|
|
|
|
|
|
|
|
; Save the first argument as the return value:
|
2018-11-20 12:59:10 +03:00
|
|
|
mov eax, dword ptr ecx
|
|
|
|
|
2018-11-20 13:17:39 +03:00
|
|
|
; Jump to the address on the stack:
|
2018-11-20 12:59:10 +03:00
|
|
|
ret
|
|
|
|
@coroutine_transfer@8 endp
|
|
|
|
|
|
|
|
end
|