]> git.lizzy.rs Git - rust.git/blob - src/rt/arch/x86_64/morestack.S
rt: Remove a FIXME frome x86_64/morestack.S
[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 #if defined(__linux)
52 MORESTACK:
53         .cfi_startproc
54
55         # Set up a normal backtrace
56         pushq %rbp
57         .cfi_def_cfa_offset 16
58         .cfi_offset %rbp, -16
59         movq %rsp, %rbp
60         .cfi_def_cfa_register %rbp
61
62         // Save argument registers
63         pushq   %rdi
64         pushq   %rsi
65         pushq   %rdx
66         pushq   %rcx
67         pushq   %r8
68         pushq   %r9
69
70         // Calculate the address of the stack arguments
71         movq %rbp, %rcx
72         addq $16, %rcx   // Add the saved %rbp, and return address
73         addq %r11, %rcx // Add the size of stack arguments
74
75         pushq %rbp // Save the Rust stack pointer
76         pushq %r11 // Size of stack arguments
77         pushq %rcx // Address of stack arguments
78         pushq %r10 // The amount of stack needed
79
80         lea RUST_NEW_STACK2@PLT(%rip), %rsi
81         mov %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
90 #else
91 MORESTACK:
92         ret
93 #endif