2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / src / arm / sysv.S
blob0e4186114a96457197e6d5bdd86c50c6e19fb392
1 /* -----------------------------------------------------------------------
2    sysv.S - Copyright (c) 1998 Red Hat, Inc.
3    
4    ARM 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 #define LIBFFI_ASM      
27 #include <fficonfig.h>
28 #include <ffi.h>
29 #ifdef HAVE_MACHINE_ASM_H
30 #include <machine/asm.h>
31 #else
32 #ifdef __USER_LABEL_PREFIX__
33 #define CONCAT1(a, b) CONCAT2(a, b)
34 #define CONCAT2(a, b) a ## b
36 /* Use the right prefix for global labels.  */
37 #define CNAME(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
38 #else
39 #define CNAME(x) x
40 #endif
41 #define ENTRY(x) .globl CNAME(x); .type CNAME(x),%function; CNAME(x):
42 #endif
43         
44 .text
46         # a1:   ffi_prep_args
47         # a2:   &ecif
48         # a3:   cif->bytes
49         # a4:   fig->flags
50         # sp+0: ecif.rvalue
51         # sp+4: fn
53         # This assumes we are using gas.
54 ENTRY(ffi_call_SYSV)
55         # Save registers
56         stmfd sp!, {a1-a4, fp, lr}
57         mov   fp, sp
59         # Make room for all of the new args.
60         sub   sp, fp, a3
62         # Place all of the ffi_prep_args in position
63         mov   ip, a1
64         mov   a1, sp
65         #     a2 already set
67         # And call
68         mov   lr, pc
69         mov   pc, ip
71         # move first 4 parameters in registers
72         ldr   a1, [sp, #0]
73         ldr   a2, [sp, #4]
74         ldr   a3, [sp, #8]
75         ldr   a4, [sp, #12]
77         # and adjust stack
78         ldr   ip, [fp, #8]
79         cmp   ip, #16
80         movge ip, #16
81         add   sp, sp, ip
83         # call function
84         mov   lr, pc
85         ldr   pc, [fp, #28]
87         # Remove the space we pushed for the args
88         mov   sp, fp
90         # Load a3 with the pointer to storage for the return value
91         ldr   a3, [sp, #24]
93         # Load a4 with the return type code 
94         ldr   a4, [sp, #12]
96         # If the return value pointer is NULL, assume no return value.
97         cmp   a3, #0
98         beq   epilogue
100 # return INT
101         cmp   a4, #FFI_TYPE_INT
102         streq a1, [a3]
103         beq   epilogue
105 # return FLOAT
106         cmp     a4, #FFI_TYPE_FLOAT
107 #ifdef __SOFTFP__
108         streq   a1, [a3]
109 #else
110         stfeqs  f0, [a3]
111 #endif
112         beq     epilogue
114 # return DOUBLE or LONGDOUBLE
115         cmp     a4, #FFI_TYPE_DOUBLE
116 #ifdef __SOFTFP__
117         stmeqia a3, {a1, a2}
118 #else
119         stfeqd  f0, [a3]
120 #endif
122 epilogue:
123         ldmfd sp!, {a1-a4, fp, pc}
125 .ffi_call_SYSV_end:
126         .size    CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)