blob: 4031c613fe7c5536c70b110b156cafe89f53b4e3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
;;
;; This file is part of the "Coroutine" project and released under the MIT License.
;;
;; Created by Samuel Williams on 10/5/2018.
;; Copyright, 2018, by Samuel Williams. All rights reserved.
;;
.code
coroutine_transfer proc
; Save the thread information block:
push gs:[0x00]
push gs:[0x08]
push gs:[0x10]
; Save caller registers:
push rbp
push rbx
push rdi
push rsi
push r12
push r13
push r14
push r15
; Save caller stack pointer:
mov [rcx], rsp
; Restore callee stack pointer:
mov rsp, [rdx]
; Restore callee stack:
pop r15
pop r14
pop r13
pop r12
pop rsi
pop rdi
pop rbx
pop rbp
; Restore the thread information block:
pop gs:[0x10]
pop gs:[0x08]
pop gs:[0x00]
; Put the first argument into the return value:
mov rax, rcx
; We pop the return address and jump to it:
ret
coroutine_transfer endp
end
|