Stub out a large set of syscall instructions
[glibc/nacl-glibc.git] / sysdeps / i386 / dl-trampoline.S
blob2fe27f13b84a04179dd1644ba4be83660449405a
1 /* PLT trampolines.  i386 version.
2    Copyright (C) 2004, 2005, 2007 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         cfi_startproc
26         .align 16
27 _dl_runtime_resolve:
28         # This no longer preserves registers %eax, %ecx and %edx, but we
29         # cannot preserve all registers because at least one is needed
30         # to perform address alignment when jumping in NaCl.
31         # This means functions called via the PLT can't use the "regparm"
32         # attribute.  See "regparm" in the gcc docs.
33         cfi_adjust_cfa_offset (8)
34         popl %eax
35         cfi_adjust_cfa_offset (-4)
36         popl %edx
37         cfi_adjust_cfa_offset (-4)
38         call _dl_fixup
39         nacljmp %eax
40         cfi_endproc
41         .size _dl_runtime_resolve, .-_dl_runtime_resolve
44 #ifndef PROF
45         .globl _dl_runtime_profile
46         .type _dl_runtime_profile, @function
47         cfi_startproc
48         .align 16
49 _dl_runtime_profile:
50         cfi_adjust_cfa_offset (8)
51         pushl %esp
52         cfi_adjust_cfa_offset (4)
53         addl $8, (%esp)         # Account for the pushed PLT data
54         pushl %ebp
55         cfi_adjust_cfa_offset (4)
56         pushl %eax              # Preserve registers otherwise clobbered.
57         cfi_adjust_cfa_offset (4)
58         pushl %ecx
59         cfi_adjust_cfa_offset (4)
60         pushl %edx
61         cfi_adjust_cfa_offset (4)
62         movl %esp, %ecx
63         subl $8, %esp
64         cfi_adjust_cfa_offset (8)
65         movl $-1, 4(%esp)
66         leal 4(%esp), %edx
67         movl %edx, (%esp)
68         pushl %ecx              # Address of the register structure
69         cfi_adjust_cfa_offset (4)
70         movl 40(%esp), %ecx     # Load return address
71         movl 36(%esp), %edx     # Copy args pushed by PLT in register.  Note
72         movl 32(%esp), %eax     # that `fixup' takes its parameters in regs.
73         call _dl_profile_fixup  # Call resolver.
74         cfi_adjust_cfa_offset (-8)
75         movl (%esp), %edx
76         testl %edx, %edx
77         jns 1f
78         popl %edx
79         cfi_adjust_cfa_offset (-4)
80         popl %edx               # Get register content back.
81         cfi_adjust_cfa_offset (-4)
82         movl (%esp), %ecx
83         movl %eax, (%esp)       # Store the function address.
84         movl 4(%esp), %eax
85 # Fix this when we are in a position to test it.
86         hlt
87 #       ret $20                 # Jump to function address.
89         /*
90             +32     return address
91             +28     PLT1
92             +24     PLT2
93             +20     %esp
94             +16     %ebp
95             +12     %eax
96             +8      %ecx
97             +4      %edx
98            %esp     free
99         */
100         cfi_adjust_cfa_offset (12)
101 1:      movl %ebx, (%esp)
102         cfi_rel_offset (ebx, 0)
103         movl %edx, %ebx         # This is the frame buffer size
104         pushl %edi
105         cfi_adjust_cfa_offset (4)
106         cfi_rel_offset (edi, 0)
107         pushl %esi
108         cfi_adjust_cfa_offset (4)
109         cfi_rel_offset (esi, 0)
110         leal 44(%esp), %esi
111         movl %ebx, %ecx
112         orl $4, %ebx            # Increase frame size if necessary to align
113                                 # stack for the function call
114         andl $~3, %ebx
115         movl %esp, %edi
116         subl %ebx, %edi
117         movl %esp, %ebx
118         cfi_def_cfa_register (ebx)
119         movl %edi, %esp
120         shrl $2, %ecx
121         rep
122         movsl
123         movl (%ebx), %esi
124         cfi_restore (esi)
125         movl 4(%ebx), %edi
126         cfi_restore (edi)
127         /*
128            %ebx+40  return address
129            %ebx+36  PLT1
130            %ebx+32  PLT2
131            %ebx+28  %esp
132            %ebx+24  %ebp
133            %ebx+20  %eax
134            %ebx+16  %ecx
135            %ebx+12  %edx
136            %ebx+8   %ebx
137            %ebx+4   free
138            %ebx     free
139            %esp     copied stack frame
140         */
141         movl %eax, (%ebx)
142         movl 12(%ebx), %edx
143         movl 16(%ebx), %ecx
144         movl 20(%ebx), %eax
145         call *(%ebx)
146         movl %ebx, %esp
147         cfi_def_cfa_register (esp)
148         movl 8(%esp), %ebx
149         cfi_restore (ebx)
150         /*
151             +40     return address
152             +36     PLT1
153             +32     PLT2
154             +28     %esp
155             +24     %ebp
156             +20     %eax
157             +16     %ecx
158             +12     %edx
159             +8      free
160             +4      free
161            %esp     free
162         */
163         subl $20, %esp
164         cfi_adjust_cfa_offset (20)
165         movl %eax, (%esp)
166         movl %edx, 4(%esp)
167         fstpt 8(%esp)
168         fstpt 20(%esp)
169         pushl %esp
170         cfi_adjust_cfa_offset (4)
171         leal 36(%esp), %ecx
172         movl 56(%esp), %eax
173         movl 60(%esp), %edx
174         call _dl_call_pltexit
175         movl (%esp), %eax
176         movl 4(%esp), %edx
177         fldt 20(%esp)
178         fldt 8(%esp)
179         addl $60, %esp
180         cfi_adjust_cfa_offset (-60)
181         popl %ecx; nacljmp %ecx
182         cfi_endproc
183         .size _dl_runtime_profile, .-_dl_runtime_profile
184 #endif