about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-12-19 15:58:03 -0800
committerBrian Anderson <banderson@mozilla.com>2011-12-19 16:24:10 -0800
commit50dc80f6177d09612a2ef78129f73ca2ef134b6e (patch)
tree99703e4026b258e678c7382187375eda3148f604 /src/rt
parentbedcaad97eaeb5ae09c2782a76d92749ac5585c4 (diff)
rt: Give upcall_new_stack the same convention as other upcalls
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/arch/i386/morestack.S44
-rw-r--r--src/rt/arch/x86_64/morestack.S24
-rw-r--r--src/rt/rust_upcall.cpp23
3 files changed, 33 insertions, 58 deletions
diff --git a/src/rt/arch/i386/morestack.S b/src/rt/arch/i386/morestack.S
index 5804a683028..4de97134218 100644
--- a/src/rt/arch/i386/morestack.S
+++ b/src/rt/arch/i386/morestack.S
@@ -68,30 +68,27 @@
 
 #if defined(__APPLE__)
 #define RUST_GET_TASK           L_rust_get_task$stub
+#define UPCALL_NEW_STACK        L_upcall_new_stack$stub
 #define UPCALL_DEL_STACK        L_upcall_del_stack$stub
-#define UPCALL_CALL_C           L_upcall_call_shim_on_c_stack$stub
 #define MORESTACK               ___morestack
 #else
 #if defined(__linux__)
 #define UPCALL_NEW_STACK        upcall_new_stack
 #define UPCALL_DEL_STACK        upcall_del_stack
 #define RUST_GET_TASK           rust_get_task
-#define UPCALL_CALL_C           upcall_call_shim_on_c_stack
 #define MORESTACK               __morestack
 #else
 #define UPCALL_NEW_STACK        _upcall_new_stack
 #define UPCALL_DEL_STACK        _upcall_del_stack
 #define RUST_GET_TASK           _rust_get_task
-#define UPCALL_CALL_C           _upcall_call_shim_on_c_stack
 #define MORESTACK               ___morestack
 #endif
 #endif
 
-.globl UPCALL_NEW_STACK
 #ifndef __APPLE__
+.globl UPCALL_NEW_STACK
 .globl UPCALL_DEL_STACK
 .globl RUST_GET_TASK
-.globl UPCALL_CALL_C_STACK
 #endif
 .globl MORESTACK
 
@@ -170,29 +167,19 @@ MORESTACK:
 	// The size of the stack arguments to copy to the new stack,
 	// ane of the the arguments to __morestack
 	movl 56(%esp),%eax
-	movl %eax,20(%esp)
+	movl %eax,8(%esp)
 	// The address of the stack arguments to the original function
 	leal 64(%esp),%eax
-	movl %eax,16(%esp)
+	movl %eax,4(%esp)
 	// The amount of stack needed for the original function,
 	// the other argument to __morestack
 	movl 52(%esp),%eax // The amount of stack needed
-	movl %eax,12(%esp)
-	// Out pointer to the new stack
-	movl $0, 8(%esp)
+	movl %eax,(%esp)
 
-#ifdef __APPLE__
-	call 1f
-1:	popl %eax
-	movl L_upcall_new_stack$non_lazy_ptr-1b(%eax),%eax
-	movl %eax, 4(%esp)
-#else
-	movl $UPCALL_NEW_STACK,4(%esp)
-#endif
+	call UPCALL_NEW_STACK
 
-	leal 8(%esp), %eax
-	movl %eax,(%esp)
-	call UPCALL_CALL_C
+	// Save the address of the new stack
+	movl %eax, (%esp)
 
 	// Grab the __morestack return pointer
 	movl 48(%esp),%eax
@@ -204,7 +191,7 @@ MORESTACK:
 	movl 24(%esp), %edx
 
         // Switch stacks
-	movl 8(%esp),%esp
+	movl (%esp),%esp
         // Re-enter the function that called us
 	call *%eax
 
@@ -253,11 +240,6 @@ MORESTACK:
 
 #ifdef __APPLE__
 
-	.section __IMPORT,__pointers,non_lazy_symbol_pointers
-L_upcall_new_stack$non_lazy_ptr:
-	.indirect_symbol _upcall_new_stack
-	.long 0
-
 .section __IMPORT,__jump_table,symbol_stubs,pure_instructions+self_modifying_code,5
 
 	// Linker will replace the hlts (the ascii) with jmp
@@ -265,14 +247,14 @@ L_rust_get_task$stub:
 	.indirect_symbol _rust_get_task
 	.ascii	 "\364\364\364\364\364"
 
