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>
39 # This assumes we are using gas.
42 .def _ffi_call_SYSV; .scl 2; .type 32; .endef
49 # Make room for all of the new args.
55 # Place all of the ffi_prep_args in position
60 # Return stack to previous state and call the function
63 # FIXME: Align the stack to a 128-bit boundary to avoid
64 # potential performance hits.
68 # Remove the space we pushed for the args
72 # Load %ecx with the return type code
75 # If the return value pointer is NULL, assume no return value.
79 # Even if there is no space for the return value, we are
80 # obliged to handle floating-point values.
81 cmpl $FFI_TYPE_FLOAT,%ecx
88 cmpl $FFI_TYPE_INT,%ecx
90 # Load %ecx with the pointer to storage for the return value
96 cmpl $FFI_TYPE_FLOAT,%ecx
98 # Load %ecx with the pointer to storage for the return value
104 cmpl $FFI_TYPE_DOUBLE,%ecx
106 # Load %ecx with the pointer to storage for the return value
112 cmpl $FFI_TYPE_LONGDOUBLE,%ecx
114 # Load %ecx with the pointer to storage for the return value
120 cmpl $FFI_TYPE_SINT64,%ecx
122 # Load %ecx with the pointer to storage for the return value
128 cmpl $FFI_TYPE_SINT8,%ecx
130 # Load %ecx with the pointer to storage for the return value
136 cmpl $FFI_TYPE_SINT16,%ecx
138 # Load %ecx with the pointer to storage for the return value
154 # This assumes we are using gas.
156 .globl _ffi_call_STDCALL
157 .def _ffi_call_STDCALL; .scl 2; .type 32; .endef
164 # Make room for all of the new args.
170 # Place all of the ffi_prep_args in position
175 # Return stack to previous state and call the function
178 # FIXME: Align the stack to a 128-bit boundary to avoid
179 # potential performance hits.
183 # stdcall functions pop arguments off the stack themselves
185 # Load %ecx with the return type code
188 # If the return value pointer is NULL, assume no return value.
192 # Even if there is no space for the return value, we are
193 # obliged to handle floating-point values.
194 cmpl $FFI_TYPE_FLOAT,%ecx
201 cmpl $FFI_TYPE_INT,%ecx
203 # Load %ecx with the pointer to storage for the return value
209 cmpl $FFI_TYPE_FLOAT,%ecx
211 # Load %ecx with the pointer to storage for the return value
217 cmpl $FFI_TYPE_DOUBLE,%ecx
219 # Load %ecx with the pointer to storage for the return value
225 cmpl $FFI_TYPE_LONGDOUBLE,%ecx
227 # Load %ecx with the pointer to storage for the return value
233 cmpl $FFI_TYPE_SINT64,%ecx
235 # Load %ecx with the pointer to storage for the return value
241 cmpl $FFI_TYPE_SINT8,%ecx
243 # Load %ecx with the pointer to storage for the return value
249 cmpl $FFI_TYPE_SINT16,%ecx
251 # Load %ecx with the pointer to storage for the return value
264 .ffi_call_STDCALL_end:
267 # This assumes we are using gas.
269 .globl _ffi_closure_SYSV
270 .def _ffi_closure_SYSV; .scl 2; .type 32; .endef
279 movl %edx, -12(%ebp) /* resp */
281 movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
283 movl %edx, (%esp) /* &resp */
284 call _ffi_closure_SYSV_inner
286 cmpl $FFI_TYPE_INT, %eax
288 cmpl $FFI_TYPE_FLOAT, %eax
290 cmpl $FFI_TYPE_DOUBLE, %eax
292 cmpl $FFI_TYPE_LONGDOUBLE, %eax
294 cmpl $FFI_TYPE_SINT64, %eax
296 cmpl $FFI_TYPE_SINT8, %eax /* 1-byte struct */
298 cmpl $FFI_TYPE_SINT16, %eax /* 2-bytes struct */
326 .ffi_closure_SYSV_end:
331 #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
332 #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
333 #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
334 #define CIF_FLAGS_OFFSET 20
336 # This assumes we are using gas.
338 .globl _ffi_closure_raw_SYSV
339 .def _ffi_closure_raw_SYSV; .scl 2; .type 32; .endef
340 _ffi_closure_raw_SYSV:
349 movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
350 movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
351 movl %edx, 12(%esp) /* user_data */
352 leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
353 movl %edx, 8(%esp) /* raw_args */
355 movl %edx, 4(%esp) /* &res */
356 movl %esi, (%esp) /* cif */
357 call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
358 movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
359 cmpl $FFI_TYPE_INT, %eax
361 cmpl $FFI_TYPE_FLOAT, %eax
363 cmpl $FFI_TYPE_DOUBLE, %eax
365 cmpl $FFI_TYPE_LONGDOUBLE, %eax
367 cmpl $FFI_TYPE_SINT64, %eax
390 .ffi_closure_raw_SYSV_end:
393 #endif /* !FFI_NO_RAW_API */
395 # This assumes we are using gas.
397 .globl _ffi_closure_STDCALL
398 .def _ffi_closure_STDCALL; .scl 2; .type 32; .endef
399 _ffi_closure_STDCALL:
407 movl %edx, -12(%ebp) /* resp */
408 leal 12(%ebp), %edx /* account for stub return address on stack */
409 movl %edx, 4(%esp) /* args */
411 movl %edx, (%esp) /* &resp */
412 call _ffi_closure_SYSV_inner
414 /* It would be nice to just share this code with the
415 duplicate sequence in _ffi_closure_SYSV, if only
416 there were some way to represent that in the EH info. */
417 cmpl $FFI_TYPE_INT, %eax
419 cmpl $FFI_TYPE_FLOAT, %eax
421 cmpl $FFI_TYPE_DOUBLE, %eax
423 cmpl $FFI_TYPE_LONGDOUBLE, %eax
425 cmpl $FFI_TYPE_SINT64, %eax
427 cmpl $FFI_TYPE_SINT8, %eax /* 1-byte struct */
429 cmpl $FFI_TYPE_SINT16, %eax /* 2-bytes struct */
457 .ffi_closure_STDCALL_end:
460 .section .eh_frame,"w"
463 .long .LECIE1-.LASCIE1 /* Length of Common Information Entry */
465 .long 0x0 /* CIE Identifier Tag */
466 .byte 0x1 /* CIE Version */
468 .ascii "zR\0" /* CIE Augmentation */
470 .ascii "\0" /* CIE Augmentation */
472 .byte 0x1 /* .uleb128 0x1; CIE Code Alignment Factor */
473 .byte 0x7c /* .sleb128 -4; CIE Data Alignment Factor */
474 .byte 0x8 /* CIE RA Column */
476 .byte 0x1 /* .uleb128 0x1; Augmentation size */
477 .byte 0x1b /* FDE Encoding (pcrel sdata4) */
479 .byte 0xc /* DW_CFA_def_cfa CFA = r4 + 4 = 4(%esp) */
480 .byte 0x4 /* .uleb128 0x4 */
481 .byte 0x4 /* .uleb128 0x4 */
482 .byte 0x88 /* DW_CFA_offset, column 0x8 %eip at CFA + 1 * -4 */
483 .byte 0x1 /* .uleb128 0x1 */
488 .long .LEFDE1-.LASFDE1 /* FDE Length */
490 .long .LASFDE1-.Lframe1 /* FDE CIE offset */
491 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
492 .long .LFB1-. /* FDE initial location */
496 .long .LFE1-.LFB1 /* FDE address range */
498 .byte 0x0 /* .uleb128 0x0; Augmentation size */
500 /* DW_CFA_xxx CFI instructions go here. */
502 .byte 0x4 /* DW_CFA_advance_loc4 */
504 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
505 .byte 0x8 /* .uleb128 0x8 */
506 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
507 .byte 0x2 /* .uleb128 0x2 */
509 .byte 0x4 /* DW_CFA_advance_loc4 */
511 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
512 .byte 0x5 /* .uleb128 0x5 */
514 /* End of DW_CFA_xxx CFI instructions. */
520 .long .LEFDE2-.LASFDE2 /* FDE Length */
522 .long .LASFDE2-.Lframe1 /* FDE CIE offset */
523 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
524 .long .LFB2-. /* FDE initial location */
528 .long .LFE2-.LFB2 /* FDE address range */
530 .byte 0x0 /* .uleb128 0x0; Augmentation size */
532 /* DW_CFA_xxx CFI instructions go here. */
534 .byte 0x4 /* DW_CFA_advance_loc4 */
536 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
537 .byte 0x8 /* .uleb128 0x8 */
538 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
539 .byte 0x2 /* .uleb128 0x2 */
541 .byte 0x4 /* DW_CFA_advance_loc4 */
543 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
544 .byte 0x5 /* .uleb128 0x5 */
546 /* End of DW_CFA_xxx CFI instructions. */
552 .long .LEFDE3-.LASFDE3 /* FDE Length */
554 .long .LASFDE3-.Lframe1 /* FDE CIE offset */
555 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
556 .long .LFB3-. /* FDE initial location */
560 .long .LFE3-.LFB3 /* FDE address range */
562 .byte 0x0 /* .uleb128 0x0; Augmentation size */
564 /* DW_CFA_xxx CFI instructions go here. */
566 .byte 0x4 /* DW_CFA_advance_loc4 */
568 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
569 .byte 0x8 /* .uleb128 0x8 */
570 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
571 .byte 0x2 /* .uleb128 0x2 */
573 .byte 0x4 /* DW_CFA_advance_loc4 */
575 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
576 .byte 0x5 /* .uleb128 0x5 */
578 /* End of DW_CFA_xxx CFI instructions. */
585 .long .LEFDE4-.LASFDE4 /* FDE Length */
587 .long .LASFDE4-.Lframe1 /* FDE CIE offset */
588 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
589 .long .LFB4-. /* FDE initial location */
593 .long .LFE4-.LFB4 /* FDE address range */
595 .byte 0x0 /* .uleb128 0x0; Augmentation size */
597 /* DW_CFA_xxx CFI instructions go here. */
599 .byte 0x4 /* DW_CFA_advance_loc4 */
601 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
602 .byte 0x8 /* .uleb128 0x8 */
603 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
604 .byte 0x2 /* .uleb128 0x2 */
606 .byte 0x4 /* DW_CFA_advance_loc4 */
608 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
609 .byte 0x5 /* .uleb128 0x5 */
611 .byte 0x4 /* DW_CFA_advance_loc4 */
613 .byte 0x86 /* DW_CFA_offset, column 0x6 %esi at CFA + 3 * -4 */
614 .byte 0x3 /* .uleb128 0x3 */
616 /* End of DW_CFA_xxx CFI instructions. */
620 #endif /* !FFI_NO_RAW_API */
623 .long .LEFDE5-.LASFDE5 /* FDE Length */
625 .long .LASFDE5-.Lframe1 /* FDE CIE offset */
626 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
627 .long .LFB5-. /* FDE initial location */
631 .long .LFE5-.LFB5 /* FDE address range */
633 .byte 0x0 /* .uleb128 0x0; Augmentation size */
635 /* DW_CFA_xxx CFI instructions go here. */
637 .byte 0x4 /* DW_CFA_advance_loc4 */
639 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
640 .byte 0x8 /* .uleb128 0x8 */
641 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
642 .byte 0x2 /* .uleb128 0x2 */
644 .byte 0x4 /* DW_CFA_advance_loc4 */
646 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
647 .byte 0x5 /* .uleb128 0x5 */
649 /* End of DW_CFA_xxx CFI instructions. */