1 /* -----------------------------------------------------------------------
2 win32.S - Copyright (c) 1996, 1998, 2001, 2002, 2009 Red Hat, Inc.
3 Copyright (c) 2001 John Beniton
4 Copyright (c) 2002 Ranjit Mathew
7 X86 Foreign Function Interface
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:
17 The above copyright notice and this permission notice shall be included
18 in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 -----------------------------------------------------------------------
32 #include <fficonfig.h>
37 # This assumes we are using gas.
40 .def _ffi_call_SYSV; .scl 2; .type 32; .endef
47 # Make room for all of the new args.
53 # Place all of the ffi_prep_args in position
58 # Return stack to previous state and call the function
61 # FIXME: Align the stack to a 128-bit boundary to avoid
62 # potential performance hits.
66 # Load %ecx with the return type code
69 # If the return value pointer is NULL, assume no return value.
73 # Even if there is no space for the return value, we are
74 # obliged to handle floating-point values.
75 cmpl $FFI_TYPE_FLOAT,%ecx
83 # Do not insert anything here between the call and the jump table.
85 .long .Lnoretval /* FFI_TYPE_VOID */
86 .long .Lretint /* FFI_TYPE_INT */
87 .long .Lretfloat /* FFI_TYPE_FLOAT */
88 .long .Lretdouble /* FFI_TYPE_DOUBLE */
89 .long .Lretlongdouble /* FFI_TYPE_LONGDOUBLE */
90 .long .Lretuint8 /* FFI_TYPE_UINT8 */
91 .long .Lretsint8 /* FFI_TYPE_SINT8 */
92 .long .Lretuint16 /* FFI_TYPE_UINT16 */
93 .long .Lretsint16 /* FFI_TYPE_SINT16 */
94 .long .Lretint /* FFI_TYPE_UINT32 */
95 .long .Lretint /* FFI_TYPE_SINT32 */
96 .long .Lretint64 /* FFI_TYPE_UINT64 */
97 .long .Lretint64 /* FFI_TYPE_SINT64 */
98 .long .Lretstruct /* FFI_TYPE_STRUCT */
99 .long .Lretint /* FFI_TYPE_POINTER */
100 .long .Lretstruct1b /* FFI_TYPE_SMALL_STRUCT_1B */
101 .long .Lretstruct2b /* FFI_TYPE_SMALL_STRUCT_2B */
102 .long .Lretstruct4b /* FFI_TYPE_SMALL_STRUCT_4B */
110 /* Sign/zero extend as appropriate. */
128 # Load %ecx with the pointer to storage for the return value
134 # Load %ecx with the pointer to storage for the return value
140 # Load %ecx with the pointer to storage for the return value
146 # Load %ecx with the pointer to storage for the return value
152 # Load %ecx with the pointer to storage for the return value
159 # Load %ecx with the pointer to storage for the return value
165 # Load %ecx with the pointer to storage for the return value
171 # Load %ecx with the pointer to storage for the return value
187 # This assumes we are using gas.
189 .globl _ffi_call_STDCALL
190 .def _ffi_call_STDCALL; .scl 2; .type 32; .endef
197 # Make room for all of the new args.
203 # Place all of the ffi_prep_args in position
208 # Return stack to previous state and call the function
211 # FIXME: Align the stack to a 128-bit boundary to avoid
212 # potential performance hits.
216 # stdcall functions pop arguments off the stack themselves
218 # Load %ecx with the return type code
221 # If the return value pointer is NULL, assume no return value.
225 # Even if there is no space for the return value, we are
226 # obliged to handle floating-point values.
227 cmpl $FFI_TYPE_FLOAT,%ecx
235 # Do not insert anything here between the call and the jump table.
237 .long .Lsc_noretval /* FFI_TYPE_VOID */
238 .long .Lsc_retint /* FFI_TYPE_INT */
239 .long .Lsc_retfloat /* FFI_TYPE_FLOAT */
240 .long .Lsc_retdouble /* FFI_TYPE_DOUBLE */
241 .long .Lsc_retlongdouble /* FFI_TYPE_LONGDOUBLE */
242 .long .Lsc_retuint8 /* FFI_TYPE_UINT8 */
243 .long .Lsc_retsint8 /* FFI_TYPE_SINT8 */
244 .long .Lsc_retuint16 /* FFI_TYPE_UINT16 */
245 .long .Lsc_retsint16 /* FFI_TYPE_SINT16 */
246 .long .Lsc_retint /* FFI_TYPE_UINT32 */
247 .long .Lsc_retint /* FFI_TYPE_SINT32 */
248 .long .Lsc_retint64 /* FFI_TYPE_UINT64 */
249 .long .Lsc_retint64 /* FFI_TYPE_SINT64 */
250 .long .Lsc_retstruct /* FFI_TYPE_STRUCT */
251 .long .Lsc_retint /* FFI_TYPE_POINTER */
252 .long .Lsc_retstruct1b /* FFI_TYPE_SMALL_STRUCT_1B */
253 .long .Lsc_retstruct2b /* FFI_TYPE_SMALL_STRUCT_2B */
254 .long .Lsc_retstruct4b /* FFI_TYPE_SMALL_STRUCT_4B */
263 /* Sign/zero extend as appropriate. */
281 # Load %ecx with the pointer to storage for the return value
287 # Load %ecx with the pointer to storage for the return value
293 # Load %ecx with the pointer to storage for the return value
299 # Load %ecx with the pointer to storage for the return value
305 # Load %ecx with the pointer to storage for the return value
312 # Load %ecx with the pointer to storage for the return value
318 # Load %ecx with the pointer to storage for the return value
324 # Load %ecx with the pointer to storage for the return value
337 .ffi_call_STDCALL_end:
340 # This assumes we are using gas.
342 .globl _ffi_closure_SYSV
343 .def _ffi_closure_SYSV; .scl 2; .type 32; .endef
352 movl %edx, -12(%ebp) /* resp */
354 movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
356 movl %edx, (%esp) /* &resp */
357 call _ffi_closure_SYSV_inner
362 # Do not insert anything here between the call and the jump table.
364 .long .Lcls_noretval /* FFI_TYPE_VOID */
365 .long .Lcls_retint /* FFI_TYPE_INT */
366 .long .Lcls_retfloat /* FFI_TYPE_FLOAT */
367 .long .Lcls_retdouble /* FFI_TYPE_DOUBLE */
368 .long .Lcls_retldouble /* FFI_TYPE_LONGDOUBLE */
369 .long .Lcls_retuint8 /* FFI_TYPE_UINT8 */
370 .long .Lcls_retsint8 /* FFI_TYPE_SINT8 */
371 .long .Lcls_retuint16 /* FFI_TYPE_UINT16 */
372 .long .Lcls_retsint16 /* FFI_TYPE_SINT16 */
373 .long .Lcls_retint /* FFI_TYPE_UINT32 */
374 .long .Lcls_retint /* FFI_TYPE_SINT32 */
375 .long .Lcls_retllong /* FFI_TYPE_UINT64 */
376 .long .Lcls_retllong /* FFI_TYPE_SINT64 */
377 .long .Lcls_retstruct /* FFI_TYPE_STRUCT */
378 .long .Lcls_retint /* FFI_TYPE_POINTER */
379 .long .Lcls_retstruct1 /* FFI_TYPE_SMALL_STRUCT_1B */
380 .long .Lcls_retstruct2 /* FFI_TYPE_SMALL_STRUCT_2B */
381 .long .Lcls_retstruct4 /* FFI_TYPE_SMALL_STRUCT_4B */
390 /* Sign/zero extend as appropriate. */
441 # Caller expects us to pop struct return value pointer hidden arg.
451 .ffi_closure_SYSV_end:
456 #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
457 #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
458 #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
459 #define CIF_FLAGS_OFFSET 20
461 # This assumes we are using gas.
463 .globl _ffi_closure_raw_SYSV
464 .def _ffi_closure_raw_SYSV; .scl 2; .type 32; .endef
465 _ffi_closure_raw_SYSV:
474 movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
475 movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
476 movl %edx, 12(%esp) /* user_data */
477 leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
478 movl %edx, 8(%esp) /* raw_args */
480 movl %edx, 4(%esp) /* &res */
481 movl %esi, (%esp) /* cif */
482 call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
483 movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
486 # Do not insert anything here between the call and the jump table.
488 .long .Lrcls_noretval /* FFI_TYPE_VOID */
489 .long .Lrcls_retint /* FFI_TYPE_INT */
490 .long .Lrcls_retfloat /* FFI_TYPE_FLOAT */
491 .long .Lrcls_retdouble /* FFI_TYPE_DOUBLE */
492 .long .Lrcls_retldouble /* FFI_TYPE_LONGDOUBLE */
493 .long .Lrcls_retuint8 /* FFI_TYPE_UINT8 */
494 .long .Lrcls_retsint8 /* FFI_TYPE_SINT8 */
495 .long .Lrcls_retuint16 /* FFI_TYPE_UINT16 */
496 .long .Lrcls_retsint16 /* FFI_TYPE_SINT16 */
497 .long .Lrcls_retint /* FFI_TYPE_UINT32 */
498 .long .Lrcls_retint /* FFI_TYPE_SINT32 */
499 .long .Lrcls_retllong /* FFI_TYPE_UINT64 */
500 .long .Lrcls_retllong /* FFI_TYPE_SINT64 */
501 .long .Lrcls_retstruct /* FFI_TYPE_STRUCT */
502 .long .Lrcls_retint /* FFI_TYPE_POINTER */
503 .long .Lrcls_retstruct1 /* FFI_TYPE_SMALL_STRUCT_1B */
504 .long .Lrcls_retstruct2 /* FFI_TYPE_SMALL_STRUCT_2B */
505 .long .Lrcls_retstruct4 /* FFI_TYPE_SMALL_STRUCT_4B */
513 /* Sign/zero extend as appropriate. */
515 movsbl -24(%ebp), %eax
519 movswl -24(%ebp), %eax
523 movzbl -24(%ebp), %eax
527 movzwl -24(%ebp), %eax
552 movsbl -24(%ebp), %eax
556 movswl -24(%ebp), %eax
572 .ffi_closure_raw_SYSV_end:
575 #endif /* !FFI_NO_RAW_API */
577 # This assumes we are using gas.
579 .globl _ffi_closure_STDCALL
580 .def _ffi_closure_STDCALL; .scl 2; .type 32; .endef
581 _ffi_closure_STDCALL:
589 movl %edx, -12(%ebp) /* resp */
590 leal 12(%ebp), %edx /* account for stub return address on stack */
591 movl %edx, 4(%esp) /* args */
593 movl %edx, (%esp) /* &resp */
594 call _ffi_closure_SYSV_inner
598 # Do not insert anything here between the call and the jump table.
600 .long .Lscls_noretval /* FFI_TYPE_VOID */
601 .long .Lscls_retint /* FFI_TYPE_INT */
602 .long .Lscls_retfloat /* FFI_TYPE_FLOAT */
603 .long .Lscls_retdouble /* FFI_TYPE_DOUBLE */
604 .long .Lscls_retldouble /* FFI_TYPE_LONGDOUBLE */
605 .long .Lscls_retuint8 /* FFI_TYPE_UINT8 */
606 .long .Lscls_retsint8 /* FFI_TYPE_SINT8 */
607 .long .Lscls_retuint16 /* FFI_TYPE_UINT16 */
608 .long .Lscls_retsint16 /* FFI_TYPE_SINT16 */
609 .long .Lscls_retint /* FFI_TYPE_UINT32 */
610 .long .Lscls_retint /* FFI_TYPE_SINT32 */
611 .long .Lscls_retllong /* FFI_TYPE_UINT64 */
612 .long .Lscls_retllong /* FFI_TYPE_SINT64 */
613 .long .Lscls_retstruct /* FFI_TYPE_STRUCT */
614 .long .Lscls_retint /* FFI_TYPE_POINTER */
615 .long .Lscls_retstruct1 /* FFI_TYPE_SMALL_STRUCT_1B */
616 .long .Lscls_retstruct2 /* FFI_TYPE_SMALL_STRUCT_2B */
617 .long .Lscls_retstruct4 /* FFI_TYPE_SMALL_STRUCT_4B */
625 /* Sign/zero extend as appropriate. */
683 .ffi_closure_STDCALL_end:
686 .section .eh_frame,"w"
689 .long .LECIE1-.LASCIE1 /* Length of Common Information Entry */
691 .long 0x0 /* CIE Identifier Tag */
692 .byte 0x1 /* CIE Version */
694 .ascii "zR\0" /* CIE Augmentation */
696 .ascii "\0" /* CIE Augmentation */
698 .byte 0x1 /* .uleb128 0x1; CIE Code Alignment Factor */
699 .byte 0x7c /* .sleb128 -4; CIE Data Alignment Factor */
700 .byte 0x8 /* CIE RA Column */
702 .byte 0x1 /* .uleb128 0x1; Augmentation size */
703 .byte 0x1b /* FDE Encoding (pcrel sdata4) */
705 .byte 0xc /* DW_CFA_def_cfa CFA = r4 + 4 = 4(%esp) */
706 .byte 0x4 /* .uleb128 0x4 */
707 .byte 0x4 /* .uleb128 0x4 */
708 .byte 0x88 /* DW_CFA_offset, column 0x8 %eip at CFA + 1 * -4 */
709 .byte 0x1 /* .uleb128 0x1 */
714 .long .LEFDE1-.LASFDE1 /* FDE Length */
716 .long .LASFDE1-.Lframe1 /* FDE CIE offset */
717 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
718 .long .LFB1-. /* FDE initial location */
722 .long .LFE1-.LFB1 /* FDE address range */
724 .byte 0x0 /* .uleb128 0x0; Augmentation size */
726 /* DW_CFA_xxx CFI instructions go here. */
728 .byte 0x4 /* DW_CFA_advance_loc4 */
730 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
731 .byte 0x8 /* .uleb128 0x8 */
732 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
733 .byte 0x2 /* .uleb128 0x2 */
735 .byte 0x4 /* DW_CFA_advance_loc4 */
737 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
738 .byte 0x5 /* .uleb128 0x5 */
740 /* End of DW_CFA_xxx CFI instructions. */
746 .long .LEFDE2-.LASFDE2 /* FDE Length */
748 .long .LASFDE2-.Lframe1 /* FDE CIE offset */
749 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
750 .long .LFB2-. /* FDE initial location */
754 .long .LFE2-.LFB2 /* FDE address range */
756 .byte 0x0 /* .uleb128 0x0; Augmentation size */
758 /* DW_CFA_xxx CFI instructions go here. */
760 .byte 0x4 /* DW_CFA_advance_loc4 */
762 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
763 .byte 0x8 /* .uleb128 0x8 */
764 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
765 .byte 0x2 /* .uleb128 0x2 */
767 .byte 0x4 /* DW_CFA_advance_loc4 */
769 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
770 .byte 0x5 /* .uleb128 0x5 */
772 /* End of DW_CFA_xxx CFI instructions. */
778 .long .LEFDE3-.LASFDE3 /* FDE Length */
780 .long .LASFDE3-.Lframe1 /* FDE CIE offset */
781 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
782 .long .LFB3-. /* FDE initial location */
786 .long .LFE3-.LFB3 /* FDE address range */
788 .byte 0x0 /* .uleb128 0x0; Augmentation size */
790 /* DW_CFA_xxx CFI instructions go here. */
792 .byte 0x4 /* DW_CFA_advance_loc4 */
794 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
795 .byte 0x8 /* .uleb128 0x8 */
796 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
797 .byte 0x2 /* .uleb128 0x2 */
799 .byte 0x4 /* DW_CFA_advance_loc4 */
801 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
802 .byte 0x5 /* .uleb128 0x5 */
804 /* End of DW_CFA_xxx CFI instructions. */
811 .long .LEFDE4-.LASFDE4 /* FDE Length */
813 .long .LASFDE4-.Lframe1 /* FDE CIE offset */
814 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
815 .long .LFB4-. /* FDE initial location */
819 .long .LFE4-.LFB4 /* FDE address range */
821 .byte 0x0 /* .uleb128 0x0; Augmentation size */
823 /* DW_CFA_xxx CFI instructions go here. */
825 .byte 0x4 /* DW_CFA_advance_loc4 */
827 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
828 .byte 0x8 /* .uleb128 0x8 */
829 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
830 .byte 0x2 /* .uleb128 0x2 */
832 .byte 0x4 /* DW_CFA_advance_loc4 */
834 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
835 .byte 0x5 /* .uleb128 0x5 */
837 .byte 0x4 /* DW_CFA_advance_loc4 */
839 .byte 0x86 /* DW_CFA_offset, column 0x6 %esi at CFA + 3 * -4 */
840 .byte 0x3 /* .uleb128 0x3 */
842 /* End of DW_CFA_xxx CFI instructions. */
846 #endif /* !FFI_NO_RAW_API */
849 .long .LEFDE5-.LASFDE5 /* FDE Length */
851 .long .LASFDE5-.Lframe1 /* FDE CIE offset */
852 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
853 .long .LFB5-. /* FDE initial location */
857 .long .LFE5-.LFB5 /* FDE address range */
859 .byte 0x0 /* .uleb128 0x0; Augmentation size */
861 /* DW_CFA_xxx CFI instructions go here. */
863 .byte 0x4 /* DW_CFA_advance_loc4 */
865 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
866 .byte 0x8 /* .uleb128 0x8 */
867 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
868 .byte 0x2 /* .uleb128 0x2 */
870 .byte 0x4 /* DW_CFA_advance_loc4 */
872 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
873 .byte 0x5 /* .uleb128 0x5 */
875 /* End of DW_CFA_xxx CFI instructions. */