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, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 OTHER DEALINGS IN THE SOFTWARE.
27 ----------------------------------------------------------------------- */
30 #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 # Remove the space we pushed for the args
70 # Load %ecx with the return type code
73 # If the return value pointer is NULL, assume no return value.
77 # Even if there is no space for the return value, we are
78 # obliged to handle floating-point values.
79 cmpl $FFI_TYPE_FLOAT,%ecx
86 cmpl $FFI_TYPE_INT,%ecx
88 # Load %ecx with the pointer to storage for the return value
94 cmpl $FFI_TYPE_FLOAT,%ecx
96 # Load %ecx with the pointer to storage for the return value
102 cmpl $FFI_TYPE_DOUBLE,%ecx
104 # Load %ecx with the pointer to storage for the return value
110 cmpl $FFI_TYPE_LONGDOUBLE,%ecx
112 # Load %ecx with the pointer to storage for the return value
118 cmpl $FFI_TYPE_SINT64,%ecx
120 # Load %ecx with the pointer to storage for the return value
126 cmpl $FFI_TYPE_SINT8,%ecx
128 # Load %ecx with the pointer to storage for the return value
134 cmpl $FFI_TYPE_SINT16,%ecx
136 # Load %ecx with the pointer to storage for the return value
152 # This assumes we are using gas.
154 .globl _ffi_call_STDCALL
155 .def _ffi_call_STDCALL; .scl 2; .type 32; .endef
162 # Make room for all of the new args.
168 # Place all of the ffi_prep_args in position
173 # Return stack to previous state and call the function
176 # FIXME: Align the stack to a 128-bit boundary to avoid
177 # potential performance hits.
181 # stdcall functions pop arguments off the stack themselves
183 # Load %ecx with the return type code
186 # If the return value pointer is NULL, assume no return value.
190 # Even if there is no space for the return value, we are
191 # obliged to handle floating-point values.
192 cmpl $FFI_TYPE_FLOAT,%ecx
199 cmpl $FFI_TYPE_INT,%ecx
201 # Load %ecx with the pointer to storage for the return value
207 cmpl $FFI_TYPE_FLOAT,%ecx
209 # Load %ecx with the pointer to storage for the return value
215 cmpl $FFI_TYPE_DOUBLE,%ecx
217 # Load %ecx with the pointer to storage for the return value
223 cmpl $FFI_TYPE_LONGDOUBLE,%ecx
225 # Load %ecx with the pointer to storage for the return value
231 cmpl $FFI_TYPE_SINT64,%ecx
233 # Load %ecx with the pointer to storage for the return value
239 cmpl $FFI_TYPE_SINT8,%ecx
241 # Load %ecx with the pointer to storage for the return value
247 cmpl $FFI_TYPE_SINT16,%ecx
249 # Load %ecx with the pointer to storage for the return value
262 .ffi_call_STDCALL_end:
265 # This assumes we are using gas.
267 .globl _ffi_closure_SYSV
268 .def _ffi_closure_SYSV; .scl 2; .type 32; .endef
277 movl %edx, -12(%ebp) /* resp */
279 movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
281 movl %edx, (%esp) /* &resp */
282 call _ffi_closure_SYSV_inner
284 cmpl $FFI_TYPE_INT, %eax
286 cmpl $FFI_TYPE_FLOAT, %eax
288 cmpl $FFI_TYPE_DOUBLE, %eax
290 cmpl $FFI_TYPE_LONGDOUBLE, %eax
292 cmpl $FFI_TYPE_SINT64, %eax
294 cmpl $FFI_TYPE_SINT8, %eax /* 1-byte struct */
296 cmpl $FFI_TYPE_SINT16, %eax /* 2-bytes struct */
324 .ffi_closure_SYSV_end:
329 #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
330 #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
331 #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
332 #define CIF_FLAGS_OFFSET 20
334 # This assumes we are using gas.
336 .globl _ffi_closure_raw_SYSV
337 .def _ffi_closure_raw_SYSV; .scl 2; .type 32; .endef
338 _ffi_closure_raw_SYSV:
347 movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
348 movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
349 movl %edx, 12(%esp) /* user_data */
350 leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
351 movl %edx, 8(%esp) /* raw_args */
353 movl %edx, 4(%esp) /* &res */
354 movl %esi, (%esp) /* cif */
355 call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
356 movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
357 cmpl $FFI_TYPE_INT, %eax
359 cmpl $FFI_TYPE_FLOAT, %eax
361 cmpl $FFI_TYPE_DOUBLE, %eax
363 cmpl $FFI_TYPE_LONGDOUBLE, %eax
365 cmpl $FFI_TYPE_SINT64, %eax
388 .ffi_closure_raw_SYSV_end:
391 #endif /* !FFI_NO_RAW_API */
394 .section .eh_frame,"w"
397 .long .LECIE1-.LASCIE1 /* Length of Common Information Entry */
399 .long 0x0 /* CIE Identifier Tag */
400 .byte 0x1 /* CIE Version */
402 .ascii "zR\0" /* CIE Augmentation */
404 .ascii "\0" /* CIE Augmentation */
406 .byte 0x1 /* .uleb128 0x1; CIE Code Alignment Factor */
407 .byte 0x7c /* .sleb128 -4; CIE Data Alignment Factor */
408 .byte 0x8 /* CIE RA Column */
410 .byte 0x1 /* .uleb128 0x1; Augmentation size */
411 .byte 0x1b /* FDE Encoding (pcrel sdata4) */
413 .byte 0xc /* DW_CFA_def_cfa CFA = r4 + 4 = 4(%esp) */
414 .byte 0x4 /* .uleb128 0x4 */
415 .byte 0x4 /* .uleb128 0x4 */
416 .byte 0x88 /* DW_CFA_offset, column 0x8 %eip at CFA + 1 * -4 */
417 .byte 0x1 /* .uleb128 0x1 */
422 .long .LEFDE1-.LASFDE1 /* FDE Length */
424 .long .LASFDE1-.Lframe1 /* FDE CIE offset */
425 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
426 .long .LFB1-. /* FDE initial location */
430 .long .LFE1-.LFB1 /* FDE address range */
432 .byte 0x0 /* .uleb128 0x0; Augmentation size */
434 /* DW_CFA_xxx CFI instructions go here. */
436 .byte 0x4 /* DW_CFA_advance_loc4 */
438 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
439 .byte 0x8 /* .uleb128 0x8 */
440 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
441 .byte 0x2 /* .uleb128 0x2 */
443 .byte 0x4 /* DW_CFA_advance_loc4 */
445 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
446 .byte 0x5 /* .uleb128 0x5 */
448 /* End of DW_CFA_xxx CFI instructions. */
454 .long .LEFDE2-.LASFDE2 /* FDE Length */
456 .long .LASFDE2-.Lframe1 /* FDE CIE offset */
457 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
458 .long .LFB2-. /* FDE initial location */
462 .long .LFE2-.LFB2 /* FDE address range */
464 .byte 0x0 /* .uleb128 0x0; Augmentation size */
466 /* DW_CFA_xxx CFI instructions go here. */
468 .byte 0x4 /* DW_CFA_advance_loc4 */
470 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
471 .byte 0x8 /* .uleb128 0x8 */
472 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
473 .byte 0x2 /* .uleb128 0x2 */
475 .byte 0x4 /* DW_CFA_advance_loc4 */
477 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
478 .byte 0x5 /* .uleb128 0x5 */
480 /* End of DW_CFA_xxx CFI instructions. */
486 .long .LEFDE3-.LASFDE3 /* FDE Length */
488 .long .LASFDE3-.Lframe1 /* FDE CIE offset */
489 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
490 .long .LFB3-. /* FDE initial location */
494 .long .LFE3-.LFB3 /* FDE address range */
496 .byte 0x0 /* .uleb128 0x0; Augmentation size */
498 /* DW_CFA_xxx CFI instructions go here. */
500 .byte 0x4 /* DW_CFA_advance_loc4 */
502 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
503 .byte 0x8 /* .uleb128 0x8 */
504 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
505 .byte 0x2 /* .uleb128 0x2 */
507 .byte 0x4 /* DW_CFA_advance_loc4 */
509 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
510 .byte 0x5 /* .uleb128 0x5 */
512 /* End of DW_CFA_xxx CFI instructions. */
519 .long .LEFDE4-.LASFDE4 /* FDE Length */
521 .long .LASFDE4-.Lframe1 /* FDE CIE offset */
522 #if defined __PIC__ && defined HAVE_AS_X86_PCREL
523 .long .LFB4-. /* FDE initial location */
527 .long .LFE4-.LFB4 /* FDE address range */
529 .byte 0x0 /* .uleb128 0x0; Augmentation size */
531 /* DW_CFA_xxx CFI instructions go here. */
533 .byte 0x4 /* DW_CFA_advance_loc4 */
535 .byte 0xe /* DW_CFA_def_cfa_offset CFA = r4 + 8 = 8(%esp) */
536 .byte 0x8 /* .uleb128 0x8 */
537 .byte 0x85 /* DW_CFA_offset, column 0x5 %ebp at CFA + 2 * -4 */
538 .byte 0x2 /* .uleb128 0x2 */
540 .byte 0x4 /* DW_CFA_advance_loc4 */
542 .byte 0xd /* DW_CFA_def_cfa_register CFA = r5 = %ebp */
543 .byte 0x5 /* .uleb128 0x5 */
545 .byte 0x4 /* DW_CFA_advance_loc4 */
547 .byte 0x86 /* DW_CFA_offset, column 0x6 %esi at CFA + 3 * -4 */
548 .byte 0x3 /* .uleb128 0x3 */
550 /* End of DW_CFA_xxx CFI instructions. */
554 #endif /* !FFI_NO_RAW_API */