Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / i386 / dl-trampoline.S
blob8cbab482068b0ef994c9dfa2c25005b0b2191eaf
1 /* PLT trampolines.  i386 version.
2    Copyright (C) 2004-2014 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, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
21         .text
22         .globl _dl_runtime_resolve
23         .type _dl_runtime_resolve, @function
24         cfi_startproc
25         .align 16
26 _dl_runtime_resolve:
27         cfi_adjust_cfa_offset (8)
28         pushl %eax              # Preserve registers otherwise clobbered.
29         cfi_adjust_cfa_offset (4)
30         pushl %ecx
31         cfi_adjust_cfa_offset (4)
32         pushl %edx
33         cfi_adjust_cfa_offset (4)
34         movl 16(%esp), %edx     # Copy args pushed by PLT in register.  Note
35         movl 12(%esp), %eax     # that `fixup' takes its parameters in regs.
36         call _dl_fixup          # Call resolver.
37         popl %edx               # Get register content back.
38         cfi_adjust_cfa_offset (-4)
39         movl (%esp), %ecx
40         movl %eax, (%esp)       # Store the function address.
41         movl 4(%esp), %eax
42         ret $12                 # Jump to function address.
43         cfi_endproc
44         .size _dl_runtime_resolve, .-_dl_runtime_resolve
47 #ifndef PROF
48         .globl _dl_runtime_profile
49         .type _dl_runtime_profile, @function
50         cfi_startproc
51         .align 16
52 _dl_runtime_profile:
53         cfi_adjust_cfa_offset (8)
54         pushl %esp
55         cfi_adjust_cfa_offset (4)
56         addl $8, (%esp)         # Account for the pushed PLT data
57         pushl %ebp
58         cfi_adjust_cfa_offset (4)
59         pushl %eax              # Preserve registers otherwise clobbered.
60         cfi_adjust_cfa_offset (4)
61         pushl %ecx
62         cfi_adjust_cfa_offset (4)
63         pushl %edx
64         cfi_adjust_cfa_offset (4)
65         movl %esp, %ecx
66         subl $8, %esp
67         cfi_adjust_cfa_offset (8)
68         movl $-1, 4(%esp)
69         leal 4(%esp), %edx
70         movl %edx, (%esp)
71         pushl %ecx              # Address of the register structure
72         cfi_adjust_cfa_offset (4)
73         movl 40(%esp), %ecx     # Load return address
74         movl 36(%esp), %edx     # Copy args pushed by PLT in register.  Note
75         movl 32(%esp), %eax     # that `fixup' takes its parameters in regs.
76         call _dl_profile_fixup  # Call resolver.
77         cfi_adjust_cfa_offset (-8)
78         movl (%esp), %edx
79         testl %edx, %edx
80         jns 1f
81         popl %edx
82         cfi_adjust_cfa_offset (-4)
83         popl %edx               # Get register content back.
84         cfi_adjust_cfa_offset (-4)
85         movl (%esp), %ecx
86         movl %eax, (%esp)       # Store the function address.
87         movl 4(%esp), %eax
88         ret $20                 # Jump to function address.
90         /*
91             +32     return address
92             +28     PLT1
93             +24     PLT2
94             +20     %esp
95             +16     %ebp
96             +12     %eax
97             +8      %ecx
98             +4      %edx
99            %esp     free
100         */
101         cfi_adjust_cfa_offset (8)
102 1:      movl %ebx, (%esp)
103         cfi_rel_offset (ebx, 0)
104         movl %edx, %ebx         # This is the frame buffer size
105         pushl %edi
106         cfi_adjust_cfa_offset (4)
107         cfi_rel_offset (edi, 0)
108         pushl %esi
109         cfi_adjust_cfa_offset (4)
110         cfi_rel_offset (esi, 0)
111         leal 44(%esp), %esi
112         movl %ebx, %ecx
113         orl $4, %ebx            # Increase frame size if necessary to align
114                                 # stack for the function call
115         andl $~3, %ebx
116         movl %esp, %edi
117         subl %ebx, %edi
118         movl %esp, %ebx
119         cfi_def_cfa_register (ebx)
120         movl %edi, %esp
121         shrl $2, %ecx
122         rep
123         movsl
124         movl (%ebx), %esi
125         cfi_restore (esi)
126         movl 4(%ebx), %edi
127         cfi_restore (edi)
128         /*
129            %ebx+40  return address
130            %ebx+36  PLT1
131            %ebx+32  PLT2
132            %ebx+28  %esp
133            %ebx+24  %ebp
134            %ebx+20  %eax
135            %ebx+16  %ecx
136            %ebx+12  %edx
137            %ebx+8   %ebx
138            %ebx+4   free
139            %ebx     free
140            %esp     copied stack frame
141         */
142         movl %eax, (%ebx)
143         movl 12(%ebx), %edx
144         movl 16(%ebx), %ecx
145         movl 20(%ebx), %eax
146         call *(%ebx)
147         movl %ebx, %esp
148         cfi_def_cfa_register (esp)
149         movl 8(%esp), %ebx
150         cfi_restore (ebx)
151         /*
152             +40     return address
153             +36     PLT1
154             +32     PLT2
155             +28     %esp
156             +24     %ebp
157             +20     %eax
158             +16     %ecx
159             +12     %edx
160             +8      free
161             +4      free
162            %esp     free
163         */
164         subl $20, %esp
165         cfi_adjust_cfa_offset (20)
166         movl %eax, (%esp)
167         movl %edx, 4(%esp)
168         fstpt 8(%esp)
169         fstpt 20(%esp)
170         pushl %esp
171         cfi_adjust_cfa_offset (4)
172         leal 36(%esp), %ecx
173         movl 56(%esp), %eax
174         movl 60(%esp), %edx
175         call _dl_call_pltexit
176         movl (%esp), %eax
177         movl 4(%esp), %edx
178         fldt 20(%esp)
179         fldt 8(%esp)
180         addl $60, %esp
181         cfi_adjust_cfa_offset (-60)
182         ret
183         cfi_endproc
184         .size _dl_runtime_profile, .-_dl_runtime_profile
185 #endif