+L_upcall_new_stack$stub:
+	.indirect_symbol _upcall_new_stack
+	.ascii	 "\364\364\364\364\364"
+	
 L_upcall_del_stack$stub:
 	.indirect_symbol _upcall_del_stack
 	.ascii	 "\364\364\364\364\364"
 
-L_upcall_call_shim_on_c_stack$stub:
-	.indirect_symbol _upcall_call_shim_on_c_stack
-	.ascii	 "\364\364\364\364\364"
-
 	.subsections_via_symbols
 #endif
 
diff --git a/src/rt/arch/x86_64/morestack.S b/src/rt/arch/x86_64/morestack.S
index f72e7107b5f..50f13619406 100644
--- a/src/rt/arch/x86_64/morestack.S
+++ b/src/rt/arch/x86_64/morestack.S
@@ -9,18 +9,15 @@
 #if defined(__APPLE__) || defined(_WIN32)
 #define UPCALL_NEW_STACK        _upcall_new_stack
 #define UPCALL_DEL_STACK        _upcall_del_stack
-#define UPCALL_CALL_C           _upcall_call_shim_on_c_stack
 #define MORESTACK               ___morestack
 #else
 #define UPCALL_NEW_STACK        upcall_new_stack
 #define UPCALL_DEL_STACK        upcall_del_stack
-#define UPCALL_CALL_C           upcall_call_shim_on_c_stack
 #define MORESTACK               __morestack
 #endif
 
 .globl UPCALL_NEW_STACK
 .globl UPCALL_DEL_STACK
-.globl UPCALL_CALL_C
 .globl MORESTACK
 
 #if defined(__linux__)
@@ -70,29 +67,22 @@ MORESTACK:
 	// Calculate the address of the stack arguments.
 	// We have the base pointer, __morestack's return address,
 	// and __morestack's caller's return address to skip
-	movq %rbp, %rcx
-	addq $24, %rcx  // Base pointer, return address x2
+	movq %rbp, %rax
+	addq $24, %rax  // Base pointer, return address x2
 
 	// The arguments to __morestack are passed in %r10 & %r11
 
-	pushq %r11 // Size of stack arguments
-	pushq %rcx // Address of stack arguments
-	pushq %r10 // The amount of stack needed
-	pushq $0   // Out pointer
+	movq %r11, %rdx // Size of stack arguments
+	movq %rax, %rsi // Address of stack arguments
+	movq %r10, %rdi // The amount of stack needed
 
-	movq UPCALL_NEW_STACK@GOTPCREL(%rip), %rsi
-	movq %rsp, %rdi
 #ifdef __APPLE__
-	call UPCALL_CALL_C
+	call UPCALL_NEW_STACK
 #endif
 #ifdef __linux__
-	call UPCALL_CALL_C@PLT
+	call UPCALL_NEW_STACK@PLT
 #endif
 
-	// Pop the new_stack_args struct
-	popq %rax
-	addq $24, %rsp
-
 	// Pop the saved arguments
 	popq %r9
 	popq %r8
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 981ce0ffb7e..867f9cd58b6 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -595,23 +595,26 @@ upcall_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
     UPCALL_SWITCH_STACK(&args, upcall_s_log_type);
 }
 
-struct rust_new_stack2_args {
-    void *new_stack;
+struct s_new_stack_args {
+    void *result;
     size_t stk_sz;
     void *args_addr;
     size_t args_sz;
 };
 
-// A new stack function suitable for calling through
-// upcall_call_shim_on_c_stack
-// FIXME: Convert this to the same arrangement as
-// the other upcalls, simplify __morestack
 extern "C" CDECL void
-upcall_new_stack(struct rust_new_stack2_args *args) {
+upcall_s_new_stack(struct s_new_stack_args *args) {
     rust_task *task = rust_scheduler::get_task();
-    args->new_stack = task->new_stack(args->stk_sz,
-                                      args->args_addr,
-                                      args->args_sz);
+    args->result = task->new_stack(args->stk_sz,
+                                   args->args_addr,
+                                   args->args_sz);
+}
+
+extern "C" CDECL void *
+upcall_new_stack(size_t stk_sz, void *args_addr, size_t args_sz) {
+    s_new_stack_args args = {NULL, stk_sz, args_addr, args_sz};
+    UPCALL_SWITCH_STACK(&args, upcall_s_new_stack);
+    return args.result;
 }
 
 extern "C" CDECL void