1 /* -----------------------------------------------------------------------
2 v9.S - Copyright (c) 2000, 2003, 2004 Red Hat, Inc.
4 SPARC 64-bit 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,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
25 ----------------------------------------------------------------------- */
28 #include <fficonfig.h>
32 /* Only compile this in for 64bit builds, because otherwise the object file
33 will have inproper architecture due to used instructions. */
35 #define STACKFRAME 128 /* Minimum stack framesize for SPARC */
36 #define STACK_BIAS 2047
37 #define ARGS (128) /* Offset of register area in frame */
47 save %sp, -STACKFRAME, %sp
50 sub %sp, %i2, %sp ! alloca() space in stack for frame to set up
51 add %sp, STACKFRAME+STACK_BIAS, %l0 ! %l0 has start of
54 mov %l0, %o0 ! call routine to set up frame
56 mov %i1, %o1 ! (delay)
58 ldx [%l0+ARGS], %o0 ! call foreign function
62 ldd [%l0+ARGS+16], %f4
63 ldd [%l0+ARGS+24], %f6
64 ldd [%l0+ARGS+32], %f8
65 ldd [%l0+ARGS+40], %f10
66 ldd [%l0+ARGS+48], %f12
67 ldd [%l0+ARGS+56], %f14
68 ldd [%l0+ARGS+64], %f16
69 ldd [%l0+ARGS+72], %f18
70 ldd [%l0+ARGS+80], %f20
71 ldd [%l0+ARGS+88], %f22
72 ldd [%l0+ARGS+96], %f24
73 ldd [%l0+ARGS+104], %f26
74 ldd [%l0+ARGS+112], %f28
75 ldd [%l0+ARGS+120], %f30
77 1: ldx [%l0+ARGS+8], %o1
78 ldx [%l0+ARGS+16], %o2
79 ldx [%l0+ARGS+24], %o3
80 ldx [%l0+ARGS+32], %o4
81 ldx [%l0+ARGS+40], %o5
83 sub %l0, STACK_BIAS, %sp ! (delay) switch to frame
85 ! If the return value pointer is NULL, assume no return value.
91 stx %o0, [%i4+0] ! (delay)
93 cmp %i3, FFI_TYPE_FLOAT
95 st %f0, [%i4+0] ! (delay)
97 cmp %i3, FFI_TYPE_DOUBLE
99 std %f0, [%i4+0] ! (delay)
101 cmp %i3, FFI_TYPE_STRUCT
104 cmp %i3, FFI_TYPE_LONGDOUBLE
114 /* This will not work correctly for unions. */
128 .size ffi_call_v9,.ffi_call_v9_end-ffi_call_v9
132 #define STACKFRAME 336 /* 16*8 register window +
133 6*8 args backing store +
135 #define FP %fp+STACK_BIAS
137 /* ffi_closure_v9(...)
139 Receives the closure argument in %g1. */
143 .globl ffi_closure_v9
147 save %sp, -STACKFRAME, %sp
150 ! Store all of the potential argument registers in va_list format.
158 ! Store possible floating point argument registers too.
176 ! Call ffi_closure_sparc_inner to do the bulk of the work.
178 add %fp, STACK_BIAS-160, %o1
179 add %fp, STACK_BIAS+128, %o2
180 call ffi_closure_sparc_inner_v9
181 add %fp, STACK_BIAS-128, %o3
183 ! Load up the return value in the proper type.
184 ! See ffi_prep_cif_machdep for the list of cases.
185 cmp %o0, FFI_TYPE_VOID
188 cmp %o0, FFI_TYPE_INT
191 cmp %o0, FFI_TYPE_FLOAT
195 cmp %o0, FFI_TYPE_DOUBLE
199 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
200 cmp %o0, FFI_TYPE_LONGDOUBLE
201 be,a,pn %icc, longdouble1
221 #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
230 .size ffi_closure_v9,.ffi_closure_v9_end-ffi_closure_v9
232 #ifdef HAVE_RO_EH_FRAME
233 .section ".eh_frame",#alloc
235 .section ".eh_frame",#alloc,#write
238 .uaword .LLECIE1-.LLSCIE1 ! Length of Common Information Entry
240 .uaword 0x0 ! CIE Identifier Tag
241 .byte 0x1 ! CIE Version
242 .ascii "zR\0" ! CIE Augmentation
243 .byte 0x1 ! uleb128 0x1; CIE Code Alignment Factor
244 .byte 0x78 ! sleb128 -8; CIE Data Alignment Factor
245 .byte 0xf ! CIE RA Column
246 .byte 0x1 ! uleb128 0x1; Augmentation size
247 #ifdef HAVE_AS_SPARC_UA_PCREL
248 .byte 0x1b ! FDE Encoding (pcrel sdata4)
250 .byte 0x50 ! FDE Encoding (aligned absolute)
252 .byte 0xc ! DW_CFA_def_cfa
253 .byte 0xe ! uleb128 0xe
254 .byte 0xff,0xf ! uleb128 0x7ff
258 .uaword .LLEFDE1-.LLASFDE1 ! FDE Length
260 .uaword .LLASFDE1-.LLframe1 ! FDE CIE offset
261 #ifdef HAVE_AS_SPARC_UA_PCREL
262 .uaword %r_disp32(.LLFB1)
263 .uaword .LLFE1-.LLFB1 ! FDE address range
267 .uaxword .LLFE1-.LLFB1 ! FDE address range
269 .byte 0x0 ! uleb128 0x0; Augmentation size
270 .byte 0x4 ! DW_CFA_advance_loc4
271 .uaword .LLCFI0-.LLFB1
272 .byte 0xd ! DW_CFA_def_cfa_register
273 .byte 0x1e ! uleb128 0x1e
274 .byte 0x2d ! DW_CFA_GNU_window_save
275 .byte 0x9 ! DW_CFA_register
276 .byte 0xf ! uleb128 0xf
277 .byte 0x1f ! uleb128 0x1f
281 .uaword .LLEFDE2-.LLASFDE2 ! FDE Length
283 .uaword .LLASFDE2-.LLframe1 ! FDE CIE offset
284 #ifdef HAVE_AS_SPARC_UA_PCREL
285 .uaword %r_disp32(.LLFB2)
286 .uaword .LLFE2-.LLFB2 ! FDE address range
290 .uaxword .LLFE2-.LLFB2 ! FDE address range
292 .byte 0x0 ! uleb128 0x0; Augmentation size
293 .byte 0x4 ! DW_CFA_advance_loc4
294 .uaword .LLCFI1-.LLFB2
295 .byte 0xd ! DW_CFA_def_cfa_register
296 .byte 0x1e ! uleb128 0x1e
297 .byte 0x2d ! DW_CFA_GNU_window_save
298 .byte 0x9 ! DW_CFA_register
299 .byte 0xf ! uleb128 0xf
300 .byte 0x1f ! uleb128 0x1f
306 .section .note.GNU-stack,"",@progbits