-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch_context.S
48 lines (40 loc) · 1.14 KB
/
switch_context.S
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
.file "switch_context.S"
.text
.globl switch_context
.type switch_context,@function
.align 16
switch_context:
leaq -56(%rsp), %rsp
movq %rdi, (%rsp) /* save suspended coro_t* */
movq %r12, 8(%rsp)
movq %r13, 16(%rsp)
movq %r14, 24(%rsp)
movq %r15, 32(%rsp)
movq %rbx, 40(%rsp)
movq %rbp, 48(%rsp)
movq %rsp, %rax /* return suspended context */
movq %rsi, %rsp /* restore context */
movq 56(%rsp), %r8 /* return point */
movq 8(%rsp), %r12
movq 16(%rsp), %r13
movq 24(%rsp), %r14
movq 32(%rsp), %r15
movq 40(%rsp), %rbx
movq 48(%rsp), %rbp
leaq 64(%rsp), %rsp
movq %rax, %rsi /* for main(coro_t*, context) 2rd argument */
jmp *%r8
.size switch_context,.-switch_context
.section .note.GNU-stack,"",%progbits
.text
.globl make_context
.type make_context,@function
.align 16
make_context:
andq $-16, %rdi /* 16 bytes align for movdqa */
leaq -56(%rdi), %rdi
movq %rsi, 56(%rdi) /* set entry */
movq %rdi, %rax /* return updated context */
retq
.size make_context,.-make_context
.section .note.GNU-stack,"",%progbits