]> git.lizzy.rs Git - rust.git/blob - src/rt/arch/x86_64/morestack.S
rt: Set hidden visibility on __morestack
[rust.git] / src / rt / arch / x86_64 / morestack.S
1     .text
2
3 // __morestack
4 //
5 // LLVM generates a call to this to allocate more stack space in a functiono
6 // prolog when we run out.
7
8 #if defined(__APPLE__) || defined(_WIN32)
9 #define RUST_NEW_STACK2     _rust_new_stack2
10 #define RUST_DEL_STACK      _rust_del_stack
11 #define UPCALL_CALL_C       _upcall_call_shim_on_c_stack
12 #define MORESTACK           ___morestack
13 #else
14 #define RUST_NEW_STACK2     rust_new_stack2
15 #define RUST_DEL_STACK      rust_del_stack
16 #define UPCALL_CALL_C       upcall_call_shim_on_c_stack
17 #define MORESTACK           __morestack
18 #endif
19
20         // Naturally, nobody can agree as to
21         // which arguments should go in which
22         // registers:
23 #if defined(_WIN32)
24 #  define ARG0 %rcx
25 #  define ARG1 %rdx
26 #  define ARG2 %r8
27 #else
28 #  define ARG0 %rdi
29 #  define ARG1 %rsi
30 #  define ARG2 %rdx
31 #endif
32
33 .globl RUST_NEW_STACK2
34 .globl RUST_DEL_STACK
35 .globl UPCALL_CALL_C
36 .globl MORESTACK
37
38 // FIXME: What about _WIN32?    
39 #if defined(__linux__)
40         .hidden MORESTACK
41 #else
42 #if defined(__APPLE__)
43         .private_extern MORESTACK
44 #endif
45 #endif
46
47 #ifdef __ELF__
48         .type MORESTACK,@function
49 #endif
50
51 MORESTACK:
52         .cfi_startproc
53
54         # Set up a normal backtrace
55         pushq %rbp
56         .cfi_def_cfa_offset 16
57         .cfi_offset %rbp, -16
58         movq %rsp, %rbp
59         .cfi_def_cfa_register %rbp
60
61         // Save argument registers
62         pushq   %rdi
63         pushq   %rsi
64         pushq   %rdx
65         pushq   %rcx
66         pushq   %r8
67         pushq   %r9
68
69         // Calculate the address of the stack arguments
70         movq %rbp, %rcx
71         addq $16, %rcx   // Add the saved %rbp, and return address
72         addq %r11, %rcx // Add the size of stack arguments
73
74         pushq %r10 // The amount of stack needed
75         pushq %rcx // Address of stack arguments
76         pushq %r11 // Size of stack arguments
77         pushq %rbp // Save the Rust stack pointer
78
79         // FIXME: Don't understand why I have to use the PLT here
80         lea RUST_NEW_STACK2@PLT(%rip), %rsi
81         lea 24(%rsp), %rdi
82         call UPCALL_CALL_C@PLT
83         
84         mov (%rsp),%rdx        // Grab the return pointer.
85         inc %rdx               // Skip past the `ret`.
86         mov %rax,%rsp          // Switch to the new stack.
87         call *%rdx             // Enter the new function.
88
89         .cfi_endproc