FSF GCC merge 02/23/03
[official-gcc.git] / libffi / src / powerpc / aix_closure.S
blobd0d50ca56bdecb80d4787ca554c6f4441475b21f
1 /* -----------------------------------------------------------------------
2    aix_closure.S - Copyright (c) 2002 2003 Free Software Foundation, Inc.
3    based on darwin_closure.S 
4   
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]
98 ffi_closure_ASM:
99         .long .ffi_closure_ASM, TOC[tc0], 0
100         .csect .text[PR]
101 .ffi_closure_ASM:
103         mflr r0                 /* extract return address */
104         stw r0, 8(r1)           /* save the return address */
105         
106         /* 24 Bytes (Linkage Area) */
107         /* 32 Bytes (params) */
108         /* 104 Bytes (13*8 from FPR) */ 
109         /* 8 Bytes (result)
110         /* 168 Bytes */
111         
112         stwu r1,-176(r1)        /* skip over caller save area
113                                 keep stack aligned to 16  */
115 /* we want to build up an area for the parameters passed */
116 /* in registers (both floating point and integer) */
117         
118         /* we store gpr 3 to gpr 10 (aligned to 4)
119         in the parents outgoing area  */
120         stw   r3, 200(r1)
121         stw   r4, 204(r1)
122         stw   r5, 208(r1) 
123         stw   r6, 212(r1)
124         stw   r7, 216(r1)
125         stw   r8, 220(r1) 
126         stw   r9, 224(r1)
127         stw   r10, 228(r1)
129         /* next save fpr 1 to fpr 13 (aligned to 8) */
130         stfd  f1, 56(r1)
131         stfd  f2, 64(r1)
132         stfd  f3, 72(r1)
133         stfd  f4, 80(r1)
134         stfd  f5, 88(r1)
135         stfd  f6, 96(r1)
136         stfd  f7, 104(r1)
137         stfd  f8, 112(r1)
138         stfd  f9, 120(r1) 
139         stfd  f10, 128(r1) 
140         stfd  f11, 136(r1) 
141         stfd  f12, 144(r1) 
142         stfd  f13, 152(r1)  
144         /* set up registers for the routine that actually does the work */
145         /* get the context pointer from the trampoline */
146         mr r3,r11
147         
148         /* now load up the pointer to the result storage */
149         addi r4,r1,160
150         
151         /* now load up the pointer to the saved gpr registers */
152         addi r5,r1,200
154         /* now load up the pointer to the saved fpr registers */
155         addi r6,r1,56
157         /* now load up the pointer to the outgoing parameter  */
158         /* stack in the previous frame */
159         addi r7,r1,232
160         
161         /* make the call */
162         bl .ffi_closure_helper_DARWIN
163         nop
165         /* now r3 contains the return type */
166         /* so use it to look up in a table */
167         /* so we know how to deal with each type */
169         /* look up the proper starting point in table  */
170         /* by using return type as offset */
171         addi r5,r1,160          /* get pointer to results area */
172         lwz r4,LC..60(2)        /* get address of jump table */
173         slwi r3,r3,2            /* now multiply return type by 4 */
174         lwzx r3,r4,r3           /* get the contents of that table value */
175         add r3,r3,r4            /* add contents of table to table address */
176         mtctr r3
177         bctr                    /* jump to it */
179 L..60:
180         .long L..44-L..60    /* FFI_TYPE_VOID */
181         .long L..50-L..60    /* FFI_TYPE_INT */
182         .long L..47-L..60    /* FFI_TYPE_FLOAT */
183         .long L..46-L..60    /* FFI_TYPE_DOUBLE */
184         .long L..46-L..60    /* FFI_TYPE_LONGDOUBLE */
185         .long L..56-L..60    /* FFI_TYPE_UINT8 */
186         .long L..55-L..60    /* FFI_TYPE_SINT8 */
187         .long L..58-L..60    /* FFI_TYPE_UINT16 */
188         .long L..57-L..60    /* FFI_TYPE_SINT16 */
189         .long L..50-L..60    /* FFI_TYPE_UINT32 */
190         .long L..50-L..60    /* FFI_TYPE_SINT32 */
191         .long L..48-L..60    /* FFI_TYPE_UINT64 */
192         .long L..48-L..60    /* FFI_TYPE_SINT64 */
193         .long L..44-L..60    /* FFI_TYPE_STRUCT */
194         .long L..50-L..60    /* FFI_TYPE_POINTER */
197 /* case double */
198 L..46:   
199         lfd f1,0(r5)
200         b L..44
202 /* case float */
203 L..47:
204         lfs f1,0(r5)
205         b L..44
206         
207 /* case long long */
208 L..48:
209         lwz r3,0(r5)
210         lwz r4,4(r5)
211         b L..44
212         
213 /* case default / int32 / pointer */
214 L..50:
215         lwz r3,0(r5)
216         b L..44
217         
218 /* case signed int8      */
219 L..55:
220         addi r5,r5,3
221         lbz r3,0(r5)
222         slwi r3,r3,24
223         srawi r3,r3,24
224         b L..44
226 /* case unsigned int8    */
227 L..56:
228         addi r5,r5,3
229         lbz r3,0(r5)
230         b L..44
232 /* case signed int16 */
233 L..57:
234         addi r5,r5,2
235         lhz r3,0(r5)
236         extsh r3,r3
237         b L..44
239 /* case unsigned int16 */
240 L..58:  
241         addi r5,r5,2
242         lhz r3,0(r5)
244 /* case void / done      */
245 L..44:
246         
247         addi r1,r1,176          /* restore stack pointer */
248         lwz r0,8(r1)            /* get return address */
249         mtlr r0                 /* reset link register */
250         blr
251         
252 /* END(ffi_closure_ASM) */