]> gcc.gnu.org Git - gcc.git/blob - libffi/src/x86/darwin.S
configure.ac [...]: Set X86_DARWIN symbol and conditional.
[gcc.git] / libffi / src / x86 / darwin.S
1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 1996, 1998, 2001, 2002, 2003, 2005 Red Hat, Inc.
3
4 X86 Foreign Function Interface
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 ``Software''), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24 ----------------------------------------------------------------------- */
25
26 #ifndef __x86_64__
27
28 #define LIBFFI_ASM
29 #include <fficonfig.h>
30 #include <ffi.h>
31
32 .text
33
34 .globl _ffi_prep_args
35
36 .align 4
37 .globl _ffi_call_SYSV
38
39 _ffi_call_SYSV:
40 .LFB1:
41 pushl %ebp
42 .LCFI0:
43 movl %esp,%ebp
44 .LCFI1:
45 subl $8,%esp
46 /* Make room for all of the new args. */
47 movl 16(%ebp),%ecx
48 subl %ecx,%esp
49
50 movl %esp,%eax
51
52 /* Place all of the ffi_prep_args in position */
53 subl $8,%esp
54 pushl 12(%ebp)
55 pushl %eax
56 call *8(%ebp)
57
58 /* Return stack to previous state and call the function */
59 addl $16,%esp
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
82 retint:
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
90 retfloat:
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
98 retdouble:
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
106 retlongdouble:
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
114 retint64:
115 cmpl $FFI_TYPE_SINT64,%ecx
116 jne retstruct1b
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 jmp epilogue
122
123 retstruct1b:
124 cmpl $FFI_TYPE_SINT8,%ecx
125 jne retstruct2b
126 /* Load %ecx with the pointer to storage for the return value */
127 movl 24(%ebp),%ecx
128 movb %al,0(%ecx)
129 jmp epilogue
130
131 retstruct2b:
132 cmpl $FFI_TYPE_SINT16,%ecx
133 jne retstruct
134 /* Load %ecx with the pointer to storage for the return value */
135 movl 24(%ebp),%ecx
136 movw %ax,0(%ecx)
137 jmp epilogue
138
139 retstruct:
140 cmpl $FFI_TYPE_STRUCT,%ecx
141 jne noretval
142 /* Nothing to do! */
143 addl $4,%esp
144 popl %ebp
145 ret
146
147 noretval:
148 epilogue:
149 addl $8,%esp
150 movl %ebp,%esp
151 popl %ebp
152 ret
153 .LFE1:
154 .ffi_call_SYSV_end:
155
156 .align 4
157 FFI_HIDDEN (ffi_closure_SYSV)
158 .globl _ffi_closure_SYSV
159
160 _ffi_closure_SYSV:
161 .LFB2:
162 pushl %ebp
163 .LCFI2:
164 movl %esp, %ebp
165 .LCFI3:
166 subl $40, %esp
167 leal -24(%ebp), %edx
168 movl %edx, -12(%ebp) /* resp */
169 leal 8(%ebp), %edx
170 movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
171 leal -12(%ebp), %edx
172 movl %edx, (%esp) /* &resp */
173 movl %ebx, 8(%esp)
174 .LCFI7:
175 call L_ffi_closure_SYSV_inner$stub
176 movl 8(%esp), %ebx
177 movl -12(%ebp), %ecx
178 cmpl $FFI_TYPE_INT, %eax
179 je .Lcls_retint
180 cmpl $FFI_TYPE_FLOAT, %eax
181 je .Lcls_retfloat
182 cmpl $FFI_TYPE_DOUBLE, %eax
183 je .Lcls_retdouble
184 cmpl $FFI_TYPE_LONGDOUBLE, %eax
185 je .Lcls_retldouble
186 cmpl $FFI_TYPE_SINT64, %eax
187 je .Lcls_retllong
188 cmpl $FFI_TYPE_SINT8, %eax
189 je .Lcls_retstruct1
190 cmpl $FFI_TYPE_SINT16, %eax
191 je .Lcls_retstruct2
192 cmpl $FFI_TYPE_STRUCT, %eax
193 je .Lcls_retstruct
194 .Lcls_epilogue:
195 movl %ebp, %esp
196 popl %ebp
197 ret
198 .Lcls_retint:
199 movl (%ecx), %eax
200 jmp .Lcls_epilogue
201 .Lcls_retfloat:
202 flds (%ecx)
203 jmp .Lcls_epilogue
204 .Lcls_retdouble:
205 fldl (%ecx)
206 jmp .Lcls_epilogue
207 .Lcls_retldouble:
208 fldt (%ecx)
209 jmp .Lcls_epilogue
210 .Lcls_retllong:
211 movl (%ecx), %eax
212 movl 4(%ecx), %edx
213 jmp .Lcls_epilogue
214 .Lcls_retstruct1:
215 movsbl (%ecx), %eax
216 jmp .Lcls_epilogue
217 .Lcls_retstruct2:
218 movswl (%ecx), %eax
219 jmp .Lcls_epilogue
220 .Lcls_retstruct:
221 lea -8(%ebp),%esp
222 movl %ebp, %esp
223 popl %ebp
224 ret $4
225 .LFE2:
226
227 #if !FFI_NO_RAW_API
228
229 #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
230 #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
231 #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
232 #define CIF_FLAGS_OFFSET 20
233
234 .align 4
235 FFI_HIDDEN (ffi_closure_raw_SYSV)
236 .globl _ffi_closure_raw_SYSV
237
238 _ffi_closure_raw_SYSV:
239 .LFB3:
240 pushl %ebp
241 .LCFI4:
242 movl %esp, %ebp
243 .LCFI5:
244 pushl %esi
245 .LCFI6:
246 subl $36, %esp
247 movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
248 movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
249 movl %edx, 12(%esp) /* user_data */
250 leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
251 movl %edx, 8(%esp) /* raw_args */
252 leal -24(%ebp), %edx
253 movl %edx, 4(%esp) /* &res */
254 movl %esi, (%esp) /* cif */
255 call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
256 movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
257 cmpl $FFI_TYPE_INT, %eax
258 je .Lrcls_retint
259 cmpl $FFI_TYPE_FLOAT, %eax
260 je .Lrcls_retfloat
261 cmpl $FFI_TYPE_DOUBLE, %eax
262 je .Lrcls_retdouble
263 cmpl $FFI_TYPE_LONGDOUBLE, %eax
264 je .Lrcls_retldouble
265 cmpl $FFI_TYPE_SINT64, %eax
266 je .Lrcls_retllong
267 .Lrcls_epilogue:
268 addl $36, %esp
269 popl %esi
270 popl %ebp
271 ret
272 .Lrcls_retint:
273 movl -24(%ebp), %eax
274 jmp .Lrcls_epilogue
275 .Lrcls_retfloat:
276 flds -24(%ebp)
277 jmp .Lrcls_epilogue
278 .Lrcls_retdouble:
279 fldl -24(%ebp)
280 jmp .Lrcls_epilogue
281 .Lrcls_retldouble:
282 fldt -24(%ebp)
283 jmp .Lrcls_epilogue
284 .Lrcls_retllong:
285 movl -24(%ebp), %eax
286 movl -20(%ebp), %edx
287 jmp .Lrcls_epilogue
288 .LFE3:
289 #endif
290
291 .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
292 L_ffi_closure_SYSV_inner$stub:
293 .indirect_symbol _ffi_closure_SYSV_inner
294 hlt ; hlt ; hlt ; hlt ; hlt
295
296
297 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
298 EH_frame1:
299 .set L$set$0,LECIE1-LSCIE1
300 .long L$set$0
301 LSCIE1:
302 .long 0x0
303 .byte 0x1
304 .ascii "zR\0"
305 .byte 0x1
306 .byte 0x7c
307 .byte 0x8
308 .byte 0x1
309 .byte 0x10
310 .byte 0xc
311 .byte 0x5
312 .byte 0x4
313 .byte 0x88
314 .byte 0x1
315 .align 2
316 LECIE1:
317 .globl _ffi_call_SYSV.eh
318 _ffi_call_SYSV.eh:
319 LSFDE1:
320 .set L$set$1,LEFDE1-LASFDE1
321 .long L$set$1
322 LASFDE1:
323 .long LASFDE1-EH_frame1
324 .long .LFB1-.
325 .set L$set$2,.LFE1-.LFB1
326 .long L$set$2
327 .byte 0x0
328 .byte 0x4
329 .set L$set$3,.LCFI0-.LFB1
330 .long L$set$3
331 .byte 0xe
332 .byte 0x8
333 .byte 0x84
334 .byte 0x2
335 .byte 0x4
336 .set L$set$4,.LCFI1-.LCFI0
337 .long L$set$4
338 .byte 0xd
339 .byte 0x4
340 .align 2
341 LEFDE1:
342 .globl _ffi_closure_SYSV.eh
343 _ffi_closure_SYSV.eh:
344 LSFDE2:
345 .set L$set$5,LEFDE2-LASFDE2
346 .long L$set$5
347 LASFDE2:
348 .long LASFDE2-EH_frame1
349 .long .LFB2-.
350 .set L$set$6,.LFE2-.LFB2
351 .long L$set$6
352 .byte 0x0
353 .byte 0x4
354 .set L$set$7,.LCFI2-.LFB2
355 .long L$set$7
356 .byte 0xe
357 .byte 0x8
358 .byte 0x84
359 .byte 0x2
360 .byte 0x4
361 .set L$set$8,.LCFI3-.LCFI2
362 .long L$set$8
363 .byte 0xd
364 .byte 0x4
365 .align 2
366 LEFDE2:
367
368 #if !FFI_NO_RAW_API
369
370 .globl _ffi_closure_raw_SYSV.eh
371 _ffi_closure_raw_SYSV.eh:
372 LSFDE3:
373 .set L$set$10,LEFDE3-LASFDE3
374 .long L$set$10
375 LASFDE3:
376 .long LASFDE3-EH_frame1
377 .long .LFB3-.
378 .set L$set$11,.LFE3-.LFB3
379 .long L$set$11
380 .byte 0x0
381 .byte 0x4
382 .set L$set$12,.LCFI4-.LFB3
383 .long L$set$12
384 .byte 0xe
385 .byte 0x8
386 .byte 0x84
387 .byte 0x2
388 .byte 0x4
389 .set L$set$13,.LCFI5-.LCFI4
390 .long L$set$13
391 .byte 0xd
392 .byte 0x4
393 .byte 0x4
394 .set L$set$14,.LCFI6-.LCFI5
395 .long L$set$14
396 .byte 0x85
397 .byte 0x3
398 .align 2
399 LEFDE3:
400
401 #endif
402
403 #endif /* ifndef __x86_64__ */
This page took 0.051896 seconds and 5 git commands to generate.