2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / src / x86 / sysv.S
blob53a4c2b7e98612ed3ced8d17ab3b915d42a6f53a
1 /* -----------------------------------------------------------------------
2    sysv.S - Copyright (c) 1996, 1998, 2001, 2002, 2003  Red Hat, Inc.
3    
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, EXPRESS
18    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20    IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23    OTHER DEALINGS IN THE SOFTWARE.
24    ----------------------------------------------------------------------- */
26 #ifndef __x86_64__
28 #define LIBFFI_ASM      
29 #include <fficonfig.h>
30 #include <ffi.h>
32 .text
34 .globl ffi_prep_args
36         .align 4
37 .globl ffi_call_SYSV
38         .type    ffi_call_SYSV,@function
40 ffi_call_SYSV:
41 .LFB1:
42         pushl %ebp
43 .LCFI0:
44         movl  %esp,%ebp
45 .LCFI1:
46         /* Make room for all of the new args.  */
47         movl  16(%ebp),%ecx
48         subl  %ecx,%esp
50         movl  %esp,%eax
52         /* Place all of the ffi_prep_args in position  */
53         pushl 12(%ebp)
54         pushl %eax
55         call  *8(%ebp)
57         /* Return stack to previous state and call the function  */
58         addl  $8,%esp   
60         call  *28(%ebp)
62         /* Remove the space we pushed for the args  */
63         movl  16(%ebp),%ecx
64         addl  %ecx,%esp
66         /* Load %ecx with the return type code  */
67         movl  20(%ebp),%ecx     
69         /* If the return value pointer is NULL, assume no return value.  */
70         cmpl  $0,24(%ebp)
71         jne   retint
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
76         jne   noretval
77         fstp  %st(0)
79         jmp   epilogue
81 retint:
82         cmpl  $FFI_TYPE_INT,%ecx
83         jne   retfloat
84         /* Load %ecx with the pointer to storage for the return value  */
85         movl  24(%ebp),%ecx     
86         movl  %eax,0(%ecx)
87         jmp   epilogue
89 retfloat:
90         cmpl  $FFI_TYPE_FLOAT,%ecx
91         jne   retdouble
92         /* Load %ecx with the pointer to storage for the return value  */
93         movl  24(%ebp),%ecx     
94         fstps (%ecx)
95         jmp   epilogue
97 retdouble:
98         cmpl  $FFI_TYPE_DOUBLE,%ecx
99         jne   retlongdouble
100         /* Load %ecx with the pointer to storage for the return value  */
101         movl  24(%ebp),%ecx     
102         fstpl (%ecx)
103         jmp   epilogue
105 retlongdouble:
106         cmpl  $FFI_TYPE_LONGDOUBLE,%ecx
107         jne   retint64
108         /* Load %ecx with the pointer to storage for the return value  */
109         movl  24(%ebp),%ecx     
110         fstpt (%ecx)
111         jmp   epilogue
112         
113 retint64:       
114         cmpl  $FFI_TYPE_SINT64,%ecx
115         jne   retstruct
116         /* Load %ecx with the pointer to storage for the return value  */
117         movl  24(%ebp),%ecx     
118         movl  %eax,0(%ecx)
119         movl  %edx,4(%ecx)
120         
121 retstruct:
122         /* Nothing to do!  */
124 noretval:
125 epilogue:
126         movl %ebp,%esp
127         popl %ebp
128         ret
129 .LFE1:
130 .ffi_call_SYSV_end:
131         .size    ffi_call_SYSV,.ffi_call_SYSV_end-ffi_call_SYSV
133         .section        .eh_frame,EH_FRAME_FLAGS,@progbits
134 .Lframe1:
135         .long   .LECIE1-.LSCIE1 /* Length of Common Information Entry */
136 .LSCIE1:
137         .long   0x0     /* CIE Identifier Tag */
138         .byte   0x1     /* CIE Version */
139 #ifdef __PIC__
140         .ascii "zR\0"   /* CIE Augmentation */
141 #else
142         .ascii "\0"     /* CIE Augmentation */
143 #endif
144         .byte   0x1     /* .uleb128 0x1; CIE Code Alignment Factor */
145         .byte   0x7c    /* .sleb128 -4; CIE Data Alignment Factor */
146         .byte   0x8     /* CIE RA Column */
147 #ifdef __PIC__
148         .byte   0x1     /* .uleb128 0x1; Augmentation size */
149         .byte   0x1b    /* FDE Encoding (pcrel sdata4) */
150 #endif
151         .byte   0xc     /* DW_CFA_def_cfa */
152         .byte   0x4     /* .uleb128 0x4 */
153         .byte   0x4     /* .uleb128 0x4 */
154         .byte   0x88    /* DW_CFA_offset, column 0x8 */
155         .byte   0x1     /* .uleb128 0x1 */
156         .align 4
157 .LECIE1:
158 .LSFDE1:
159         .long   .LEFDE1-.LASFDE1        /* FDE Length */
160 .LASFDE1:
161         .long   .LASFDE1-.Lframe1       /* FDE CIE offset */
162 #ifdef __PIC__
163         .long   .LFB1-. /* FDE initial location */
164 #else
165         .long   .LFB1   /* FDE initial location */
166 #endif
167         .long   .LFE1-.LFB1     /* FDE address range */
168 #ifdef __PIC__
169         .byte   0x0     /* .uleb128 0x0; Augmentation size */
170 #endif
171         .byte   0x4     /* DW_CFA_advance_loc4 */
172         .long   .LCFI0-.LFB1
173         .byte   0xe     /* DW_CFA_def_cfa_offset */
174         .byte   0x8     /* .uleb128 0x8 */
175         .byte   0x85    /* DW_CFA_offset, column 0x5 */
176         .byte   0x2     /* .uleb128 0x2 */
177         .byte   0x4     /* DW_CFA_advance_loc4 */
178         .long   .LCFI1-.LCFI0
179         .byte   0xd     /* DW_CFA_def_cfa_register */
180         .byte   0x5     /* .uleb128 0x5 */
181         .align 4
182 .LEFDE1:
184 #endif /* ifndef __x86_64__ */