PageRenderTime 282ms CodeModel.GetById 120ms app.highlight 8ms RepoModel.GetById 102ms app.codeStats 0ms

/Modules/_ctypes/libffi_msvc/win32.S

http://unladen-swallow.googlecode.com/
Assembly | 243 lines | 189 code | 54 blank | 0 comment | 17 complexity | f932527ade12cc7c74b5037af590eebd MD5 | raw file
  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 <fficonfig.h>
 31#include <ffi.h>
 32 
 33.text
 34 
 35.globl ffi_prep_args
 36 
 37        # This assumes we are using gas.
 38        .balign 16
 39.globl _ffi_call_SYSV
 40 
 41_ffi_call_SYSV:
 42        pushl %ebp
 43        movl  %esp,%ebp
 44
 45	#THe: save previous %esi, and store the current stack pointer in %esi
 46	pushl %esi
 47	movl %esp,%esi
 48
 49        # Make room for all of the new args.
 50        movl  16(%ebp),%ecx                                                     
 51        subl  %ecx,%esp
 52 
 53        movl  %esp,%eax
 54 
 55        # Place all of the ffi_prep_args in position
 56        pushl 12(%ebp)
 57        pushl %eax
 58        call  *8(%ebp)
 59 
 60        # Return stack to previous state and call the function
 61        addl  $8,%esp
 62 
 63        # FIXME: Align the stack to a 128-bit boundary to avoid
 64        # potential performance hits.
 65
 66	call  *28(%ebp)
 67 
 68        # Remove the space we pushed for the args
 69        movl  16(%ebp),%ecx
 70        addl  %ecx,%esp
 71
 72	sub %esp,%esi # calculate stack pointer difference
 73
 74        # Load %ecx with the return type code
 75        movl  20(%ebp),%ecx
 76 
 77        # If the return value pointer is NULL, assume no return value.
 78        cmpl  $0,24(%ebp)
 79        jne   retint
 80 
 81        # Even if there is no space for the return value, we are
 82        # obliged to handle floating-point values.
 83        cmpl  $FFI_TYPE_FLOAT,%ecx
 84        jne   noretval
 85        fstp  %st(0)
 86 
 87        jmp   epilogue
 88 
 89retint:
 90        cmpl  $FFI_TYPE_INT,%ecx
 91        jne   retfloat
 92        # Load %ecx with the pointer to storage for the return value
 93        movl  24(%ebp),%ecx
 94        movl  %eax,0(%ecx)
 95        jmp   epilogue
 96 
 97retfloat:
 98        cmpl  $FFI_TYPE_FLOAT,%ecx
 99        jne   retdouble   
100         # Load %ecx with the pointer to storage for the return value
101        movl  24(%ebp),%ecx
102        fstps (%ecx)
103        jmp   epilogue
104 
105retdouble:
106        cmpl  $FFI_TYPE_DOUBLE,%ecx
107        jne   retlongdouble
108        # Load %ecx with the pointer to storage for the return value
109        movl  24(%ebp),%ecx
110        fstpl (%ecx)
111        jmp   epilogue
112 
113retlongdouble:
114        cmpl  $FFI_TYPE_LONGDOUBLE,%ecx
115        jne   retint64
116        # Load %ecx with the pointer to storage for the return value
117        movl  24(%ebp),%ecx
118        fstpt (%ecx)
119        jmp   epilogue
120 
121retint64:
122        cmpl  $FFI_TYPE_SINT64,%ecx
123        jne   retstruct
124        # Load %ecx with the pointer to storage for the return value
125        movl  24(%ebp),%ecx
126        movl  %eax,0(%ecx)
127        movl  %edx,4(%ecx)
128 
129retstruct:
130        # Nothing to do!
131 
132noretval:
133epilogue:
134	movl %esi,%eax # return the stack pointer detlta in %eax
135	popl %esi # restore previous %esi
136        movl %ebp,%esp
137        popl %ebp
138        ret
139 
140.ffi_call_SYSV_end:
141
142        # This assumes we are using gas.
143        .balign 16
144.globl _ffi_call_STDCALL
145
146_ffi_call_STDCALL:
147        pushl %ebp
148        movl  %esp,%ebp
149
150	#THe: save previous %esi, and store the current stack pointer in %esi
151	pushl %esi
152	movl %esp,%esi
153	
154        # Make room for all of the new args.
155        movl  16(%ebp),%ecx 
156        subl  %ecx,%esp
157
158        movl  %esp,%eax
159
160        # Place all of the ffi_prep_args in position
161        pushl 12(%ebp)
162        pushl %eax
163        call  *8(%ebp)
164
165        # Return stack to previous state and call the function
166        addl  $8,%esp
167
168        # FIXME: Align the stack to a 128-bit boundary to avoid
169        # potential performance hits.
170
171        call  *28(%ebp)
172
173	sub %esp,%esi # difference in stack
174
175        # stdcall functions pop arguments off the stack themselves
176
177        # Load %ecx with the return type code
178        movl  20(%ebp),%ecx
179
180        # If the return value pointer is NULL, assume no return value.
181        cmpl  $0,24(%ebp)
182        jne   sc_retint
183
184        # Even if there is no space for the return value, we are
185        # obliged to handle floating-point values.
186        cmpl  $FFI_TYPE_FLOAT,%ecx
187        jne   sc_noretval
188        fstp  %st(0)
189
190        jmp   sc_epilogue
191
192sc_retint:
193        cmpl  $FFI_TYPE_INT,%ecx
194        jne   sc_retfloat
195        # Load %ecx with the pointer to storage for the return value
196        movl  24(%ebp),%ecx
197        movl  %eax,0(%ecx)
198        jmp   sc_epilogue
199
200sc_retfloat:
201        cmpl  $FFI_TYPE_FLOAT,%ecx
202        jne   sc_retdouble
203         # Load %ecx with the pointer to storage for the return value
204        movl  24(%ebp),%ecx
205        fstps (%ecx)
206        jmp   sc_epilogue
207
208sc_retdouble:
209        cmpl  $FFI_TYPE_DOUBLE,%ecx
210        jne   sc_retlongdouble
211        # Load %ecx with the pointer to storage for the return value
212        movl  24(%ebp),%ecx
213        fstpl (%ecx)
214        jmp   sc_epilogue
215
216sc_retlongdouble:
217        cmpl  $FFI_TYPE_LONGDOUBLE,%ecx
218        jne   sc_retint64
219        # Load %ecx with the pointer to storage for the return value
220        movl  24(%ebp),%ecx
221        fstpt (%ecx)
222        jmp   sc_epilogue
223
224sc_retint64:
225        cmpl  $FFI_TYPE_SINT64,%ecx
226        jne   sc_retstruct
227        # Load %ecx with the pointer to storage for the return value
228        movl  24(%ebp),%ecx
229        movl  %eax,0(%ecx)
230        movl  %edx,4(%ecx)
231
232sc_retstruct:
233        # Nothing to do!
234
235sc_noretval:
236sc_epilogue:
237        movl %esi,%eax # return the stack difference
238	popl %esi # restore previous %esi value
239        movl %ebp,%esp
240        popl %ebp
241        ret
242
243.ffi_call_STDCALL_end: