OSDN Git Service

b3dc477fec043222df3f99260c7c30405fed6dd5
[pf3gnuchains/gcc-fork.git] / libffi / src / alpha / osf.S
1 /* -----------------------------------------------------------------------
2    osf.S - Copyright (c) 1998 Cygnus Solutions
3    
4    Alpha/OSF Foreign Function Interface 
5
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:
13
14    The above copyright notice and this permission notice shall be included
15    in all copies or substantial portions of the Software.
16
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    ----------------------------------------------------------------------- */
25
26 #define LIBFFI_ASM      
27 #include <ffi.h>
28
29         .arch ev6
30         .text
31
32 /* ffi_call_osf (void *args, unsigned long bytes, unsigned flags,
33                  void *raddr, void (*fnaddr)());
34
35    Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
36    for this function.  This has been allocated by ffi_call.  We also
37    deallocate some of the stack that has been alloca'd.  */
38
39         .align  3
40         .globl  ffi_call_osf
41         .ent    ffi_call_osf
42 ffi_call_osf:
43         .frame  $15, 32, $26, 0
44         .mask   0x4008000, -32
45         addq    $16,$17,$1
46         mov     $16, $30
47         stq     $26, 0($1)
48         stq     $15, 8($1)
49         stq     $18, 16($1)
50         mov     $1, $15
51         .prologue 0
52
53         stq     $19, 24($1)
54         mov     $20, $27
55
56         # Load up all of the (potential) argument registers.
57         ldq     $16, 0($30)
58         ldt     $f16, 0($30)
59         ldt     $f17, 8($30)
60         ldq     $17, 8($30)
61         ldt     $f18, 16($30)
62         ldq     $18, 16($30)
63         ldt     $f19, 24($30)
64         ldq     $19, 24($30)
65         ldt     $f20, 32($30)
66         ldq     $20, 32($30)
67         ldt     $f21, 40($30)
68         ldq     $21, 40($30)
69
70         # Deallocate the register argument area.
71         lda     $30, 48($30)
72
73         jsr     $26, ($27), 0
74         ldgp    $29, 0($26)
75
76         # If the return value pointer is NULL, assume no return value.
77         ldq     $19, 24($15)
78         ldq     $18, 16($15)
79         ldq     $26, 0($15)
80         beq     $19, $noretval
81
82         # Store the return value out in the proper type.
83         cmpeq   $18, FFI_TYPE_INT, $1
84         bne     $1, $retint
85         cmpeq   $18, FFI_TYPE_FLOAT, $2
86         bne     $2, $retfloat
87         cmpeq   $18, FFI_TYPE_DOUBLE, $3
88         bne     $3, $retdouble
89
90 $noretval:
91         ldq     $15, 8($15)
92         ret
93
94 $retint:
95         stq     $0, 0($19)
96         nop
97         ldq     $15, 8($15)
98         ret
99
100 $retfloat:
101         sts     $f0, 0($19)
102         nop
103         ldq     $15, 8($15)
104         ret
105
106 $retdouble:
107         stt     $f0, 0($19)
108         nop
109         ldq     $15, 8($15)
110         ret
111
112         .end    ffi_call_osf
113
114 /* ffi_closure_osf(...)
115
116    Receives the closure argument in $1.   */
117
118         .align  3
119         .globl  ffi_closure_osf
120         .ent    ffi_closure_osf
121 ffi_closure_osf:
122         .frame  $30, 16*8, $26, 0
123         .mask   0x4000000, -16*8
124         ldgp    $29, 0($27)
125         subq    $30, 16*8, $30
126         stq     $26, 0($30)
127         .prologue 1
128
129         # Store all of the potential argument registers in va_list format.
130         stt     $f16, 4*8($30)
131         stt     $f17, 5*8($30)
132         stt     $f18, 6*8($30)
133         stt     $f19, 7*8($30)
134         stt     $f20, 8*8($30)
135         stt     $f21, 9*8($30)
136         stq     $16, 10*8($30)
137         stq     $17, 11*8($30)
138         stq     $18, 12*8($30)
139         stq     $19, 13*8($30)
140         stq     $20, 14*8($30)
141         stq     $21, 15*8($30)
142
143         # Call ffi_closure_osf_inner to do the bulk of the work.
144         mov     $1, $16
145         lda     $17, 2*8($30)
146         lda     $18, 10*8($30)
147         jsr     $26, ffi_closure_osf_inner
148         ldgp    $29, 0($26)
149         ldq     $26, 0($30)
150
151         # Load up the return value in the proper type.
152         lda     $1, $load_table
153         s4addq  $0, $1, $1
154         ldl     $1, 0($1)
155         addq    $1, $29, $1
156         jmp     $31, ($1), $load_32
157
158         .align 4
159 $load_none:
160         addq    $30, 16*8, $30
161         ret
162
163         .align 4
164 $load_float:
165         lds     $f0, 16($30)
166         nop
167         addq    $30, 16*8, $30
168         ret
169
170         .align 4
171 $load_double:
172         ldt     $f0, 16($30)
173         nop
174         addq    $30, 16*8, $30
175         ret
176
177         .align 4
178 $load_u8:
179 #ifdef __alpha_bwx__
180         ldbu    $0, 16($30)
181         nop
182 #else
183         ldq     $0, 16($30)
184         and     $0, 255, $0
185 #endif
186         addq    $30, 16*8, $30
187         ret
188
189         .align 4
190 $load_s8:
191 #ifdef __alpha_bwx__
192         ldbu    $0, 16($30)
193         sextb   $0, $0
194 #else
195         ldq     $0, 16($30)
196         sll     $0, 56, $0
197         sra     $0, 56, $0
198 #endif
199         addq    $30, 16*8, $30
200         ret
201
202         .align 4
203 $load_u16:
204 #ifdef __alpha_bwx__
205         ldwu    $0, 16($30)
206         nop
207 #else
208         ldq     $0, 16($30)
209         zapnot  $0, 3, $0
210 #endif
211         addq    $30, 16*8, $30
212         ret
213
214         .align 4
215 $load_s16:
216 #ifdef __alpha_bwx__
217         ldwu    $0, 16($30)
218         sextw   $0, $0
219 #else
220         ldq     $0, 16($30)
221         sll     $0, 48, $0
222         sra     $0, 48, $0
223 #endif
224         addq    $30, 16*8, $30
225         ret
226
227         .align 4
228 $load_32:
229         ldl     $0, 16($30)
230         nop
231         addq    $30, 16*8, $30
232         ret
233
234         .align 4
235 $load_64:
236         ldq     $0, 16($30)
237         nop
238         addq    $30, 16*8, $30
239         ret
240
241         .end    ffi_closure_osf
242
243 .section .rodata
244 $load_table:
245         .gprel32 $load_none     # FFI_TYPE_VOID
246         .gprel32 $load_32       # FFI_TYPE_INT
247         .gprel32 $load_float    # FFI_TYPE_FLOAT
248         .gprel32 $load_double   # FFI_TYPE_DOUBLE
249         .gprel32 $load_double   # FFI_TYPE_LONGDOUBLE
250         .gprel32 $load_u8       # FFI_TYPE_UINT8
251         .gprel32 $load_s8       # FFI_TYPE_SINT8
252         .gprel32 $load_u16      # FFI_TYPE_UINT16
253         .gprel32 $load_s16      # FFI_TYPE_SINT16
254         .gprel32 $load_32       # FFI_TYPE_UINT32
255         .gprel32 $load_32       # FFI_TYPE_SINT32
256         .gprel32 $load_64       # FFI_TYPE_UINT64
257         .gprel32 $load_64       # FFI_TYPE_SINT64
258         .gprel32 $load_none     # FFI_TYPE_STRUCT
259         .gprel32 $load_64       # FFI_TYPE_POINTER
260
261 /* Assert that the table above is in sync with ffi.h.  */
262
263 #if        FFI_TYPE_FLOAT != 2          \
264         || FFI_TYPE_DOUBLE != 3         \
265         || FFI_TYPE_UINT8 != 5          \
266         || FFI_TYPE_SINT8 != 6          \
267         || FFI_TYPE_UINT16 != 7         \
268         || FFI_TYPE_SINT16 != 8         \
269         || FFI_TYPE_UINT32 != 9         \
270         || FFI_TYPE_SINT32 != 10        \
271         || FFI_TYPE_UINT64 != 11        \
272         || FFI_TYPE_SINT64 != 12        \
273         || FFI_TYPE_STRUCT != 13        \
274         || FFI_TYPE_POINTER != 14       \
275         || FFI_TYPE_LAST != 14
276 #error "osf.S out of sync with ffi.h"
277 #endif