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

« back to all changes in this revision

Viewing changes to libffi/src/powerpc/darwin.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
   darwin.S - Copyright (c) 2000 John Hornkvist
 
3
              Copyright (c) 2004 Free Software Foundation, Inc.
 
4
 
 
5
   PowerPC Assembly glue.
 
6
 
 
7
   Permission is hereby granted, free of charge, to any person obtaining
 
8
   a copy of this software and associated documentation files (the
 
9
   ``Software''), to deal in the Software without restriction, including
 
10
   without limitation the rights to use, copy, modify, merge, publish,
 
11
   distribute, sublicense, and/or sell copies of the Software, and to
 
12
   permit persons to whom the Software is furnished to do so, subject to
 
13
   the following conditions:
 
14
 
 
15
   The above copyright notice and this permission notice shall be included
 
16
   in all copies or substantial portions of the Software.
 
17
 
 
18
   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
19
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
20
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
21
   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
22
   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
23
   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
24
   OTHER DEALINGS IN THE SOFTWARE.
 
25
   ----------------------------------------------------------------------- */
 
26
 
 
27
#if defined(__ppc64__)
 
28
#define MODE_CHOICE(x, y) y
 
29
#else
 
30
#define MODE_CHOICE(x, y) x
 
31
#endif
 
32
 
 
33
#define g_long  MODE_CHOICE(long, quad)         /* usage is ".g_long" */
 
34
 
 
35
#define LOG2_GPR_BYTES  MODE_CHOICE(2,3)        /* log2(GPR_BYTES) */
 
36
 
 
37
#define LIBFFI_ASM
 
38
#include <fficonfig.h>
 
39
#include <ffi.h>
 
40
#define JUMPTARGET(name) name
 
41
#define L(x) x
 
42
.text
 
43
        .align 2
 
44
.globl _ffi_prep_args
 
45
 
 
46
.text
 
47
        .align 2
 
48
.globl _ffi_call_DARWIN
 
49
.text
 
50
        .align 2
 
51
_ffi_call_DARWIN:
 
52
LFB0:
 
53
        mr      r12,r8  /* We only need r12 until the call,
 
54
                           so it doesn't have to be saved.  */
 
55
LFB1:
 
56
        /* Save the old stack pointer as AP.  */
 
57
        mr      r8,r1
 
58
LCFI0:
 
59
        /* Allocate the stack space we need.  */
 
60
        stwux   r1,r1,r4
 
61
 
 
62
        /* Save registers we use.  */
 
63
        mflr    r9
 
64
 
 
65
        stw     r28,-16(r8)     
 
66
        stw     r29,-12(r8)
 
67
        stw     r30,-8(r8)
 
68
        stw     r31,-4(r8)
 
69
 
 
70
        stw     r9,8(r8)
 
71
        stw     r2,20(r1)
 
72
LCFI1:
 
73
 
 
74
        /* Save arguments over call.  */
 
75
        mr      r31,r5  /* flags,  */
 
76
        mr      r30,r6  /* rvalue,  */
 
77
        mr      r29,r7  /* function address,  */
 
78
        mr      r28,r8  /* our AP.  */
 
79
LCFI2:
 
80
        /* Call ffi_prep_args.  */
 
81
        mr      r4,r1
 
82
        li      r9,0
 
83
 
 
84
        mtctr   r12 /* r12 holds address of _ffi_prep_args.  */
 
85
        bctrl
 
86
        lwz     r2,20(r1)
 
87
 
 
88
        /* Now do the call.
 
89
           Set up cr1 with bits 4-7 of the flags.  */
 
90
        mtcrf   0x40,r31
 
91
        /* Get the address to call into CTR.  */
 
92
        mtctr   r29
 
93
        /* Load all those argument registers.
 
94
           We have set up a nice stack frame, just load it into registers.  */
 
95
        lwz     r3,20+(1*4)(r1)
 
96
        lwz     r4,20+(2*4)(r1)
 
97
        lwz     r5,20+(3*4)(r1)
 
98
        lwz     r6,20+(4*4)(r1)
 
99
        nop
 
100
        lwz     r7,20+(5*4)(r1)
 
101
        lwz     r8,20+(6*4)(r1)
 
102
        lwz     r9,20+(7*4)(r1)
 
103
        lwz     r10,20+(8*4)(r1)
 
104
 
 
105
L1:
 
106
        /* Load all the FP registers.  */
 
107
        bf      6,L2    /* No floats to load.  */
 
108
        lfd     f1,-16-(13*8)(r28)
 
109
        lfd     f2,-16-(12*8)(r28)
 
110
        lfd     f3,-16-(11*8)(r28)
 
111
        lfd     f4,-16-(10*8)(r28)
 
112
        nop
 
113
        lfd     f5,-16-(9*8)(r28)
 
114
        lfd     f6,-16-(8*8)(r28)
 
115
        lfd     f7,-16-(7*8)(r28)
 
116
        lfd     f8,-16-(6*8)(r28)
 
117
        nop
 
118
        lfd     f9,-16-(5*8)(r28)
 
119
        lfd     f10,-16-(4*8)(r28)
 
120
        lfd     f11,-16-(3*8)(r28)
 
121
        lfd     f12,-16-(2*8)(r28)
 
122
        nop
 
123
        lfd     f13,-16-(1*8)(r28)
 
124
 
 
125
L2:
 
126
        mr      r12,r29 /* Put the target address in r12 as specified.  */
 
127
        mtctr   r12
 
128
        nop
 
129
        nop
 
130
        /* Make the call.  */
 
