1 /* -----------------------------------------------------------------------
2 aix_closure.S - Copyright (c) 2002, 2003, 2009 Free Software Foundation, Inc.
3 based on darwin_closure.S
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 ----------------------------------------------------------------------- */
83 #define JUMPTARGET(name) name
94 .globl ffi_closure_ASM
95 .globl .ffi_closure_ASM
96 .csect ffi_closure_ASM[DS]
99 .llong .ffi_closure_ASM, TOC[tc0], 0
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) */
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 */
149 /* now load up the pointer to the result storage */
152 /* now load up the pointer to the saved gpr registers */
155 /* now load up the pointer to the saved fpr registers */
159 bl .ffi_closure_helper_DARWIN
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 */
174 bctr /* jump to it */
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 */
210 /* case long long / pointer */
220 /* case int / sint32 */
225 /* case signed int8 */
231 /* case unsigned int8 */
236 /* case signed int16 */
241 /* case unsigned int16 */
245 /* case void / done */
247 addi r1,r1,240 /* restore stack pointer */
248 ld r0,16(r1) /* get return address */
249 mtlr r0 /* reset link register */
252 #else /* ! __64BIT__ */
254 .long .ffi_closure_ASM, TOC[tc0], 0
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) */
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 */
284 /* next save fpr 1 to fpr 13 (aligned to 8) */
299 /* set up registers for the routine that actually does the work */
300 /* get the context pointer from the trampoline */
303 /* now load up the pointer to the result storage */
306 /* now load up the pointer to the saved gpr registers */
309 /* now load up the pointer to the saved fpr registers */
313 bl .ffi_closure_helper_DARWIN
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 */
328 bctr /* jump to it */
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 */
370 /* case default / int32 / pointer */
375 /* case signed int8 */
381 /* case unsigned int8 */
386 /* case signed int16 */
391 /* case unsigned int16 */
395 /* case void / done */
397 addi r1,r1,176 /* restore stack pointer */
398 lwz r0,8(r1) /* get return address */
399 mtlr r0 /* reset link register */
402 /* END(ffi_closure_ASM) */