source: trunk/gcc/libffi/src/x86/win32.S

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.1 KB
Line 
1/* -----------------------------------------------------------------------
2 win32.S - Copyright (c) 1996, 1998, 2001, 2002 Red Hat, Inc.
3 Copyright (c) 2001 John Beniton
4 Copyright (c) 2002 Ranjit Mathew
5
6
7 X86 Foreign Function Interface
8
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 ``Software''), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice shall be included
18 in all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 OTHER DEALINGS IN THE SOFTWARE.
27 ----------------------------------------------------------------------- */
28
29#define LIBFFI_ASM
30#include <ffi.h>
31
32.text
33
34.globl ffi_prep_args
35
36 # This assumes we are using gas.
37 .balign 16
38.globl _ffi_call_SYSV
39
40_ffi_call_SYSV:
41 pushl %ebp
42 movl %esp,%ebp
43
44 # Make room for all of the new args.
45 movl 16(%ebp),%ecx
46 subl %ecx,%esp
47
48 movl %esp,%eax
49
50 # Place all of the ffi_prep_args in position
51 pushl 12(%ebp)
52 pushl %eax
53 call *8(%ebp)
54
55 # Return stack to previous state and call the function
56 addl $8,%esp
57
58 # FIXME: Align the stack to a 128-bit boundary to avoid
59 # potential performance hits.
60
61 call *28(%ebp)
62
63 # Remove the space we pushed for the args
64 movl 16(%ebp),%ecx
65 addl %ecx,%esp
66
67 # Load %ecx with the return type code
68 movl 20(%ebp),%ecx
69
70 # If the return value pointer is NULL, assume no return value.
71 cmpl $0,24(%ebp)
72 jne retint
73
74 # Even if there is no space for the return value, we are
75 # obliged to handle floating-point values.
76 cmpl $FFI_TYPE_FLOAT,%ecx
77 jne noretval
78 fstp %st(0)
79
80 jmp epilogue
81
82retint:
83 cmpl $FFI_TYPE_INT,%ecx
84 jne retfloat
85 # Load %ecx with the pointer to storage for the return value
86 movl 24(%ebp),%ecx
87 movl %eax,0(%ecx)
88 jmp epilogue
89
90retfloat:
91 cmpl $FFI_TYPE_FLOAT,%ecx
92 jne retdouble
93 # Load %ecx with the pointer to storage for the return value
94 movl 24(%ebp),%ecx
95 fstps (%ecx)
96 jmp epilogue
97
98retdouble:
99 cmpl $FFI_TYPE_DOUBLE,%ecx
100 jne retlongdouble
101 # Load %ecx with the pointer to storage for the return value
102 movl 24(%ebp),%ecx
103 fstpl (%ecx)
104 jmp epilogue
105
106retlongdouble:
107 cmpl $FFI_TYPE_LONGDOUBLE,%ecx
108 jne retint64
109 # Load %ecx with the pointer to storage for the return value
110 movl 24(%ebp),%ecx
111 fstpt (%ecx)
112 jmp epilogue
113
114retint64:
115 cmpl $FFI_TYPE_SINT64,%ecx
116 jne retstruct
117 # Load %ecx with the pointer to storage for the return value
118 movl 24(%ebp),%ecx
119 movl %eax,0(%ecx)
120 movl %edx,4(%ecx)
121
122retstruct:
123 # Nothing to do!
124
125noretval:
126epilogue:
127 movl %ebp,%esp
128 popl %ebp
129 ret
130
131.ffi_call_SYSV_end:
132
133 # This assumes we are using gas.
134 .balign 16
135.globl _ffi_call_STDCALL
136
137_ffi_call_STDCALL:
138 pushl %ebp
139 movl %esp,%ebp
140
141 # Make room for all of the new args.
142 movl 16(%ebp),%ecx
143 subl %ecx,%esp
144
145 movl %esp,%eax
146
147 # Place all of the ffi_prep_args in position
148 pushl 12(%ebp)
149 pushl %eax
150 call *8(%ebp)
151
152 # Return stack to previous state and call the function
153 addl $8,%esp
154
155 # FIXME: Align the stack to a 128-bit boundary to avoid
156 # potential performance hits.
157
158 call *28(%ebp)
159
160 # stdcall functions pop arguments off the stack themselves
161
162 # Load %ecx with the return type code
163 movl 20(%ebp),%ecx
164
165 # If the return value pointer is NULL, assume no return value.
166 cmpl $0,24(%ebp)
167 jne sc_retint
168
169 # Even if there is no space for the return value, we are
170 # obliged to handle floating-point values.
171 cmpl $FFI_TYPE_FLOAT,%ecx
172 jne sc_noretval
173 fstp %st(0)
174
175 jmp sc_epilogue
176
177sc_retint:
178 cmpl $FFI_TYPE_INT,%ecx
179 jne sc_retfloat
180 # Load %ecx with the pointer to storage for the return value
181 movl 24(%ebp),%ecx
182 movl %eax,0(%ecx)
183 jmp sc_epilogue
184
185sc_retfloat:
186 cmpl $FFI_TYPE_FLOAT,%ecx
187 jne sc_retdouble
188 # Load %ecx with the pointer to storage for the return value
189 movl 24(%ebp),%ecx
190 fstps (%ecx)
191 jmp sc_epilogue
192
193sc_retdouble:
194 cmpl $FFI_TYPE_DOUBLE,%ecx
195 jne sc_retlongdouble
196 # Load %ecx with the pointer to storage for the return value
197 movl 24(%ebp),%ecx
198 fstpl (%ecx)
199 jmp sc_epilogue
200
201sc_retlongdouble:
202 cmpl $FFI_TYPE_LONGDOUBLE,%ecx
203 jne sc_retint64
204 # Load %ecx with the pointer to storage for the return value
205 movl 24(%ebp),%ecx
206 fstpt (%ecx)
207 jmp sc_epilogue
208
209sc_retint64:
210 cmpl $FFI_TYPE_SINT64,%ecx
211 jne sc_retstruct
212 # Load %ecx with the pointer to storage for the return value
213 movl 24(%ebp),%ecx
214 movl %eax,0(%ecx)
215 movl %edx,4(%ecx)
216
217sc_retstruct:
218 # Nothing to do!
219
220sc_noretval:
221sc_epilogue:
222 movl %ebp,%esp
223 popl %ebp
224 ret
225
226.ffi_call_STDCALL_end:
Note: See TracBrowser for help on using the repository browser.