~ubuntu-branches/ubuntu/lucid/gauche-c-wrapper/lucid

« back to all changes in this revision

Viewing changes to libffi/src/sparc/v8.S

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2008-04-07 09:15:03 UTC
  • Revision ID: james.westby@ubuntu.com-20080407091503-wu0h414koe95kj4i
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -----------------------------------------------------------------------
 
2
   v8.S - Copyright (c) 1996, 1997, 2003, 2004 Red Hat, Inc.
 
3
   
 
4
   SPARC 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 <fficonfig.h>
 
28
#include <ffi.h>
 
29
 
 
30
#define STACKFRAME 96           /* Minimum stack framesize for SPARC */
 
31
#define ARGS (64+4)             /* Offset of register area in frame */
 
32
 
 
33
.text
 
34
        .align 8
 
35
.globl ffi_call_v8
 
36
.globl _ffi_call_v8
 
37
 
 
38
ffi_call_v8:
 
39
_ffi_call_v8:
 
40
.LLFB1:
 
41
        save    %sp, -STACKFRAME, %sp
 
42
.LLCFI0:
 
43
        
 
44
        sub     %sp, %i2, %sp   ! alloca() space in stack for frame to set up
 
45
        add     %sp, STACKFRAME, %l0    ! %l0 has start of 
 
46
                                        ! frame to set up
 
47
 
 
48
        mov     %l0, %o0        ! call routine to set up frame
 
49
        call    %i0
 
50
        mov     %i1, %o1        ! (delay)
 
51
 
 
52
        ld      [%l0+ARGS], %o0 ! call foreign function
 
53
        ld      [%l0+ARGS+4], %o1
 
54
        ld      [%l0+ARGS+8], %o2
 
55
        ld      [%l0+ARGS+12], %o3
 
56
        ld      [%l0+ARGS+16], %o4
 
57
        ld      [%l0+ARGS+20], %o5
 
58
        call    %i5
 
59
        mov     %l0, %sp        ! (delay) switch to frame
 
60
        nop                     ! STRUCT returning functions skip 12 instead of 8 bytes
 
61
 
 
62
        ! If the return value pointer is NULL, assume no return value.
 
63
        tst     %i4
 
64
        bz      done
 
65
        nop
 
66
 
 
67
        cmp     %i3, FFI_TYPE_INT
 
68
        be,a    done
 
69
        st      %o0, [%i4]      ! (delay)
 
70
 
 
71
        cmp     %i3, FFI_TYPE_FLOAT
 
72
        be,a    done
 
73
        st      %f0, [%i4+0]    ! (delay)
 
74
 
 
75
        cmp     %i3, FFI_TYPE_SINT64
 
76
        be      longlong
 
77
 
 
78
        cmp     %i3, FFI_TYPE_DOUBLE
 
79
        bne     done
 
80
        nop
 
81
        st      %f0, [%i4+0]
 
82
        st      %f1, [%i4+4]
 
83
        
 
84
done:
 
85
        ret
 
86
        restore
 
87
 
 
88
longlong:
 
89
        st      %o0, [%i4+0]
 
90
        st      %o1, [%i4+4]
 
91
        ret
 
92
        restore
 
93
.LLFE1:
 
94
 
 
95
.ffi_call_v8_end:
 
96
        .size   ffi_call_v8,.ffi_call_v8_end-ffi_call_v8
 
97
 
 
98
 
 
99
#undef STACKFRAME
 
100
#define STACKFRAME      104     /* 16*4 register window +
 
101
                                   1*4 struct return +  
 
102
                                   6*4 args backing store +
 
103
                                   3*4 locals */
 
104
 
 
105
/* ffi_closure_v8(...)
 
106
 
 
107
   Receives the closure argument in %g2.   */
 
108
 
 
109
        .text
 
110
        .align 8
 
111
        .globl ffi_closure_v8
 
112
 
 
113
ffi_closure_v8:
 
114
#ifdef HAVE_AS_REGISTER_PSEUDO_OP
 
115
                .register       %g2, #scratch
 
116
#endif
 
117
.LLFB2:
 
118
        ! Reserve frame space for all arguments in case
 
119
        ! we need to align them on a 8-byte boundary.
 
120
        ld      [%g2+FFI_TRAMPOLINE_SIZE], %g1
 
121
        ld      [%g1+4], %g1
 
122
        sll     %g1, 3, %g1
 
123
        add     %g1, STACKFRAME, %g1
 
124
        ! %g1 == STACKFRAME + 8*nargs
 
125
        neg     %g1
 
126
        save    %sp, %g1, %sp
 
127
.LLCFI1:
 
128
 
 
129
        ! Store all of the potential argument registers in va_list format.
 
130
        st      %i0, [%fp+68+0]
 
131
        st      %i1, [%fp+68+4]
 
132
        st      %i2, [%fp+68+8]
 
133
        st      %i3, [%fp+68+12]
 
134
        st      %i4, [%fp+68+16]
 
135
        st      %i5, [%fp+68+20]
 
136
 
 
137
        ! Call ffi_closure_sparc_inner to do the bulk of the work.
 
138
        mov     %g2, %o0
 
139
        add     %fp, -8, %o1
 
140
        add     %fp,  64, %o2
 
141
        call    ffi_closure_sparc_inner_v8
 
142
         add    %fp, -16, %o3
 
143
 
 
144
        ! Load up the return value in the proper type.
 
145
        ! See ffi_prep_cif_machdep for the list of cases.
 
