1 /* -----------------------------------------------------------------------
2 sysv.S - Copyright (c) 2002, 2003, 2004, 2006, 2008 Kaz Kojima
4 SuperH 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 ----------------------------------------------------------------------- */
28 #include <fficonfig.h>
30 #ifdef HAVE_MACHINE_ASM_H
31 #include <machine/asm.h>
33 /* XXX these lose for some platforms, I'm sure. */
35 #define ENTRY(x) .globl CNAME(x); .type CNAME(x),%function; CNAME(x):
38 #if defined(__HITACHI__)
39 #define STRUCT_VALUE_ADDRESS_WITH_ARG 1
41 #define STRUCT_VALUE_ADDRESS_WITH_ARG 0
53 # This assumes we are using gas.
89 mov #FFI_TYPE_STRUCT,r2
92 #if STRUCT_VALUE_ADDRESS_WITH_ARG
112 cmp/eq #FFI_TYPE_DOUBLE,r0
139 #ifdef __LITTLE_ENDIAN__
168 cmp/eq #FFI_TYPE_FLOAT,r0
188 #ifdef __LITTLE_ENDIAN__
225 cmp/eq #FFI_TYPE_INT,r0
256 #if (! STRUCT_VALUE_ADDRESS_WITH_ARG)
264 mov #FFI_TYPE_DOUBLE,r2
269 #ifdef __LITTLE_ENDIAN__
282 mov #FFI_TYPE_SINT64,r2
285 mov #FFI_TYPE_UINT64,r2
296 mov #FFI_TYPE_FLOAT,r2
314 # Remove the space we pushed for the args
342 mov #FFI_TYPE_STRUCT,r2
345 #if STRUCT_VALUE_ADDRESS_WITH_ARG
364 cmp/eq #FFI_TYPE_DOUBLE,r0
405 cmp/eq #FFI_TYPE_INT,r0
436 #if (! STRUCT_VALUE_ADDRESS_WITH_ARG)
444 mov #FFI_TYPE_DOUBLE,r2
454 mov #FFI_TYPE_SINT64,r2
457 mov #FFI_TYPE_UINT64,r2
468 mov #FFI_TYPE_FLOAT,r2
480 # Remove the space we pushed for the args
493 .size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)
495 .globl ffi_closure_helper_SYSV
497 ENTRY(ffi_closure_SYSV)
512 xx bytes (on stack parameters)
513 16 bytes (register parameters)
514 4 bytes (saved frame pointer)
515 4 bytes (saved return address)
516 32 bytes (floating register parameters, SH-4 only)
535 #ifdef __LITTLE_ENDIAN__
601 .long _GLOBAL_OFFSET_TABLE_
603 .long ffi_closure_helper_SYSV@GOTOFF
606 .long ffi_closure_helper_SYSV
609 .short L_case_v - 0b /* FFI_TYPE_VOID */
610 .short L_case_i - 0b /* FFI_TYPE_INT */
612 .short L_case_f - 0b /* FFI_TYPE_FLOAT */
613 .short L_case_d - 0b /* FFI_TYPE_DOUBLE */
614 .short L_case_d - 0b /* FFI_TYPE_LONGDOUBLE */
616 .short L_case_i - 0b /* FFI_TYPE_FLOAT */
617 .short L_case_ll - 0b /* FFI_TYPE_DOUBLE */
618 .short L_case_ll - 0b /* FFI_TYPE_LONGDOUBLE */
620 .short L_case_uq - 0b /* FFI_TYPE_UINT8 */
621 .short L_case_q - 0b /* FFI_TYPE_SINT8 */
622 .short L_case_uh - 0b /* FFI_TYPE_UINT16 */
623 .short L_case_h - 0b /* FFI_TYPE_SINT16 */
624 .short L_case_i - 0b /* FFI_TYPE_UINT32 */
625 .short L_case_i - 0b /* FFI_TYPE_SINT32 */
626 .short L_case_ll - 0b /* FFI_TYPE_UINT64 */
627 .short L_case_ll - 0b /* FFI_TYPE_SINT64 */
628 .short L_case_v - 0b /* FFI_TYPE_STRUCT */
629 .short L_case_i - 0b /* FFI_TYPE_POINTER */
633 #ifdef __LITTLE_ENDIAN__
658 #ifdef __LITTLE_ENDIAN__
666 #ifdef __LITTLE_ENDIAN__
675 #ifdef __LITTLE_ENDIAN__
683 #ifdef __LITTLE_ENDIAN__
702 .ffi_closure_SYSV_end:
703 .size CNAME(ffi_closure_SYSV),.ffi_closure_SYSV_end-CNAME(ffi_closure_SYSV)
705 #if defined __ELF__ && defined __linux__
706 .section .note.GNU-stack,"",@progbits
709 .section ".eh_frame","aw",@progbits
711 .4byte .LECIE1-.LSCIE1 /* Length of Common Information Entry */
713 .4byte 0x0 /* CIE Identifier Tag */
714 .byte 0x1 /* CIE Version */
716 .ascii "zR\0" /* CIE Augmentation */
718 .byte 0x0 /* CIE Augmentation */
720 .byte 0x1 /* uleb128 0x1; CIE Code Alignment Factor */
721 .byte 0x7c /* sleb128 -4; CIE Data Alignment Factor */
722 .byte 0x11 /* CIE RA Column */
724 .uleb128 0x1 /* Augmentation size */
725 .byte 0x10 /* FDE Encoding (pcrel) */
727 .byte 0xc /* DW_CFA_def_cfa */
728 .byte 0xf /* uleb128 0xf */
729 .byte 0x0 /* uleb128 0x0 */
733 .4byte .LEFDE1-.LASFDE1 /* FDE Length */
735 .4byte .LASFDE1-__FRAME_BEGIN__ /* FDE CIE offset */
737 .4byte .LFB1-. /* FDE initial location */
739 .4byte .LFB1 /* FDE initial location */
741 .4byte .LFE1-.LFB1 /* FDE address range */
743 .uleb128 0x0 /* Augmentation size */
745 .byte 0x4 /* DW_CFA_advance_loc4 */
747 .byte 0xe /* DW_CFA_def_cfa_offset */
748 .byte 0x4 /* uleb128 0x4 */
749 .byte 0x4 /* DW_CFA_advance_loc4 */
751 .byte 0xe /* DW_CFA_def_cfa_offset */
752 .byte 0x8 /* uleb128 0x4 */
753 .byte 0x4 /* DW_CFA_advance_loc4 */
755 .byte 0xe /* DW_CFA_def_cfa_offset */
756 .byte 0xc /* uleb128 0x4 */
757 .byte 0x4 /* DW_CFA_advance_loc4 */
759 .byte 0xe /* DW_CFA_def_cfa_offset */
760 .byte 0x10 /* uleb128 0x4 */
761 .byte 0x4 /* DW_CFA_advance_loc4 */
763 .byte 0xe /* DW_CFA_def_cfa_offset */
764 .byte 0x14 /* uleb128 0x4 */
765 .byte 0x4 /* DW_CFA_advance_loc4 */
767 .byte 0xe /* DW_CFA_def_cfa_offset */
768 .byte 0x18 /* uleb128 0x4 */
769 .byte 0x91 /* DW_CFA_offset, column 0x11 */
770 .byte 0x6 /* uleb128 0x6 */
771 .byte 0x8e /* DW_CFA_offset, column 0xe */
772 .byte 0x5 /* uleb128 0x5 */
773 .byte 0x8c /* DW_CFA_offset, column 0xc */
774 .byte 0x4 /* uleb128 0x4 */
775 .byte 0x8a /* DW_CFA_offset, column 0xa */
776 .byte 0x3 /* uleb128 0x3 */
777 .byte 0x89 /* DW_CFA_offset, column 0x9 */
778 .byte 0x2 /* uleb128 0x2 */
779 .byte 0x88 /* DW_CFA_offset, column 0x8 */
780 .byte 0x1 /* uleb128 0x1 */
781 .byte 0x4 /* DW_CFA_advance_loc4 */
783 .byte 0xd /* DW_CFA_def_cfa_register */
784 .byte 0xe /* uleb128 0xe */
789 .4byte .LEFDE3-.LASFDE3 /* FDE Length */
791 .4byte .LASFDE3-__FRAME_BEGIN__ /* FDE CIE offset */
793 .4byte .LFB2-. /* FDE initial location */
795 .4byte .LFB2 /* FDE initial location */
797 .4byte .LFE2-.LFB2 /* FDE address range */
799 .uleb128 0x0 /* Augmentation size */
801 .byte 0x4 /* DW_CFA_advance_loc4 */
803 .byte 0xe /* DW_CFA_def_cfa_offset */
804 .byte 0x4 /* uleb128 0x4 */
805 .byte 0x4 /* DW_CFA_advance_loc4 */
807 .byte 0xe /* DW_CFA_def_cfa_offset */
808 .byte 0x8 /* uleb128 0x4 */
809 .byte 0x4 /* DW_CFA_advance_loc4 */
811 .byte 0xe /* DW_CFA_def_cfa_offset */
812 .byte 0xc /* uleb128 0x4 */
813 .byte 0x4 /* DW_CFA_advance_loc4 */
815 .byte 0xe /* DW_CFA_def_cfa_offset */
816 .byte 0x10 /* uleb128 0x4 */
817 .byte 0x4 /* DW_CFA_advance_loc4 */
819 .byte 0xe /* DW_CFA_def_cfa_offset */
820 .byte 0x14 /* uleb128 0x4 */
821 .byte 0x4 /* DW_CFA_advance_loc4 */
823 .byte 0xe /* DW_CFA_def_cfa_offset */
824 .byte 0x18 /* uleb128 0x4 */
825 .byte 0x4 /* DW_CFA_advance_loc4 */
827 .byte 0xe /* DW_CFA_def_cfa_offset */
829 .byte 24+48 /* uleb128 24+48 */
831 .byte 24+16 /* uleb128 24+16 */
833 .byte 0x91 /* DW_CFA_offset, column 0x11 */
834 .byte 0x6 /* uleb128 0x6 */
835 .byte 0x8e /* DW_CFA_offset, column 0xe */
836 .byte 0x5 /* uleb128 0x5 */
837 .byte 0x84 /* DW_CFA_offset, column 0x4 */
838 .byte 0x4 /* uleb128 0x4 */
839 .byte 0x85 /* DW_CFA_offset, column 0x5 */
840 .byte 0x3 /* uleb128 0x3 */
841 .byte 0x86 /* DW_CFA_offset, column 0x6 */
842 .byte 0x2 /* uleb128 0x2 */
843 .byte 0x87 /* DW_CFA_offset, column 0x7 */
844 .byte 0x1 /* uleb128 0x1 */
845 .byte 0x4 /* DW_CFA_advance_loc4 */
847 .byte 0xd /* DW_CFA_def_cfa_register */
848 .byte 0xe /* uleb128 0xe */