* src/powerpc/aix.S (ffi_call_AIX): Convert to more standard
[official-gcc.git] / libffi / src / powerpc / aix_closure.S
blob70456188092b79564979196a1de610f017a0860c
1 /* -----------------------------------------------------------------------
2    aix_closure.S - Copyright (c) 2002, 2003, 2009 Free Software Foundation, Inc.
3    based on darwin_closure.S
5    PowerPC Assembly glue.
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:
15    The above copyright notice and this permission notice shall be included
16    in all copies or substantial portions of the Software.
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    ----------------------------------------------------------------------- */
27         .set r0,0
28         .set r1,1
29         .set r2,2
30         .set r3,3
31         .set r4,4
32         .set r5,5
33         .set r6,6
34         .set r7,7
35         .set r8,8
36         .set r9,9
37         .set r10,10
38         .set r11,11
39         .set r12,12
40         .set r13,13
41         .set r14,14
42         .set r15,15
43         .set r16,16
44         .set r17,17
45         .set r18,18
46         .set r19,19
47         .set r20,20
48         .set r21,21
49         .set r22,22
50         .set r23,23
51         .set r24,24
52         .set r25,25
53         .set r26,26
54         .set r27,27
55         .set r28,28
56         .set r29,29
57         .set r30,30
58         .set r31,31
59         .set f0,0
60         .set f1,1
61         .set f2,2
62         .set f3,3
63         .set f4,4
64         .set f5,5
65         .set f6,6
66         .set f7,7
67         .set f8,8
68         .set f9,9
69         .set f10,10
70         .set f11,11
71         .set f12,12
72         .set f13,13
73         .set f14,14
74         .set f15,15
75         .set f16,16
76         .set f17,17
77         .set f18,18
78         .set f19,19
79         .set f20,20
80         .set f21,21
82 #define LIBFFI_ASM
83 #define JUMPTARGET(name) name
84 #define L(x) x
85         .file "aix_closure.S"
86         .toc
87 LC..60:
88         .tc L..60[TC],L..60
89         .csect .text[PR]
90         .align 2
92 .csect .text[PR]
93         .align 2
94         .globl ffi_closure_ASM
95         .globl .ffi_closure_ASM
96 .csect ffi_closure_ASM[DS]
97 ffi_closure_ASM:
98 #ifdef __64BIT__
99         .llong .ffi_closure_ASM, TOC[tc0], 0
100         .csect .text[PR]
101 .ffi_closure_ASM:
103         mflr r0                 /* extract return address */
104         std r0,16(r1)           /* save the return address */
106         /* 48  Bytes (Linkage Area) */
107         /* 64  Bytes (params) */
108         /* 16  Bytes (result) */
109         /* 104 Bytes (13*8 from FPR) */
110         /* 8   Bytes (alignment) */
111         /* 240 Bytes */
113         stdu r1,-240(r1)        /* skip over caller save area
114                                    keep stack aligned to 16  */
116 /* we want to build up an area for the parameters passed */
117 /* in registers (both floating point and integer) */
119         /* we store gpr 3 to gpr 10 (aligned to 4)
120         in the parents outgoing area  */
121         std   r3, 288+(0*8)(r1)
122         std   r4, 288+(1*8)(r1)
123         std   r5, 288+(2*8)(r1)
124         std   r6, 288+(3*8)(r1)
125         std   r7, 288+(4*8)(r1)
126         std   r8, 288+(5*8)(r1)
127         std   r9, 288+(6*8)(r1)
128         std   r10, 288+(7*8)(r1)
130         /* next save fpr 1 to fpr 13 (aligned to 8) */
131         stfd  f1, 128+(0*8)(r1)
132         stfd  f2, 128+(1*8)(r1)
133         stfd  f3, 128+(2*8)(r1)
134         stfd  f4, 128+(3*8)(r1)
135         stfd  f5, 128+(4*8)(r1)
136         stfd  f6, 128+(5*8)(r1)
137         stfd  f7, 128+(6*8)(r1)
138         stfd  f8, 128+(7*8)(r1)
139         stfd  f9, 128+(8*8)(r1)
140         stfd  f10, 128+(9*8)(r1)
141         stfd  f11, 128+(10*8)(r1)
142         stfd  f12, 128+(11*8)(r1)
143         stfd  f13, 128+(12*8)(r1)
145         /* set up registers for the routine that actually does the work */
146         /* get the context pointer from the trampoline */
147         mr r3,r11
149         /* now load up the pointer to the result storage */
150         addi r4,r1,112
152         /* now load up the pointer to the saved gpr registers */
153         addi r5,r1,288
155         /* now load up the pointer to the saved fpr registers */
156         addi r6,r1,128
158         /* make the call */
159         bl .ffi_closure_helper_DARWIN
160         nop
162         /* now r3 contains the return type */
163         /* so use it to look up in a table */
164         /* so we know how to deal with each type */
166         /* look up the proper starting point in table  */
167         /* by using return type as offset */
168         addi r5,r1,112          /* get pointer to results area */
169         ld r4,LC..60(2)         /* get address of jump table */
170         sldi r3,r3,2            /* now multiply return type by 4 */
171         lwzx r3,r4,r3           /* get the contents of that table value */
172         add r3,r3,r4            /* add contents of table to table address */
173         mtctr r3
174         bctr                    /* jump to it */
176 L..60:
177         .long L..44-L..60    /* FFI_TYPE_VOID */
178         .long L..51-L..60    /* FFI_TYPE_INT */
179         .long L..47-L..60    /* FFI_TYPE_FLOAT */
180         .long L..46-L..60    /* FFI_TYPE_DOUBLE */
181         .long L..45-L..60    /* FFI_TYPE_LONGDOUBLE */
182         .long L..56-L..60    /* FFI_TYPE_UINT8 */
183         .long L..55-L..60    /* FFI_TYPE_SINT8 */
184         .long L..58-L..60    /* FFI_TYPE_UINT16 */
185         .long L..57-L..60    /* FFI_TYPE_SINT16 */
186         .long L..50-L..60    /* FFI_TYPE_UINT32 */
187         .long L..51-L..60    /* FFI_TYPE_SINT32 */
188         .long L..48-L..60    /* FFI_TYPE_UINT64 */
189         .long L..48-L..60    /* FFI_TYPE_SINT64 */
190         .long L..44-L..60    /* FFI_TYPE_STRUCT */
191         .long L..48-L..60    /* FFI_TYPE_POINTER */
194 /* case long double */
195 L..45:
196         lfd f1,0(r5)
197         lfd f2,8(r5)
198         b L..44
200 /* case double */
201 L..46:
202         lfd f1,0(r5)
203         b L..44
205 /* case float */
206 L..47:
207         lfs f1,0(r5)
208         b L..44
210 /* case long long / pointer */
211 L..48:
212         ld r3,0(r5)
213         b L..44
215 /* case uint32 */
216 L..50:
217         lwz r3,4(r5)
218         b L..44
220 /* case int / sint32 */
221 L..51:
222         lwa r3,4(r5)
223         b L..44
225 /* case signed int8 */
226 L..55:
227         lbz r3,7(r5)
228         extsb r3,r3
229         b L..44
231 /* case unsigned int8 */
232 L..56:
233         lbz r3,7(r5)
234         b L..44
236 /* case signed int16 */
237 L..57:
238         lha r3,6(r5)
239         b L..44
241 /* case unsigned int16 */
242 L..58:
243         lhz r3,6(r5)
245 /* case void / done      */
246 L..44:
247         addi r1,r1,240          /* restore stack pointer */
248         ld r0,16(r1)            /* get return address */
249         mtlr r0                 /* reset link register */
250         blr
252 #else /* ! __64BIT__ */
253         
254         .long .ffi_closure_ASM, TOC[tc0], 0
255         .csect .text[PR]
256 .ffi_closure_ASM:
258         mflr r0                 /* extract return address */
259         stw r0, 8(r1)           /* save the return address */
261         /* 24 Bytes (Linkage Area) */
262         /* 32 Bytes (params) */
263         /* 104 Bytes (13*8 from FPR) */
264         /* 16  Bytes (result) */
265         /* 176 Bytes */
267         stwu r1,-176(r1)        /* skip over caller save area
268                                 keep stack aligned to 16  */
270 /* we want to build up an area for the parameters passed */
271 /* in registers (both floating point and integer) */
273         /* we store gpr 3 to gpr 10 (aligned to 4)
274         in the parents outgoing area  */
275         stw   r3, 200(r1)
276         stw   r4, 204(r1)
277         stw   r5, 208(r1)
278         stw   r6, 212(r1)
279         stw   r7, 216(r1)
280         stw   r8, 220(r1)
281         stw   r9, 224(r1)
282         stw   r10, 228(r1)
284         /* next save fpr 1 to fpr 13 (aligned to 8) */
285         stfd  f1, 56(r1)
286         stfd  f2, 64(r1)
287         stfd  f3, 72(r1)
288         stfd  f4, 80(r1)
289         stfd  f5, 88(r1)
290         stfd  f6, 96(r1)
291         stfd  f7, 104(r1)
292         stfd  f8, 112(r1)
293         stfd  f9, 120(r1)
294         stfd  f10, 128(r1)
295         stfd  f11, 136(r1)
296         stfd  f12, 144(r1)
297         stfd  f13, 152(r1)
299         /* set up registers for the routine that actually does the work */
300         /* get the context pointer from the trampoline */
301         mr r3,r11
303         /* now load up the pointer to the result storage */
304         addi r4,r1,160
306         /* now load up the pointer to the saved gpr registers */
307         addi r5,r1,200
309         /* now load up the pointer to the saved fpr registers */
310         addi r6,r1,56
312         /* make the call */
313         bl .ffi_closure_helper_DARWIN
314         nop
316         /* now r3 contains the return type */
317         /* so use it to look up in a table */
318         /* so we know how to deal with each type */
320         /* look up the proper starting point in table  */
321         /* by using return type as offset */
322         addi r5,r1,160          /* get pointer to results area */
323         lwz r4,LC..60(2)        /* get address of jump table */
324         slwi r3,r3,2            /* now multiply return type by 4 */
325         lwzx r3,r4,r3           /* get the contents of that table value */
326         add r3,r3,r4            /* add contents of table to table address */
327         mtctr r3
328         bctr                    /* jump to it */
330 L..60:
331         .long L..44-L..60    /* FFI_TYPE_VOID */
332         .long L..50-L..60    /* FFI_TYPE_INT */
333         .long L..47-L..60    /* FFI_TYPE_FLOAT */
334         .long L..46-L..60    /* FFI_TYPE_DOUBLE */
335         .long L..45-L..60    /* FFI_TYPE_LONGDOUBLE */
336         .long L..56-L..60    /* FFI_TYPE_UINT8 */
337         .long L..55-L..60    /* FFI_TYPE_SINT8 */
338         .long L..58-L..60    /* FFI_TYPE_UINT16 */
339         .long L..57-L..60    /* FFI_TYPE_SINT16 */
340         .long L..50-L..60    /* FFI_TYPE_UINT32 */
341         .long L..50-L..60    /* FFI_TYPE_SINT32 */
342         .long L..48-L..60    /* FFI_TYPE_UINT64 */
343         .long L..48-L..60    /* FFI_TYPE_SINT64 */
344         .long L..44-L..60    /* FFI_TYPE_STRUCT */
345         .long L..50-L..60    /* FFI_TYPE_POINTER */
348 /* case long double */
349 L..45:
350         lfd f1,0(r5)
351         lfd f2,8(r5)
352         b L..44
354 /* case double */
355 L..46:
356         lfd f1,0(r5)
357         b L..44
359 /* case float */
360 L..47:
361         lfs f1,0(r5)
362         b L..44
364 /* case long long */
365 L..48:
366         lwz r3,0(r5)
367         lwz r4,4(r5)
368         b L..44
370 /* case default / int32 / pointer */
371 L..50:
372         lwz r3,0(r5)
373         b L..44
375 /* case signed int8 */
376 L..55:
377         lbz r3,3(r5)
378         extsb r3,r3
379         b L..44
381 /* case unsigned int8 */
382 L..56:
383         lbz r3,3(r5)
384         b L..44
386 /* case signed int16 */
387 L..57:
388         lha r3,2(r5)
389         b L..44
391 /* case unsigned int16 */
392 L..58:
393         lhz r3,2(r5)
395 /* case void / done      */
396 L..44:
397         addi r1,r1,176          /* restore stack pointer */
398         lwz r0,8(r1)            /* get return address */
399         mtlr r0                 /* reset link register */
400         blr
401 #endif
402 /* END(ffi_closure_ASM) */