146
        cmp     %o0, FFI_TYPE_VOID
 
147
        be      done1
 
148
 
 
149
        cmp     %o0, FFI_TYPE_INT
 
150
        be      integer
 
151
 
 
152
        cmp     %o0, FFI_TYPE_FLOAT
 
153
        be,a    done1
 
154
         ld     [%fp-8], %f0
 
155
 
 
156
        cmp     %o0, FFI_TYPE_DOUBLE
 
157
        be,a    done1
 
158
         ldd    [%fp-8], %f0
 
159
 
 
160
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
 
161
        cmp     %o0, FFI_TYPE_LONGDOUBLE
 
162
        be      done2
 
163
#endif
 
164
 
 
165
        cmp     %o0, FFI_TYPE_STRUCT
 
166
        be      done2
 
167
 
 
168
        ! FFI_TYPE_SINT64
 
169
        ! FFI_TYPE_UINT64
 
170
        ld      [%fp-4], %i1
 
171
 
 
172
integer:
 
173
        ld      [%fp-8], %i0
 
174
 
 
175
done1:
 
176
        jmp     %i7+8
 
177
         restore
 
178
done2:
 
179
        ! Skip 'unimp'.
 
180
        jmp     %i7+12
 
181
         restore
 
182
.LLFE2:
 
183
 
 
184
.ffi_closure_v8_end:
 
185
        .size   ffi_closure_v8,.ffi_closure_v8_end-ffi_closure_v8
 
186
 
 
187
#ifdef SPARC64
 
188
#define WS 8
 
189
#define nword   xword
 
190
#define uanword uaxword
 
191
#else
 
192
#define WS 4
 
193
#define nword   long
 
194
#define uanword uaword
 
195
#endif
 
196
 
 
197
#ifdef HAVE_RO_EH_FRAME
 
198
        .section        ".eh_frame",#alloc
 
199
#else
 
200
        .section        ".eh_frame",#alloc,#write
 
201
#endif
 
202
.LLframe1:
 
203
        .uaword .LLECIE1-.LLSCIE1       ! Length of Common Information Entry
 
204
.LLSCIE1:
 
205
        .uaword 0x0     ! CIE Identifier Tag
 
206
        .byte   0x1     ! CIE Version
 
207
        .ascii "zR\0"   ! CIE Augmentation
 
208
        .byte   0x1     ! uleb128 0x1; CIE Code Alignment Factor
 
209
        .byte   0x80-WS ! sleb128 -WS; CIE Data Alignment Factor
 
210
        .byte   0xf     ! CIE RA Column
 
211
        .byte   0x1     ! uleb128 0x1; Augmentation size
 
212
#ifdef HAVE_AS_SPARC_UA_PCREL
 
213
        .byte   0x1b    ! FDE Encoding (pcrel sdata4)
 
214
#else
 
215
        .byte   0x50    ! FDE Encoding (aligned absolute)
 
216
#endif
 
217
        .byte   0xc     ! DW_CFA_def_cfa
 
218
        .byte   0xe     ! uleb128 0xe
 
219
        .byte   0x0     ! uleb128 0x0
 
220
        .align  WS
 
221
.LLECIE1:
 
222
.LLSFDE1:
 
223
        .uaword .LLEFDE1-.LLASFDE1      ! FDE Length
 
224
.LLASFDE1:
 
225
        .uaword .LLASFDE1-.LLframe1     ! FDE CIE offset
 
226
#ifdef HAVE_AS_SPARC_UA_PCREL
 
227
        .uaword %r_disp32(.LLFB1)
 
228
        .uaword .LLFE1-.LLFB1   ! FDE address range
 
229
#else
 
230
        .align  WS
 
231
        .nword  .LLFB1
 
232
        .uanword .LLFE1-.LLFB1  ! FDE address range
 
233
#endif
 
234
        .byte   0x0     ! uleb128 0x0; Augmentation size
 
235
        .byte   0x4     ! DW_CFA_advance_loc4
 
236
        .uaword .LLCFI0-.LLFB1
 
237
        .byte   0xd     ! DW_CFA_def_cfa_register
 
238
        .byte   0x1e    ! uleb128 0x1e
 
239
        .byte   0x2d    ! DW_CFA_GNU_window_save
 
240
        .byte   0x9     ! DW_CFA_register
 
241
        .byte   0xf     ! uleb128 0xf
 
242
        .byte   0x1f    ! uleb128 0x1f
 
243
        .align  WS
 
244
.LLEFDE1:
 
245
.LLSFDE2:
 
246
        .uaword .LLEFDE2-.LLASFDE2      ! FDE Length
 
247
.LLASFDE2:
 
248
        .uaword .LLASFDE2-.LLframe1     ! FDE CIE offset
 
249
#ifdef HAVE_AS_SPARC_UA_PCREL
 
250
        .uaword %r_disp32(.LLFB2)
 
251
        .uaword .LLFE2-.LLFB2   ! FDE address range
 
252
#else
 
253
        .align  WS
 
254
        .nword  .LLFB2
 
255
        .uanword .LLFE2-.LLFB2  ! FDE address range
 
256
#endif
 
257
        .byte   0x0     ! uleb128 0x0; Augmentation size
 
258
        .byte   0x4     ! DW_CFA_advance_loc4
 
259
        .uaword .LLCFI1-.LLFB2
 
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
 
266
        .align  WS
 
267
.LLEFDE2: