1 /* -----------------------------------------------------------------------
2 darwin.S - Copyright (c) 1996, 1998, 2001, 2002, 2003, 2005 Red Hat, Inc.
3 Copyright (C) 2008 Free Software Foundation, Inc.
5 X86 Foreign Function Interface
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 ``Software''), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 -----------------------------------------------------------------------
32 #include <fficonfig.h>
49 /* Make room for all of the new args. */
55 /* Place all of the ffi_prep_args in position */
61 /* Return stack to previous state and call the function */
66 /* Load %ecx with the return type code */
69 /* Protect %esi. We're going to pop it in the epilogue. */
72 /* If the return value pointer is NULL, assume no return value. */
76 /* Even if there is no space for the return value, we are
77 obliged to handle floating-point values. */
78 cmpl $FFI_TYPE_FLOAT,%ecx
87 .long noretval-.Lstore_table /* FFI_TYPE_VOID */
88 .long retint-.Lstore_table /* FFI_TYPE_INT */
89 .long retfloat-.Lstore_table /* FFI_TYPE_FLOAT */
90 .long retdouble-.Lstore_table /* FFI_TYPE_DOUBLE */
91 .long retlongdouble-.Lstore_table /* FFI_TYPE_LONGDOUBLE */
92 .long retuint8-.Lstore_table /* FFI_TYPE_UINT8 */
93 .long retsint8-.Lstore_table /* FFI_TYPE_SINT8 */
94 .long retuint16-.Lstore_table /* FFI_TYPE_UINT16 */
95 .long retsint16-.Lstore_table /* FFI_TYPE_SINT16 */
96 .long retint-.Lstore_table /* FFI_TYPE_UINT32 */
97 .long retint-.Lstore_table /* FFI_TYPE_SINT32 */
98 .long retint64-.Lstore_table /* FFI_TYPE_UINT64 */
99 .long retint64-.Lstore_table /* FFI_TYPE_SINT64 */
100 .long retstruct-.Lstore_table /* FFI_TYPE_STRUCT */
101 .long retint-.Lstore_table /* FFI_TYPE_POINTER */
102 .long retstruct1b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_1B */
103 .long retstruct2b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_2B */
106 add (%esi, %ecx, 4), %esi
109 /* Sign/zero extend as appropriate. */
127 /* Load %ecx with the pointer to storage for the return value */
133 /* Load %ecx with the pointer to storage for the return value */
139 /* Load %ecx with the pointer to storage for the return value */
145 /* Load %ecx with the pointer to storage for the return value */
152 /* Load %ecx with the pointer to storage for the return value */
158 /* Load %ecx with the pointer to storage for the return value */
164 /* Load %ecx with the pointer to storage for the return value */
182 FFI_HIDDEN (ffi_closure_SYSV)
183 .globl _ffi_closure_SYSV
193 movl %edx, -12(%ebp) /* resp */
195 movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
197 movl %edx, (%esp) /* &resp */
200 call L_ffi_closure_SYSV_inner$stub
203 cmpl $FFI_TYPE_INT, %eax
206 /* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
207 FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
208 cmpl $FFI_TYPE_UINT64, %eax
210 cmpl $FFI_TYPE_UINT8, %eax
213 0: cmpl $FFI_TYPE_FLOAT, %eax
215 cmpl $FFI_TYPE_DOUBLE, %eax
217 cmpl $FFI_TYPE_LONGDOUBLE, %eax
219 cmpl $FFI_TYPE_SINT64, %eax
221 cmpl $FFI_TYPE_SMALL_STRUCT_1B, %eax
223 cmpl $FFI_TYPE_SMALL_STRUCT_2B, %eax
225 cmpl $FFI_TYPE_STRUCT, %eax
262 #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
263 #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
264 #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
265 #define CIF_FLAGS_OFFSET 20
268 FFI_HIDDEN (ffi_closure_raw_SYSV)
269 .globl _ffi_closure_raw_SYSV
271 _ffi_closure_raw_SYSV:
280 movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
281 movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
282 movl %edx, 12(%esp) /* user_data */
283 leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
284 movl %edx, 8(%esp) /* raw_args */
286 movl %edx, 4(%esp) /* &res */
287 movl %esi, (%esp) /* cif */
288 call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
289 movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
290 cmpl $FFI_TYPE_INT, %eax
293 /* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
294 FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
295 cmpl $FFI_TYPE_UINT64, %eax
297 cmpl $FFI_TYPE_UINT8, %eax
300 cmpl $FFI_TYPE_FLOAT, %eax
302 cmpl $FFI_TYPE_DOUBLE, %eax
304 cmpl $FFI_TYPE_LONGDOUBLE, %eax
306 cmpl $FFI_TYPE_SINT64, %eax
332 .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
333 L_ffi_closure_SYSV_inner$stub:
334 .indirect_symbol _ffi_closure_SYSV_inner
335 hlt ; hlt ; hlt ; hlt ; hlt
338 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
340 .set L$set$0,LECIE1-LSCIE1
358 .globl _ffi_call_SYSV.eh
361 .set L$set$1,LEFDE1-LASFDE1
364 .long LASFDE1-EH_frame1
366 .set L$set$2,.LFE1-.LFB1
370 .set L$set$3,.LCFI0-.LFB1
377 .set L$set$4,.LCFI1-.LCFI0
383 .globl _ffi_closure_SYSV.eh
384 _ffi_closure_SYSV.eh:
386 .set L$set$5,LEFDE2-LASFDE2
389 .long LASFDE2-EH_frame1
391 .set L$set$6,.LFE2-.LFB2
395 .set L$set$7,.LCFI2-.LFB2
402 .set L$set$8,.LCFI3-.LCFI2
411 .globl _ffi_closure_raw_SYSV.eh
412 _ffi_closure_raw_SYSV.eh:
414 .set L$set$10,LEFDE3-LASFDE3
417 .long LASFDE3-EH_frame1
419 .set L$set$11,.LFE3-.LFB3
423 .set L$set$12,.LCFI4-.LFB3
430 .set L$set$13,.LCFI5-.LCFI4
435 .set L$set$14,.LCFI6-.LCFI5
444 #endif /* ifndef __x86_64__ */