1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 1996, 1998, 2001-2003, 2005, 2008, 2010 Red Hat, Inc.
4 X86 Foreign Function Interface
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:
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
30 #include <fficonfig.h>
39 .type ffi_call_SYSV,@function
47 /* Make room for all of the new args. */
51 /* Align the stack pointer to 16-bytes */
52 andl $0xfffffff0, %esp
56 /* 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
88 .long noretval-.Lstore_table /* FFI_TYPE_VOID */
89 .long retint-.Lstore_table /* FFI_TYPE_INT */
90 .long retfloat-.Lstore_table /* FFI_TYPE_FLOAT */
91 .long retdouble-.Lstore_table /* FFI_TYPE_DOUBLE */
92 .long retlongdouble-.Lstore_table /* FFI_TYPE_LONGDOUBLE */
93 .long retuint8-.Lstore_table /* FFI_TYPE_UINT8 */
94 .long retsint8-.Lstore_table /* FFI_TYPE_SINT8 */
95 .long retuint16-.Lstore_table /* FFI_TYPE_UINT16 */
96 .long retsint16-.Lstore_table /* FFI_TYPE_SINT16 */
97 .long retint-.Lstore_table /* FFI_TYPE_UINT32 */
98 .long retint-.Lstore_table /* FFI_TYPE_SINT32 */
99 .long retint64-.Lstore_table /* FFI_TYPE_UINT64 */
100 .long retint64-.Lstore_table /* FFI_TYPE_SINT64 */
101 .long retstruct-.Lstore_table /* FFI_TYPE_STRUCT */
102 .long retint-.Lstore_table /* FFI_TYPE_POINTER */
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 */
167 .size ffi_call_SYSV,.ffi_call_SYSV_end-ffi_call_SYSV
170 FFI_HIDDEN (ffi_closure_SYSV)
171 .globl ffi_closure_SYSV
172 .type ffi_closure_SYSV, @function
182 movl %edx, -12(%ebp) /* resp */
184 movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
186 movl %edx, (%esp) /* &resp */
187 #if defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE || !defined __PIC__
188 call ffi_closure_SYSV_inner
194 addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
195 call ffi_closure_SYSV_inner@PLT
199 cmpl $FFI_TYPE_INT, %eax
202 /* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
203 FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
204 cmpl $FFI_TYPE_UINT64, %eax
206 cmpl $FFI_TYPE_UINT8, %eax
209 0: cmpl $FFI_TYPE_FLOAT, %eax
211 cmpl $FFI_TYPE_DOUBLE, %eax
213 cmpl $FFI_TYPE_LONGDOUBLE, %eax
215 cmpl $FFI_TYPE_SINT64, %eax
217 cmpl $FFI_TYPE_STRUCT, %eax
244 .size ffi_closure_SYSV, .-ffi_closure_SYSV
248 /* Precalculate for e.g. the Solaris 10/x86 assembler. */
249 #if FFI_TRAMPOLINE_SIZE == 10
250 #define RAW_CLOSURE_CIF_OFFSET 12
251 #define RAW_CLOSURE_FUN_OFFSET 16
252 #define RAW_CLOSURE_USER_DATA_OFFSET 20
253 #elif FFI_TRAMPOLINE_SIZE == 24
254 #define RAW_CLOSURE_CIF_OFFSET 24
255 #define RAW_CLOSURE_FUN_OFFSET 28
256 #define RAW_CLOSURE_USER_DATA_OFFSET 32
258 #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
259 #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
260 #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
262 #define CIF_FLAGS_OFFSET 20
265 FFI_HIDDEN (ffi_closure_raw_SYSV)
266 .globl ffi_closure_raw_SYSV
267 .type ffi_closure_raw_SYSV, @function
269 ffi_closure_raw_SYSV:
278 movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
279 movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
280 movl %edx, 12(%esp) /* user_data */
281 leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
282 movl %edx, 8(%esp) /* raw_args */
284 movl %edx, 4(%esp) /* &res */
285 movl %esi, (%esp) /* cif */
286 call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
287 movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
288 cmpl $FFI_TYPE_INT, %eax
291 /* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
292 FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
293 cmpl $FFI_TYPE_UINT64, %eax
295 cmpl $FFI_TYPE_UINT8, %eax
298 cmpl $FFI_TYPE_FLOAT, %eax
300 cmpl $FFI_TYPE_DOUBLE, %eax
302 cmpl $FFI_TYPE_LONGDOUBLE, %eax
304 cmpl $FFI_TYPE_SINT64, %eax
328 .size ffi_closure_raw_SYSV, .-ffi_closure_raw_SYSV
331 .section .eh_frame,EH_FRAME_FLAGS,@progbits
333 .long .LECIE1-.LSCIE1 /* Length of Common Information Entry */
335 .long 0x0 /* CIE Identifier Tag */
336 .byte 0x1 /* CIE Version */
337 #ifdef HAVE_AS_ASCII_PSEUDO_OP
339 .ascii "zR\0" /* CIE Augmentation */
341 .ascii "\0" /* CIE Augmentation */
343 #elif defined HAVE_AS_STRING_PSEUDO_OP
345 .string "zR" /* CIE Augmentation */
347 .string "" /* CIE Augmentation */
350 #error missing .ascii/.string
352 .byte 0x1 /* .uleb128 0x1; CIE Code Alignment Factor */
353 .byte 0x7c /* .sleb128 -4; CIE Data Alignment Factor */
354 .byte 0x8 /* CIE RA Column */
356 .byte 0x1 /* .uleb128 0x1; Augmentation size */
357 .byte 0x1b /* FDE Encoding (pcrel sdata4) */
359 .byte 0xc /* DW_CFA_def_cfa */
360 .byte 0x4 /* .uleb128 0x4 */
361 .byte 0x4 /* .uleb128 0x4 */
362 .byte 0x88 /* DW_CFA_offset, column 0x8 */
363 .byte 0x1 /* .uleb128 0x1 */
367 .long .LEFDE1-.LASFDE1 /* FDE Length */
369 .long .LASFDE1-.Lframe1 /* FDE CIE offset */
370 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
371 .long .LFB1-. /* FDE initial location */
372 #elif defined __PIC__
377 .long .LFE1-.LFB1 /* FDE address range */
379 .byte 0x0 /* .uleb128 0x0; Augmentation size */
381 .byte 0x4 /* DW_CFA_advance_loc4 */
383 .byte 0xe /* DW_CFA_def_cfa_offset */
384 .byte 0x8 /* .uleb128 0x8 */
385 .byte 0x85 /* DW_CFA_offset, column 0x5 */
386 .byte 0x2 /* .uleb128 0x2 */
387 .byte 0x4 /* DW_CFA_advance_loc4 */
389 .byte 0xd /* DW_CFA_def_cfa_register */
390 .byte 0x5 /* .uleb128 0x5 */
394 .long .LEFDE2-.LASFDE2 /* FDE Length */
396 .long .LASFDE2-.Lframe1 /* FDE CIE offset */
397 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
398 .long .LFB2-. /* FDE initial location */
399 #elif defined __PIC__
404 .long .LFE2-.LFB2 /* FDE address range */
406 .byte 0x0 /* .uleb128 0x0; Augmentation size */
408 .byte 0x4 /* DW_CFA_advance_loc4 */
410 .byte 0xe /* DW_CFA_def_cfa_offset */
411 .byte 0x8 /* .uleb128 0x8 */
412 .byte 0x85 /* DW_CFA_offset, column 0x5 */
413 .byte 0x2 /* .uleb128 0x2 */
414 .byte 0x4 /* DW_CFA_advance_loc4 */
416 .byte 0xd /* DW_CFA_def_cfa_register */
417 .byte 0x5 /* .uleb128 0x5 */
418 #if !defined HAVE_HIDDEN_VISIBILITY_ATTRIBUTE && defined __PIC__
419 .byte 0x4 /* DW_CFA_advance_loc4 */
421 .byte 0x83 /* DW_CFA_offset, column 0x3 */
422 .byte 0xa /* .uleb128 0xa */
430 .long .LEFDE3-.LASFDE3 /* FDE Length */
432 .long .LASFDE3-.Lframe1 /* FDE CIE offset */
433 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
434 .long .LFB3-. /* FDE initial location */
435 #elif defined __PIC__
440 .long .LFE3-.LFB3 /* FDE address range */
442 .byte 0x0 /* .uleb128 0x0; Augmentation size */
444 .byte 0x4 /* DW_CFA_advance_loc4 */
446 .byte 0xe /* DW_CFA_def_cfa_offset */
447 .byte 0x8 /* .uleb128 0x8 */
448 .byte 0x85 /* DW_CFA_offset, column 0x5 */
449 .byte 0x2 /* .uleb128 0x2 */
450 .byte 0x4 /* DW_CFA_advance_loc4 */
452 .byte 0xd /* DW_CFA_def_cfa_register */
453 .byte 0x5 /* .uleb128 0x5 */
454 .byte 0x4 /* DW_CFA_advance_loc4 */
456 .byte 0x86 /* DW_CFA_offset, column 0x6 */
457 .byte 0x3 /* .uleb128 0x3 */
463 #endif /* ifndef __x86_64__ */
465 #if defined __ELF__ && defined __linux__
466 .section .note.GNU-stack,"",@progbits