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, EXPRESS
19
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
23
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
OTHER DEALINGS IN THE SOFTWARE.
26
----------------------------------------------------------------------- */
31
#include <fficonfig.h>
48
/* Make room for all of the new args. */
54
/* Place all of the ffi_prep_args in position */
60
/* Return stack to previous state and call the function */
65
/* Load %ecx with the return type code */
68
/* Protect %esi. We're going to pop it in the epilogue. */
71
/* If the return value pointer is NULL, assume no return value. */
75
/* Even if there is no space for the return value, we are
76
obliged to handle floating-point values. */
77
cmpl $FFI_TYPE_FLOAT,%ecx
86
.long noretval-.Lstore_table /* FFI_TYPE_VOID */
87
.long retint-.Lstore_table /* FFI_TYPE_INT */
88
.long retfloat-.Lstore_table /* FFI_TYPE_FLOAT */
89
.long retdouble-.Lstore_table /* FFI_TYPE_DOUBLE */
90
.long retlongdouble-.Lstore_table /* FFI_TYPE_LONGDOUBLE */
91
.long retuint8-.Lstore_table /* FFI_TYPE_UINT8 */
92
.long retsint8-.Lstore_table /* FFI_TYPE_SINT8 */
93
.long retuint16-.Lstore_table /* FFI_TYPE_UINT16 */
94
.long retsint16-.Lstore_table /* FFI_TYPE_SINT16 */
95
.long retint-.Lstore_table /* FFI_TYPE_UINT32 */
96
.long retint-.Lstore_table /* FFI_TYPE_SINT32 */
97
.long retint64-.Lstore_table /* FFI_TYPE_UINT64 */
98
.long retint64-.Lstore_table /* FFI_TYPE_SINT64 */
99
.long retstruct-.Lstore_table /* FFI_TYPE_STRUCT */
100
.long retint-.Lstore_table /* FFI_TYPE_POINTER */
101
.long retstruct1b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_1B */
102
.long retstruct2b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_2B */
105
add (%esi, %ecx, 4), %esi
108
/* Sign/zero extend as appropriate. */
126
/* Load %ecx with the pointer to storage for the return value */
132
/* Load %ecx with the pointer to storage for the return value */
138
/* Load %ecx with the pointer to storage for the return value */
144
/* Load %ecx with the pointer to storage for the return value */
151
/* Load %ecx with the pointer to storage for the return value */
157
/* Load %ecx with the pointer to storage for the return value */
163
/* Load %ecx with the pointer to storage for the return value */
181
FFI_HIDDEN (ffi_closure_SYSV)
182
.globl _ffi_closure_SYSV
192
movl %edx, -12(%ebp) /* resp */
194
movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
196
movl %edx, (%esp) /* &resp */
199
call L_ffi_closure_SYSV_inner$stub
202
cmpl $FFI_TYPE_INT, %eax
205
/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
206
FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
207
cmpl $FFI_TYPE_UINT64, %eax
209
cmpl $FFI_TYPE_UINT8, %eax
212
0: cmpl $FFI_TYPE_FLOAT, %eax
214
cmpl $FFI_TYPE_DOUBLE, %eax
216
cmpl $FFI_TYPE_LONGDOUBLE, %eax
218
cmpl $FFI_TYPE_SINT64, %eax
220
cmpl $FFI_TYPE_SMALL_STRUCT_1B, %eax
222
cmpl $FFI_TYPE_SMALL_STRUCT_2B, %eax
224
cmpl $FFI_TYPE_STRUCT, %eax
261
#define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
262
#define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
263
#define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
264
#define CIF_FLAGS_OFFSET 20
267
FFI_HIDDEN (ffi_closure_raw_SYSV)
268
.globl _ffi_closure_raw_SYSV
270
_ffi_closure_raw_SYSV:
279
movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
280
movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
281
movl %edx, 12(%esp) /* user_data */
282
leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
283
movl %edx, 8(%esp) /* raw_args */
285
movl %edx, 4(%esp) /* &res */
286
movl %esi, (%esp) /* cif */
287
call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
288
movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
289
cmpl $FFI_TYPE_INT, %eax
292
/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
293
FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
294
cmpl $FFI_TYPE_UINT64, %eax
296
cmpl $FFI_TYPE_UINT8, %eax
299
cmpl $FFI_TYPE_FLOAT, %eax
301
cmpl $FFI_TYPE_DOUBLE, %eax
303
cmpl $FFI_TYPE_LONGDOUBLE, %eax
305
cmpl $FFI_TYPE_SINT64, %eax
331
.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
332
L_ffi_closure_SYSV_inner$stub:
333
.indirect_symbol _ffi_closure_SYSV_inner
334
hlt ; hlt ; hlt ; hlt ; hlt
337
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
339
.set L$set$0,LECIE1-LSCIE1
357
.globl _ffi_call_SYSV.eh
360
.set L$set$1,LEFDE1-LASFDE1
363
.long LASFDE1-EH_frame1
365
.set L$set$2,.LFE1-.LFB1
369
.set L$set$3,.LCFI0-.LFB1
376
.set L$set$4,.LCFI1-.LCFI0
382
.globl _ffi_closure_SYSV.eh
383
_ffi_closure_SYSV.eh:
385
.set L$set$5,LEFDE2-LASFDE2
388
.long LASFDE2-EH_frame1
390
.set L$set$6,.LFE2-.LFB2
394
.set L$set$7,.LCFI2-.LFB2
401
.set L$set$8,.LCFI3-.LCFI2
410
.globl _ffi_closure_raw_SYSV.eh
411
_ffi_closure_raw_SYSV.eh:
413
.set L$set$10,LEFDE3-LASFDE3
416
.long LASFDE3-EH_frame1
418
.set L$set$11,.LFE3-.LFB3
422
.set L$set$12,.LCFI4-.LFB3
429
.set L$set$13,.LCFI5-.LCFI4
434
.set L$set$14,.LCFI6-.LCFI5
443
#endif /* ifndef __x86_64__ */