-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcuoco_ctx_swap.S
73 lines (55 loc) · 928 Bytes
/
cuoco_ctx_swap.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#define _esp 0
#define _eip 4
/* ------ */
#define _rsp 0
#define _rip 8
.globl cuoco_ctx_swap
#ifndef __MACH__
.type cuoco_ctx_swap, @function
#endif
cuoco_ctx_swap:
#if defined(__i386__)
pushl %ebx
pushl %ebp
leal 8(%esp),%esp
/* sp,ip */
/* param old ctx */
movl 4(%esp), %eax
movl (%esp), %ecx
movl %ecx, _eip(%eax)
movl %esp, _esp(%eax)
/* param new ctx */
movl 8(%esp), %eax
/* push ret ( ip,sp ) */
movl _eip(%eax), %ecx
movl _esp(%eax), %esp
movl %ecx, (%esp)
leal -8(%esp),%esp
popl %ebp
popl %ebx
movl $0, %eax
ret
#elif defined(__x86_64__)
pushq %r12
pushq %r13
pushq %r14
pushq %r15
pushq %rbx
pushq %rbp
leaq 48(%rsp),%rsp
movq (%rsp), %rcx
movq %rcx, _rip(%rdi)
movq %rsp, _rsp(%rdi)
movq _rsp(%rsi), %rsp
movq _rip(%rsi), %rcx
movq %rcx, (%rsp)
leaq -48(%rsp),%rsp
popq %rbp
popq %rbx
popq %r15
popq %r14
popq %r13
popq %r12
xorl %eax, %eax
ret
#endif