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.
|
|
|
|
;; Copyright, 2018, by Samuel Williams. All rights reserved.
|
|
|
|
;;
|
|
|
|
|
2018-11-27 20:04:39 -05:00
|
|
|
.386
|
2018-11-20 04:59:10 -05:00
|
|
|
.model flat
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
2018-11-20 05:17:44 -05:00
|
|
|
assume fs:nothing
|
|
|
|
|
2018-11-20 04:59:10 -05: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 05:17:39 -05:00
|
|
|
; Save the thread information block:
|
|
|
|
push fs:[0]
|
|
|
|
push fs:[4]
|
|
|
|
push fs:[8]
|
|
|
|
|
|
|
|
; Save caller registers:
|
2018-11-20 04:59:10 -05:00
|
|
|
push ebp
|
|
|
|
push ebx
|
|
|
|
push edi
|
|
|
|
push esi
|
2018-11-20 05:17:00 -05:00
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; Save caller stack pointer:
|
2018-11-20 04:59:10 -05:00
|
|
|
mov dword ptr [ecx], esp
|
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 esp, dword ptr [edx]
|
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; Restore callee stack:
|
2018-11-20 04:59:10 -05:00
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebx
|
|
|
|
pop ebp
|
|
|
|
|
2018-11-20 05:17:39 -05: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 04:59:10 -05:00
|
|
|
mov eax, dword ptr ecx
|
|
|
|
|
2018-11-20 05:17:39 -05:00
|
|
|
; Jump to the address on the stack:
|
2018-11-20 04:59:10 -05:00
|
|
|
ret
|
|
|
|
@coroutine_transfer@8 endp
|
|
|
|
|
|
|
|
end
|