-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_asm.S
50 lines (43 loc) · 1.03 KB
/
context_asm.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
.extern cur_ctx
.globl my_yeild
#ifdef __x86_64__
my_yeild:
movq cur_ctx, %rsi
movq %rsp, 0(%rsi)
/* Save the callee saved registers */
movq %rbp, 8(%rsi)
movq %r12, 16(%rsi)
movq %r13, 24(%rsi)
movq %r14, 32(%rsi)
movq %r15, 40(%rsi)
my_set:
movq %rdi, cur_ctx /*argument will be in rdi */
/* reload the registers */
movq 0(%rdi), %rsp
movq 8(%rdi), %rbp
movq 16(%rdi), %r12
movq 24(%rdi), %r13
movq 32(%rdi), %r14
movq 40(%rdi), %r15
ret
#endif
#ifdef __i386__
my_yeild:
movl cur_ctx, %eax
movl %esp, 0(%eax)
/* Save the callee saved registers */
movl %ebx, 4(%eax)
movl %esi, 8(%eax)
movl %edi, 12(%eax)
movl %ebp, 16(%eax)
my_set:
movl 4(%esp), %eax /* agrument will be on stack*/
movl %eax, cur_ctx
/* reload the registers */
movl 0(%eax), %esp
movl 4(%eax), %ebx
movl 8(%eax), %esi
movl 12(%eax), %edi
movl 16(%eax), %ebp
ret
#endif