131
        bctrl
 
132
 
 
133
        /* Now, deal with the return value.  */
 
134
        mtcrf   0x01,r31
 
135
 
 
136
        bt      30,L(done_return_value)
 
137
        bt      29,L(fp_return_value)
 
138
        stw     r3,0(r30)
 
139
        bf      28,L(done_return_value)
 
140
        stw     r4,4(r30)
 
141
 
 
142
        /* Fall through.  */
 
143
 
 
144
L(done_return_value):
 
145
        /* Restore the registers we used and return.  */
 
146
        lwz     r9,8(r28)
 
147
        lwz     r31,-4(r28)
 
148
        mtlr    r9
 
149
        lwz     r30,-8(r28)
 
150
        lwz     r29,-12(r28)
 
151
        lwz     r28,-16(r28)
 
152
        lwz     r1,0(r1)
 
153
        blr
 
154
 
 
155
L(fp_return_value):
 
156
        /* Do we have long double to store?  */
 
157
        bf      31,L(fd_return_value)
 
158
        stfd    f1,0(r30)
 
159
        stfd    f2,8(r30)
 
160
        b       L(done_return_value)
 
161
 
 
162
L(fd_return_value):
 
163
        /* Do we have double to store?  */
 
164
        bf      28,L(float_return_value)
 
165
        stfd    f1,0(r30)
 
166
        b       L(done_return_value)
 
167
 
 
168
L(float_return_value):
 
169
        /* We only have a float to store.  */
 
170
        stfs    f1,0(r30)
 
171
        b       L(done_return_value)
 
172
 
 
173
LFE1:
 
174
/* END(_ffi_call_DARWIN)  */
 
175
 
 
176
/* Provide a null definition of _ffi_call_AIX.  */
 
177
.text
 
178
        .align 2
 
179
.globl _ffi_call_AIX
 
180
.text
 
181
        .align 2
 
182
_ffi_call_AIX:
 
183
        blr
 
184
/* END(_ffi_call_AIX)  */
 
185
 
 
186
.data
 
187
.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms
 
188
EH_frame1:
 
189
        .set    L$set$0,LECIE1-LSCIE1
 
190
        .long   L$set$0 ; Length of Common Information Entry
 
191
LSCIE1:
 
192
        .long   0x0     ; CIE Identifier Tag
 
193
        .byte   0x1     ; CIE Version
 
194
        .ascii  "zR\0"  ; CIE Augmentation
 
195
        .byte   0x1     ; uleb128 0x1; CIE Code Alignment Factor
 
196
        .byte   0x7c    ; sleb128 -4; CIE Data Alignment Factor
 
197
        .byte   0x41    ; CIE RA Column
 
198
        .byte   0x1     ; uleb128 0x1; Augmentation size
 
199
        .byte   0x90    ; FDE Encoding (indirect pcrel)
 
200
        .byte   0xc     ; DW_CFA_def_cfa
 
201
        .byte   0x1     ; uleb128 0x1
 
202
        .byte   0x0     ; uleb128 0x0
 
203
        .align  LOG2_GPR_BYTES
 
204
LECIE1:
 
205
.globl _ffi_call_DARWIN.eh
 
206
_ffi_call_DARWIN.eh:
 
207
LSFDE1:
 
208
        .set    L$set$1,LEFDE1-LASFDE1
 
209
        .long   L$set$1 ; FDE Length
 
210
LASFDE1:
 
211
        .long   LASFDE1-EH_frame1 ; FDE CIE offset
 
212
        .g_long LLFB0$non_lazy_ptr-.    ; FDE initial location
 
213
        .set    L$set$3,LFE1-LFB0
 
214
        .g_long L$set$3 ; FDE address range
 
215
        .byte   0x0     ; uleb128 0x0; Augmentation size
 
216
        .byte   0x4     ; DW_CFA_advance_loc4
 
217
        .set    L$set$4,LCFI0-LFB1
 
218
        .long   L$set$4
 
219
        .byte   0xd     ; DW_CFA_def_cfa_register
 
220
        .byte   0x08    ; uleb128 0x08
 
221
        .byte   0x4     ; DW_CFA_advance_loc4
 
222
        .set    L$set$5,LCFI1-LCFI0
 
223
        .long   L$set$5
 
224
        .byte   0x11    ; DW_CFA_offset_extended_sf
 
225
        .byte   0x41    ; uleb128 0x41
 
226
        .byte   0x7e    ; sleb128 -2
 
227
        .byte   0x9f    ; DW_CFA_offset, column 0x1f
 
228
        .byte   0x1     ; uleb128 0x1
 
229
        .byte   0x9e    ; DW_CFA_offset, column 0x1e
 
230
        .byte   0x2     ; uleb128 0x2
 
231
        .byte   0x9d    ; DW_CFA_offset, column 0x1d
 
232
        .byte   0x3     ; uleb128 0x3
 
233
        .byte   0x9c    ; DW_CFA_offset, column 0x1c
 
234
        .byte   0x4     ; uleb128 0x4
 
235
        .byte   0x4     ; DW_CFA_advance_loc4
 
236
        .set    L$set$6,LCFI2-LCFI1
 
237
        .long   L$set$6
 
238
        .byte   0xd     ; DW_CFA_def_cfa_register
 
239
        .byte   0x1c    ; uleb128 0x1c
 
240
        .align LOG2_GPR_BYTES
 
241
LEFDE1:
 
242
.data
 
243
        .align LOG2_GPR_BYTES
 
244
LLFB0$non_lazy_ptr:
 
245
        .g_long LFB0