-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_asm.S
47 lines (39 loc) · 948 Bytes
/
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
.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 %r12, 8(%rsi)
movq %r13, 16(%rsi)
movq %r14, 24(%rsi)
movq %r15, 32(%rsi)
my_set:
movq %rdi, cur_ctx /*argument will be in rdi */
/* reload the registers */
movq 0(%rdi), %rsp
movq 8(%rdi), %r12
movq 16(%rdi), %r13
movq 24(%rdi), %r14
movq 32(%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)
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
ret
#endif