Skip to content

Commit b5b2ac0

Browse files
committed
rt: Make 32-bit morestack compatible with fastcc
1 parent 7d51961 commit b5b2ac0

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/rt/arch/i386/morestack.S

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,19 @@ MORESTACK:
6262
#endif
6363

6464
// NB: This can be called with the fastcc convention so we
65-
// have to preserve any argument registers we want to use
65+
// have to preserve any argument registers
6666

6767
// NB: __morestack is called misaligned by 4 bytes, i.e.
6868
// subl $4, %esp would get us to a normal alignment
6969

70+
subl $44,%esp
71+
72+
// Save fastcc arguments
73+
movl %ecx, 28(%esp)
74+
movl %edx, 24(%esp)
75+
7076
// FIXME (1226): main is compiled with the split-stack prologue,
7177
// causing it to call __morestack, so we have to jump back out
72-
subl $28,%esp
7378
calll RUST_GET_TASK
7479
testl %eax,%eax
7580
jz .L$bail
@@ -88,13 +93,13 @@ MORESTACK:
8893
// for the unwinder
8994
leal 20(%ebp), %eax
9095
movl %eax, -4(%ebp)
91-
96+
9297
// The arguments to rust_new_stack2
93-
movl 40(%esp),%eax // Size of stack arguments
98+
movl 56(%esp),%eax // Size of stack arguments
9499
movl %eax,20(%esp)
95-
leal 48(%esp),%eax // Address of stack arguments
100+
leal 64(%esp),%eax // Address of stack arguments
96101
movl %eax,16(%esp)
97-
movl 36(%esp),%eax // The amount of stack needed
102+
movl 52(%esp),%eax // The amount of stack needed
98103
movl %eax,12(%esp)
99104
movl $0, 8(%esp) // Out pointer
100105

@@ -111,11 +116,15 @@ MORESTACK:
111116
movl %eax,(%esp)
112117
call UPCALL_CALL_C
113118

114-
movl 32(%esp),%eax // Grab the return pointer.
119+
movl 48(%esp),%eax // Grab the return pointer.
115120
inc %eax // Skip past the ret instruction in the parent fn
116121

122+
// Restore fastcc arguments
123+
movl 28(%esp), %ecx
124+
movl 24(%esp), %edx
125+
117126
movl 8(%esp),%esp // Switch stacks.
118-
call *%eax // Re-enter the function that called us.
127+
call *%eax // Re-enter the function that called us.
119128

120129
// Now the function that called us has returned, so we need to delete the
121130
// old stack space.
@@ -155,7 +164,7 @@ MORESTACK:
155164
movl 32(%esp),%eax
156165
inc %eax
157166

158-
addl $28, %esp
167+
addl $44, %esp
159168
popl %ebp
160169
addl $4+8,%esp
161170

0 commit comments

Comments
 (0)