4 See i386/morestack.S for the lengthy, general explanation.
9 #if defined(__APPLE__) || defined(_WIN32)
10 #define UPCALL_NEW_STACK _upcall_new_stack
11 #define UPCALL_DEL_STACK _upcall_del_stack
12 #define UPCALL_CALL_C _upcall_call_shim_on_c_stack
13 #define MORESTACK ___morestack
15 #define UPCALL_NEW_STACK upcall_new_stack
16 #define UPCALL_DEL_STACK upcall_del_stack
17 #define UPCALL_CALL_C upcall_call_shim_on_c_stack
18 #define MORESTACK __morestack
21 .globl UPCALL_NEW_STACK
22 .globl UPCALL_DEL_STACK
26 #if defined(__linux__)
29 #if defined(__APPLE__)
30 .private_extern MORESTACK
35 .type MORESTACK,@function
39 #if defined(__linux__) || defined(__APPLE__)
44 // The CFA is 24 bytes above the register that it will
45 // be associated with for this frame (%rbp). That is 8
46 // bytes greater than a normal frame, to allow the unwinder
47 // to skip the partial frame of the original function.
48 .cfi_def_cfa_offset 24
49 // %rbp is -24 bytes from the CFA
52 // Calculate the CFA as on offset from %ebp
53 .cfi_def_cfa_register %rbp
55 // Save the grandparent stack pointer for the unwinder
56 // FIXME: This isn't used
60 // FIXME: libgcc also saves rax. not sure if we need to
62 // Save argument registers of the original function
70 // Calculate the address of the stack arguments.
71 // We have the base pointer, __morestack's return address,
72 // and __morestack's caller's return address to skip
74 addq $24, %rcx // Base pointer, return address x2
76 // The arguments to __morestack are passed in %r10 & %r11
78 pushq %r11 // Size of stack arguments
79 pushq %rcx // Address of stack arguments
80 pushq %r10 // The amount of stack needed
81 pushq $0 // Out pointer
83 movq UPCALL_NEW_STACK@GOTPCREL(%rip), %rsi
89 call UPCALL_CALL_C@PLT
92 // Pop the new_stack_args struct
96 // Pop the saved arguments
104 // Pop the unwinding %rsp
107 movq 8(%rbp),%r10 // Grab the return pointer.
108 incq %r10 // Skip past the `ret` in our parent frame
109 movq %rax,%rsp // Switch to the new stack.
111 call *%r10 // Reenter the caller function
113 // Switch back to the rust stack
116 // Align the stack again
119 // FIXME: Should preserve %rax here
120 movq UPCALL_DEL_STACK@GOTPCREL(%rip), %rsi
126 call UPCALL_CALL_C@PLT
131 // FIXME: I don't think these rules are necessary
132 // since the unwinder should never encounter an instruction
133 // pointer pointing here.
135 .cfi_def_cfa %rsp, 16