2.5-18.1
[glibc.git] / sysdeps / x86_64 / dl-trampoline.S
blobc1686dae1061c200d2a24ef883e8c774d2580fb5
1 /* PLT trampolines.  x86-64 version.
2    Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
22         .text
23         .globl _dl_runtime_resolve
24         .type _dl_runtime_resolve, @function
25         .align 16
26         cfi_startproc
27 _dl_runtime_resolve:
28         subq $56,%rsp
29         cfi_adjust_cfa_offset(72) # Incorporate PLT
30         movq %rax,(%rsp)        # Preserve registers otherwise clobbered.
31         movq %rcx, 8(%rsp)
32         movq %rdx, 16(%rsp)
33         movq %rsi, 24(%rsp)
34         movq %rdi, 32(%rsp)
35         movq %r8, 40(%rsp)
36         movq %r9, 48(%rsp)
37         movq 64(%rsp), %rsi     # Copy args pushed by PLT in register.
38         movq %rsi, %r11         # Multiply by 24
39         addq %r11, %rsi
40         addq %r11, %rsi
41         shlq $3, %rsi
42         movq 56(%rsp), %rdi     # %rdi: link_map, %rsi: reloc_offset
43         call _dl_fixup          # Call resolver.
44         movq %rax, %r11         # Save return value
45         movq 48(%rsp), %r9      # Get register content back.
46         movq 40(%rsp), %r8
47         movq 32(%rsp), %rdi
48         movq 24(%rsp), %rsi
49         movq 16(%rsp), %rdx
50         movq 8(%rsp), %rcx
51         movq (%rsp), %rax
52         addq $72, %rsp          # Adjust stack(PLT did 2 pushes)
53         cfi_adjust_cfa_offset(-72)
54         jmp *%r11               # Jump to function address.
55         cfi_endproc
56         .size _dl_runtime_resolve, .-_dl_runtime_resolve
59 #ifndef PROF
60         .globl _dl_runtime_profile
61         .type _dl_runtime_profile, @function
62         .align 16
63         cfi_startproc
64 _dl_runtime_profile:
65         subq $80, %rsp
66         cfi_adjust_cfa_offset(96) # Incorporate PLT
67         movq %rax, (%rsp)       # Preserve registers otherwise clobbered.
68         movq %rdx, 8(%rsp)
69         movq %r8, 16(%rsp)
70         movq %r9, 24(%rsp)
71         movq %rcx, 32(%rsp)
72         movq %rsi, 40(%rsp)
73         movq %rdi, 48(%rsp)
74         movq %rbp, 56(%rsp)     # Information for auditors.
75         leaq 96(%rsp), %rax
76         movq %rax, 64(%rsp)
77         leaq 8(%rsp), %rcx
78         movq 96(%rsp), %rdx     # Load return address if needed
79         movq 88(%rsp), %rsi     # Copy args pushed by PLT in register.
80         movq %rsi,%r11          # Multiply by 24
81         addq %r11,%rsi
82         addq %r11,%rsi
83         shlq $3, %rsi
84         movq 80(%rsp), %rdi     # %rdi: link_map, %rsi: reloc_offset
85         leaq 72(%rsp), %r8
86         call _dl_profile_fixup  # Call resolver.
87         movq %rax, %r11         # Save return value
88         movq 8(%rsp), %rdx      # Get back register content.
89         movq 16(%rsp), %r8
90         movq 24(%rsp), %r9
91         movq (%rsp),%rax
92         movq 72(%rsp), %r10
93         testq %r10, %r10
94         jns 1f
95         movq 32(%rsp), %rcx
96         movq 40(%rsp), %rsi
97         movq 48(%rsp), %rdi
98         addq $96,%rsp           # Adjust stack
99         cfi_adjust_cfa_offset (-96)
100         jmp *%r11               # Jump to function address.
102         /*
103             +96     return address
104             +88     PLT2
105             +80     PLT1
106             +72     free
107             +64     %rsp
108             +56     %rbp
109             +48     %rdi
110             +40     %rsi
111             +32     %rcx
112             +24     %r9
113             +16     %r8
114             +8      %rdx
115            %esp     %rax
116         */
117         cfi_adjust_cfa_offset (96)
118 1:      movq %rbx, 72(%rsp)
119         cfi_rel_offset (1, 72)
120         leaq 104(%rsp), %rsi
121         movq %rsp, %rbx
122         cfi_def_cfa_register (1)
123         subq %r10, %rsp
124         movq %rsp, %rdi
125         movq %r10, %rcx
126         shrq $3, %rcx
127         rep
128         movsq
129         andq $0xfffffffffffffff0, %rsp
130         movq 32(%rbx), %rcx
131         movq 40(%rbx), %rsi
132         movq 48(%rbx), %rdi
133         call *%r11
134         movq %rbx, %rsp
135         cfi_def_cfa_register (7)
136         subq $72, %rsp
137         cfi_adjust_cfa_offset (72)
138         movq %rsp, %rcx
139         movq %rax, (%rcx)
140         movq %rdx, 8(%rcx)
141         /* Even though the stack is correctly aligned to allow using movaps
142            we use movups.  Some callers might provide an incorrectly aligned
143            stack and we do not want to have it blow up here.  */
144         movups %xmm0, 16(%rcx)
145         movups %xmm1, 32(%rcx)
146         fstpt 48(%rcx)
147         fstpt 64(%rcx)
148         /*
149             +168    return address
150             +160    PLT2
151             +152    PLT1
152             +144    free
153             +136    %rsp
154             +128    %rbp
155             +120    %rdi
156             +112    %rsi
157             +104    %rcx
158             +96     %r9
159             +88     %r8
160             +80     %rdx
161             +64     %st1 result
162             +48     %st result
163             +32     %xmm1 result
164             +16     %xmm0 result
165             +8      %rdx result
166            %esp     %rax result
167         */
168         leaq 80(%rsp), %rdx
169         movq 144(%rsp), %rbx
170         cfi_restore (1)
171         movq 160(%rsp), %rsi    # Copy args pushed by PLT in register.
172         movq %rsi,%r11          # Multiply by 24
173         addq %r11,%rsi
174         addq %r11,%rsi
175         shlq $3, %rsi
176         movq 152(%rsp), %rdi    # %rdi: link_map, %rsi: reloc_offset
177         call _dl_call_pltexit
178         movq (%rsp), %rax
179         movq 8(%rsp), %rdx
180         movups 16(%rsp), %xmm0
181         movups 32(%rsp), %xmm1
182         fldt 64(%rsp)
183         fldt 48(%rsp)
184         addq $168, %rsp
185         cfi_adjust_cfa_offset (-168)
186         retq
187         cfi_endproc
188         .size _dl_runtime_profile, .-_dl_runtime_profile
189 #endif