1 /* -----------------------------------------------------------------------
2 v9.S - Copyright (c) 2000, 2003 Cygnus Solutions
4 Sparc 64bit 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 ----------------------------------------------------------------------- */
30 /* Only compile this in for 64bit builds, because otherwise the object file
31 will have inproper architecture due to used instructions. */
33 #define STACKFRAME 128 /* Minimum stack framesize for SPARC */
34 #define STACK_BIAS 2047
35 #define ARGS (128) /* Offset of register area in frame */
45 save %sp, -STACKFRAME, %sp
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
52 mov %l0, %o0 ! call routine to set up frame
54 mov %i1, %o1 ! (delay)
56 ldx [%l0+ARGS], %o0 ! call foreign function
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
75 1: 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
81 sub %l0, STACK_BIAS, %sp ! (delay) switch to frame
83 ! If the return value pointer is NULL, assume no return value.
89 stx %o0, [%i4] ! (delay)
91 cmp %i3, FFI_TYPE_FLOAT
93 st %f0, [%i4+0] ! (delay)
95 cmp %i3, FFI_TYPE_DOUBLE
97 std %f0, [%i4+0] ! (delay)
99 cmp %i3, FFI_TYPE_STRUCT
102 cmp %i3, FFI_TYPE_LONGDOUBLE
112 /* This will not work correctly for unions. */
126 .size ffi_call_V9,.ffi_call_V9_end-ffi_call_V9
129 #define STACKFRAME 320 /* 16*8 register window +
130 6*8 args backing store +
132 #define FP %fp+STACK_BIAS
134 /* ffi_closure_v9(...)
136 Receives the closure argument in %g1. */
140 .globl ffi_closure_v9
144 save %sp, -STACKFRAME, %sp
147 ! Store all of the potential argument registers in va_list format.
155 ! Store possible floating point argument registers too.
173 ! Call ffi_closure_sparc_inner to do the bulk of the work.
175 add %fp, STACK_BIAS-144, %o1
176 add %fp, STACK_BIAS+128, %o2
177 call ffi_closure_sparc_inner
178 add %fp, STACK_BIAS-128, %o3
180 ! Load up the return value in the proper type.
181 cmp %o0, FFI_TYPE_VOID
184 cmp %o0, FFI_TYPE_FLOAT
188 cmp %o0, FFI_TYPE_DOUBLE
192 cmp %o0, FFI_TYPE_LONGDOUBLE
193 be,a,pn %icc, longdouble1
196 cmp %o0, FFI_TYPE_STRUCT
199 ! FFI_TYPE_UINT64 | FFI_TYPE_SINT64 | FFI_TYPE_POINTER
218 .size ffi_closure_v9,.ffi_closure_v9_end-ffi_closure_v9
220 #ifdef HAVE_RO_EH_FRAME
221 .section ".eh_frame",#alloc
223 .section ".eh_frame",#alloc,#write
226 .uaword .LLECIE1-.LLSCIE1 ! Length of Common Information Entry
228 .uaword 0x0 ! CIE Identifier Tag
229 .byte 0x1 ! CIE Version
230 .ascii "zR\0" ! CIE Augmentation
231 .byte 0x1 ! uleb128 0x1; CIE Code Alignment Factor
232 .byte 0x78 ! sleb128 -8; CIE Data Alignment Factor
233 .byte 0xf ! CIE RA Column
234 .byte 0x1 ! uleb128 0x1; Augmentation size
235 #ifdef HAVE_AS_SPARC_UA_PCREL
236 .byte 0x1b ! FDE Encoding (pcrel sdata4)
238 .byte 0x50 ! FDE Encoding (aligned absolute)
240 .byte 0xc ! DW_CFA_def_cfa
241 .byte 0xe ! uleb128 0xe
242 .byte 0xff,0xf ! uleb128 0x7ff
246 .uaword .LLEFDE1-.LLASFDE1 ! FDE Length
248 .uaword .LLASFDE1-.LLframe1 ! FDE CIE offset
249 #ifdef HAVE_AS_SPARC_UA_PCREL
250 .uaword %r_disp32(.LLFB1)
251 .uaword .LLFE1-.LLFB1 ! FDE address range
255 .uaxword .LLFE1-.LLFB1 ! FDE address range
257 .byte 0x0 ! uleb128 0x0; Augmentation size
258 .byte 0x4 ! DW_CFA_advance_loc4
259 .uaword .LLCFI0-.LLFB1
260 .byte 0xd ! DW_CFA_def_cfa_register
261 .byte 0x1e ! uleb128 0x1e
262 .byte 0x2d ! DW_CFA_GNU_window_save
263 .byte 0x9 ! DW_CFA_register
264 .byte 0xf ! uleb128 0xf
265 .byte 0x1f ! uleb128 0x1f
269 .uaword .LLEFDE2-.LLASFDE2 ! FDE Length
271 .uaword .LLASFDE2-.LLframe1 ! FDE CIE offset
272 #ifdef HAVE_AS_SPARC_UA_PCREL
273 .uaword %r_disp32(.LLFB2)
274 .uaword .LLFE2-.LLFB2 ! FDE address range
278 .uaxword .LLFE2-.LLFB2 ! FDE address range
280 .byte 0x0 ! uleb128 0x0; Augmentation size
281 .byte 0x4 ! DW_CFA_advance_loc4
282 .uaword .LLCFI1-.LLFB2
283 .byte 0xd ! DW_CFA_def_cfa_register
284 .byte 0x1e ! uleb128 0x1e
285 .byte 0x2d ! DW_CFA_GNU_window_save
286 .byte 0x9 ! DW_CFA_register
287 .byte 0xf ! uleb128 0xf
288 .byte 0x1f ! uleb128 0x1f