File tree Expand file tree Collapse file tree 3 files changed +21
-58
lines changed Expand file tree Collapse file tree 3 files changed +21
-58
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 98dee91f2568522bc129f8cffcaa2879b43646c3
2
+ refs/heads/master: 860e8fd98b07cc0dfbb3ff33124778c2225ba81d
Original file line number Diff line number Diff line change @@ -13,15 +13,17 @@ Saves a set of registers. This is used by our implementation of
13
13
getcontext.
14
14
15
15
The registers_t variable is in (%esp)
16
- */
17
-
18
- .globl get_registers
19
- get_registers:
20
- movl 4 (%esp ), %eax
21
- movl %eax , 0 (%eax )
16
+ */
17
+
18
+ // swap_registers(registers_t *oregs, registers_t *regs)
19
+ .globl swap_registers
20
+ swap_registers:
21
+ // save the old context
22
+ movl 4 (%esp ), %eax
23
+ //movl %eax, 0(%eax)
22
24
movl %ebx , 4 (%eax )
23
- movl %ecx , 8 (%eax )
24
- movl %edx , 12 (%eax )
25
+ // movl %ecx, 8(%eax)
26
+ // movl %edx, 12(%eax)
25
27
movl %ebp , 16 (%eax )
26
28
movl %esi , 20 (%eax )
27
29
movl %edi , 24 (%eax )
@@ -43,17 +45,12 @@ get_registers:
43
45
movl %esp , 28 (%eax )
44
46
movl %ecx , 48 (%eax )
45
47
46
- // return 0
47
- xor %eax , %eax
48
- jmp *%ecx
49
-
50
- .globl set_registers
51
- set_registers:
52
- movl 4 (%esp ), %eax
48
+ // restore the new context
49
+ movl 4 (%esp ), %eax
53
50
54
51
movl 4 (%eax ), %ebx
55
52
// save ecx for later...
56
- movl 12 (%eax ), %edx
53
+ // movl 12(%eax), %edx
57
54
movl 16 (%eax ), %ebp
58
55
movl 20 (%eax ), %esi
59
56
movl 24 (%eax ), %edi
@@ -71,36 +68,5 @@ set_registers:
71
68
push %ecx
72
69
popf
73
70
74
- // get ready to return.
75
- mov 48 (%eax ), %ecx
76
- push %ecx
77
-
78
- // okay, now we can restore ecx.
79
- movl 8 (%eax ), %ecx
80
-
81
- // return 1 to the saved eip
82
- movl $1 , %eax
83
- ret
84
-
85
- // swap_registers(registers_t *oregs, registers_t *regs)
86
- .globl swap_registers
87
- swap_registers:
88
- // %eax = get_registers(oregs);
89
- movl 4 (%esp ), %eax
90
- push %eax
91
- call get_registers
92
-
93
- // if(!%eax) goto call_set
94
- test %eax , %eax
95
- jz call_set
96
-
97
- // else
98
- addl $4 , %esp
99
- ret
100
-
101
- call_set:
102
- // set_registers(regs)
103
- movl 12 (%esp ), %eax
104
- movl %eax , 0 (%esp )
105
- call set_registers
106
- // set_registers never returns
71
+ // Return!
72
+ jmp *48 (%eax )
Original file line number Diff line number Diff line change 5
5
#include < stdio.h>
6
6
#include < stdlib.h>
7
7
8
- // extern "C" uint32_t CDECL get_registers(registers_t *regs)
9
- // asm ("get_registers");
10
8
extern " C" uint32_t CDECL swap_registers (registers_t *oregs,
11
9
registers_t *regs)
12
10
asm (" swap_registers" );
13
11
14
12
context::context ()
15
- : next(NULL )
16
13
{
17
- // get_registers(®s);
18
- swap_registers (®s, ®s);
19
14
}
20
15
21
16
void context::swap (context &out)
@@ -24,13 +19,15 @@ void context::swap(context &out)
24
19
}
25
20
26
21
void context::call (void *f, void *arg, void *stack) {
22
+ // Get the current context, which we will then modify to call the
23
+ // given function.
24
+ swap (*this );
25
+
27
26
// set up the trampoline frame
28
27
uint32_t *sp = (uint32_t *)stack;
29
28
30
29
// Shift the stack pointer so the alignment works out right.
31
- sp = align_down (sp) - 2 ;
32
-
33
- *--sp = (uint32_t )this ;
30
+ sp = align_down (sp) - 3 ;
34
31
*--sp = (uint32_t )arg;
35
32
*--sp = 0xdeadbeef ;
36
33
You can’t perform that action at this time.
0 commit comments