]> git.ipfire.org Git - thirdparty/gcc.git/blame - libffi/src/sparc/v9.S
Port to sparc 32 and 64 Linux.
[thirdparty/gcc.git] / libffi / src / sparc / v9.S
CommitLineData
3791773c
JJ
1/* -----------------------------------------------------------------------
2 v9.S - Copyright (c) 2000 Cygnus Solutions
3
4 Sparc 64bit Foreign Function Interface
5
6 $Id:$
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 ``Software''), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice shall be included
17 in all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 OTHER DEALINGS IN THE SOFTWARE.
26 ----------------------------------------------------------------------- */
27
28#define LIBFFI_ASM
29#include <ffi.h>
30
31#ifdef SPARC64
32/* Only compile this in for 64bit builds, because otherwise the object file
33 will have inproper architecture due to used instructions. */
34
35#define STACKFRAME 128 /* Minimum stack framesize for SPARC */
36#define STACK_BIAS 2047
37#define ARGS (128) /* Offset of register area in frame */
38
39.text
40 .align 8
41.globl ffi_call_V9
42.globl _ffi_call_V9
43
44ffi_call_V9:
45_ffi_call_V9:
46 save %sp, -STACKFRAME, %sp
47
48 sub %sp, %i2, %sp ! alloca() space in stack for frame to set up
49 add %sp, STACKFRAME+STACK_BIAS, %l0 ! %l0 has start of
50 ! frame to set up
51
52 mov %l0, %o0 ! call routine to set up frame
53 call %i0
54 mov %i1, %o1 ! (delay)
55 brz,pt %o0, 1f
56 ldx [%l0+ARGS], %o0 ! call foreign function
57
58 ldd [%l0+ARGS], %f0
59 ldd [%l0+ARGS+8], %f2
60 ldd [%l0+ARGS+16], %f4
61 ldd [%l0+ARGS+24], %f6
62 ldd [%l0+ARGS+32], %f8
63 ldd [%l0+ARGS+40], %f10
64 ldd [%l0+ARGS+48], %f12
65 ldd [%l0+ARGS+56], %f14
66 ldd [%l0+ARGS+64], %f16
67 ldd [%l0+ARGS+72], %f18
68 ldd [%l0+ARGS+80], %f20
69 ldd [%l0+ARGS+88], %f22
70 ldd [%l0+ARGS+96], %f24
71 ldd [%l0+ARGS+104], %f26
72 ldd [%l0+ARGS+112], %f28
73 ldd [%l0+ARGS+120], %f30
74
751: ldx [%l0+ARGS+8], %o1
76 ldx [%l0+ARGS+16], %o2
77 ldx [%l0+ARGS+24], %o3
78 ldx [%l0+ARGS+32], %o4
79 ldx [%l0+ARGS+40], %o5
80 call %i5
81 sub %l0, STACK_BIAS, %sp ! (delay) switch to frame
82
83 ! If the return value pointer is NULL, assume no return value.
84 brz,pn %i4, done
85 nop
86
87 cmp %i3, FFI_TYPE_INT
88 be,a,pt %icc, done
89 stx %o0, [%i4] ! (delay)
90
91 cmp %i3, FFI_TYPE_FLOAT
92 be,a,pn %icc, done
93 st %f0, [%i4+0] ! (delay)
94
95 cmp %i3, FFI_TYPE_DOUBLE
96 be,a,pn %icc, done
97 std %f0, [%i4+0] ! (delay)
98
99 cmp %i3, FFI_TYPE_STRUCT
100 be,pn %icc, dostruct
101
102 cmp %i3, FFI_TYPE_LONGDOUBLE
103 bne,pt %icc, done
104 nop
105 std %f0, [%i4+0]
106 std %f2, [%i4+8]
107
108done: ret
109 restore
110
111dostruct:
112 /* This will not work correctly for unions. */
113 stx %o0, [%i4+0]
114 stx %o1, [%i4+8]
115 stx %o2, [%i4+16]
116 stx %o3, [%i4+24]
117 std %f0, [%i4+32]
118 std %f2, [%i4+40]
119 std %f4, [%i4+48]
120 std %f6, [%i4+56]
121 ret
122 restore
123
124.ffi_call_V9_end:
125 .size ffi_call_V9,.ffi_call_V9_end-ffi_call_V9
126
127#endif