Skip to content

Commit 7baf68b

Browse files
committed
hack around the problem that x86_64 expects first few args in regs.
call on c-stack expects all data to be delivered on the stack.
1 parent fc064f4 commit 7baf68b

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/rt/arch/x86_64/ccall.S

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
.text
1+
#include "regs.h"
2+
3+
#define ARG0 RUSTRT_ARG0_S
4+
#define ARG1 RUSTRT_ARG1_S
5+
6+
.text
27

38
// upcall_call_c_stack(void (*fn)(), void *new_esp)
49
//
@@ -21,8 +26,32 @@ upcall_call_c_stack_float:
2126
#endif
2227
push %rbp
2328
mov %rsp,%rbp // save rsp
24-
mov %rsi,%rsp // switch stack
25-
call *%rdi
29+
mov ARG1,%rsp // switch stack
30+
31+
// Hack: the arguments to the function are sitting
32+
// on the stack right now, as in i386 calling
33+
// convention. We need them in registers.
34+
// For now, we just load them into registers.
35+
//
36+
// This is a total hack because it does not consider
37+
// the actual arguments of the target function.
38+
// It fails if there are non-INTEGER class arguments,
39+
// which would get pushed on the stack, or if there are
40+
// additional arguments beyond those that will get
41+
// passed in registers.
42+
mov ARG0,%r11 // Remember target address
43+
mov 0(%rsp),RUSTRT_ARG0_S
44+
mov 8(%rsp),RUSTRT_ARG1_S
45+
mov 16(%rsp),RUSTRT_ARG2_S
46+
mov 24(%rsp),RUSTRT_ARG3_S
47+
# ifdef RUSTRT_ARG4_S
48+
mov 32(%rsp),RUSTRT_ARG4_S
49+
# endif
50+
# ifdef RUSTRT_ARG5_S
51+
mov 40(%rsp),RUSTRT_ARG5_S
52+
# endif
53+
54+
call *%r11
2655
mov %rbp,%rsp // would like to use "leave" but it's slower
2756
pop %rbp
2857
ret

src/rt/arch/x86_64/regs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@
2121
#if defined(__MINGW32__) || defined(_WINDOWS)
2222
# define RUSTRT_ARG0_S %rcx
2323
# define RUSTRT_ARG1_S %rdx
24+
# define RUSTRT_ARG2_S %r8
25+
# define RUSTRT_ARG3_S %r9
2426
#else
2527
# define RUSTRT_ARG0_S %rdi
2628
# define RUSTRT_ARG1_S %rsi
29+
# define RUSTRT_ARG2_S %rdx
30+
# define RUSTRT_ARG3_S %rcx
31+
# define RUSTRT_ARG4_S %r8
32+
# define RUSTRT_ARG5_S %r9
2733
#endif
2834

2935

0 commit comments

Comments
 (0)