|
2 | 2 |
|
3 | 3 | // __morestack
|
4 | 4 | //
|
5 |
| -// LLVM generates a call to this to allocate more stack space in a function |
| 5 | +// LLVM generates a call to this to allocate more stack space in a functiono |
6 | 6 | // prolog when we run out.
|
7 | 7 |
|
8 | 8 | #if defined(__APPLE__) || defined(_WIN32)
|
9 |
| -#define RUST_NEW_STACK _rust_new_stack |
10 |
| -#define RUST_DEL_STACK _rust_del_stack |
11 |
| -#define RUST_GET_PREV_STACK _rust_get_prev_stack |
12 |
| -#define RUST_GET_TASK _rust_get_task |
13 |
| -#define UPCALL_ALLOC_C_STACK _upcall_alloc_c_stack |
14 |
| -#define UPCALL_CALL_C_STACK _upcall_call_c_stack |
15 |
| -#define MORESTACK ___morestack |
| 9 | +#define RUST_NEW_STACK _rust_new_stack |
| 10 | +#define RUST_DEL_STACK _rust_del_stack |
| 11 | +#define MORESTACK ___morestack |
16 | 12 | #else
|
17 |
| -#define RUST_NEW_STACK rust_new_stack |
18 |
| -#define RUST_DEL_STACK rust_del_stack |
19 |
| -#define RUST_GET_PREV_STACK rust_get_prev_stack |
20 |
| -#define RUST_GET_TASK rust_get_task |
21 |
| -#define UPCALL_ALLOC_C_STACK upcall_alloc_c_stack |
22 |
| -#define UPCALL_CALL_C_STACK upcall_call_c_stack |
23 |
| -#define MORESTACK __morestack |
| 13 | +#define RUST_NEW_STACK rust_new_stack |
| 14 | +#define RUST_DEL_STACK rust_del_stack |
| 15 | +#define MORESTACK __morestack |
24 | 16 | #endif
|
25 | 17 |
|
26 |
| -#ifdef __APPLE__ |
27 |
| -#define ALIGNMENT 4 |
28 |
| -#else |
29 |
| -#define ALIGNMENT 8 |
30 |
| -#endif |
31 |
| - |
32 |
| -#define RETURN_OFFSET 7 |
33 |
| - |
34 | 18 | .globl RUST_NEW_STACK
|
35 | 19 | .globl RUST_DEL_STACK
|
36 |
| -.globl RUST_GET_PREV_STACK |
37 |
| -.globl RUST_GET_TASK |
38 |
| -.globl UPCALL_ALLOC_C_STACK |
39 |
| -.globl UPCALL_CALL_C_STACK |
| 20 | + |
40 | 21 | .globl MORESTACK
|
41 | 22 |
|
42 | 23 | MORESTACK:
|
43 |
| - |
44 |
| - // Sanity check to make sure that there is a currently-running task. |
45 |
| - subl $12,%esp |
46 |
| - calll RUST_GET_TASK |
47 |
| - testl %eax,%eax |
48 |
| - jz L$bail |
49 |
| - |
50 |
| - subl $12,%esp |
51 |
| - pushl $12 |
52 |
| - calll UPCALL_ALLOC_C_STACK |
53 |
| - movl %eax,%edx |
54 |
| - |
55 |
| - // C stack | esp+12 |
56 |
| - // ---------------------+------------------------- |
57 |
| - movl 20(%esp),%eax // | ra stksz argsz x ra args |
58 |
| - movl %eax,8(%edx) // argsz > | ra stksz argsz x ra args |
59 |
| - leal 32(%esp),%eax // argsz | ra stksz argsz x ra args |
60 |
| - movl %eax,4(%edx) // argp > argsz | ra stksz argsz x ra args |
61 |
| - movl 16(%esp),%eax // argp argsz | ra stksz argsz x ra args |
62 |
| - movl %eax,(%edx) // stksz > argp argsz | ra stksz argsz x ra args |
63 |
| - |
64 |
| - calll L$pic_ref_pt_0 |
65 |
| -L$pic_ref_pt_0: |
66 |
| - popl %eax |
67 |
| - |
68 |
| - movl rust_new_stack_sym-L$pic_ref_pt_0(%eax),%eax |
69 |
| - movl %eax,(%esp) |
70 |
| - movl %edx,4(%esp) |
71 |
| - calll UPCALL_CALL_C_STACK |
72 |
| - |
73 |
| - movl 16(%esp),%edx // Grab the return pointer. |
74 |
| - addl $RETURN_OFFSET,%edx // Skip past the `add esp,4` and the `ret`. |
75 |
| - |
76 |
| - movl %eax,%esp // Switch stacks. |
77 |
| - subl $12,%esp // Align the stack. |
| 24 | + pushl 8(%esp) // argsz > ra stksz argsz x x ra args |
| 25 | + leal 28(%esp),%eax // argsz ra stksz argsz x x ra args |
| 26 | + pushl %eax // argp > argsz ra stksz argsz x x ra args |
| 27 | + pushl 12(%esp) // stksz > argp argsz ra stksz argsz x x ra args |
| 28 | + calll RUST_NEW_STACK |
| 29 | + addl $12,%esp // ra stksz argsz x x ra args |
| 30 | + |
| 31 | + movl (%esp),%edx // Grab the return pointer. |
| 32 | + incl %edx // Skip past the `ret`. |
| 33 | + movl %eax,%esp // Switch to the new stack. |
78 | 34 | calll *%edx // Re-enter the function that called us.
|
79 | 35 |
|
80 | 36 | // Now the function that called us has returned, so we need to delete the
|
81 | 37 | // old stack space.
|
82 |
| - |
83 |
| - calll RUST_GET_PREV_STACK |
84 |
| - movl %eax,%esp // Switch back to the old stack. |
85 |
| - |
86 |
| - movl $0,(%esp) |
87 |
| - calll UPCALL_ALLOC_C_STACK |
88 |
| - |
89 |
| - calll L$pic_ref_pt_1 |
90 |
| -L$pic_ref_pt_1: |
91 |
| - popl %edx |
92 |
| - |
93 |
| - movl rust_del_stack_sym-L$pic_ref_pt_1(%edx),%edx |
94 |
| - movl %edx,(%esp) |
95 |
| - movl %eax,4(%esp) |
96 |
| - calll UPCALL_CALL_C_STACK |
97 |
| - |
98 |
| - addl $16,%esp |
99 |
| - retl $16 + ALIGNMENT // ra stksz argsz x ra args |
100 |
| - |
101 |
| -L$bail: |
102 |
| - movl 12(%esp),%edx |
103 |
| - addl $RETURN_OFFSET,%edx |
104 |
| - addl $12+16,%esp |
105 |
| - jmpl *%edx |
106 |
| - |
107 |
| -#ifdef __APPLE__ |
108 |
| - |
109 |
| - .section __IMPORT,__pointers,non_lazy_symbol_pointers |
110 |
| -rust_new_stack_sym: |
111 |
| - .indirect_symbol RUST_NEW_STACK |
112 |
| - .long 0 |
113 |
| -rust_del_stack_sym: |
114 |
| - .indirect_symbol RUST_DEL_STACK |
115 |
| - .long 0 |
116 |
| - |
117 |
| -#endif |
| 38 | + calll RUST_DEL_STACK |
| 39 | + movl %eax,%esp |
| 40 | + retl $8 // ra stksz argsz x x ra args |
118 | 41 |
|
0 commit comments