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
102 /* we want to build up an area for the parameters passed */
103 /* in registers (both floating point and integer) */
105 /* we store gpr 3 to gpr 10 (aligned to 4)
106 in the parents outgoing area */
116 std r10, 48+(7*8)(r1)
117 std r0, 16(r1) /* save the return address */
120 /* 48 Bytes (Linkage Area) */
121 /* 64 Bytes (params) */
122 /* 16 Bytes (result) */
123 /* 104 Bytes (13*8 from FPR) */
124 /* 8 Bytes (alignment) */
127 stdu r1, -240(r1) /* skip over caller save area
128 keep stack aligned to 16 */
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 ld r4, LC..60(2) /* get address of jump table */
169 sldi r3, r3, 4 /* now multiply return type by 16 */
170 ld r0, 240+16(r1) /* load return address */
171 add r3, r3, r4 /* add contents of table to table address */
173 bctr /* jump to it */
175 /* Each fragment must be exactly 16 bytes long (4 instructions).
176 Align to 16 byte boundary for cache and dispatch efficiency. */
180 /* case FFI_TYPE_VOID */
186 /* case FFI_TYPE_INT */
192 /* case FFI_TYPE_FLOAT */
198 /* case FFI_TYPE_DOUBLE */
204 /* case FFI_TYPE_LONGDOUBLE */
210 /* case FFI_TYPE_UINT8 */
216 /* case FFI_TYPE_SINT8 */
222 /* case FFI_TYPE_UINT16 */
229 /* case FFI_TYPE_SINT16 */
235 /* case FFI_TYPE_UINT32 */
241 /* case FFI_TYPE_SINT32 */
247 /* case FFI_TYPE_UINT64 */
253 /* case FFI_TYPE_SINT64 */
259 /* case FFI_TYPE_STRUCT */
265 /* case FFI_TYPE_POINTER */
271 #else /* ! __64BIT__ */
273 .long .ffi_closure_ASM, TOC[tc0], 0
276 /* we want to build up an area for the parameters passed */
277 /* in registers (both floating point and integer) */
279 /* we store gpr 3 to gpr 10 (aligned to 4)
280 in the parents outgoing area */
290 stw r10, 24+(7*4)(r1)
293 /* 24 Bytes (Linkage Area) */
294 /* 32 Bytes (params) */
295 /* 16 Bytes (result) */
296 /* 104 Bytes (13*8 from FPR) */
299 stwu r1, -176(r1) /* skip over caller save area
300 keep stack aligned to 16 */
302 /* next save fpr 1 to fpr 13 (aligned to 8) */
303 stfd f1, 72+(0*8)(r1)
304 stfd f2, 72+(1*8)(r1)
305 stfd f3, 72+(2*8)(r1)
306 stfd f4, 72+(3*8)(r1)
307 stfd f5, 72+(4*8)(r1)
308 stfd f6, 72+(5*8)(r1)
309 stfd f7, 72+(6*8)(r1)
310 stfd f8, 72+(7*8)(r1)
311 stfd f9, 72+(8*8)(r1)
312 stfd f10, 72+(9*8)(r1)
313 stfd f11, 72+(10*8)(r1)
314 stfd f12, 72+(11*8)(r1)
315 stfd f13, 72+(12*8)(r1)
317 /* set up registers for the routine that actually does the work */
318 /* get the context pointer from the trampoline */
321 /* now load up the pointer to the result storage */
324 /* now load up the pointer to the saved gpr registers */
327 /* now load up the pointer to the saved fpr registers */
331 bl .ffi_closure_helper_DARWIN
334 /* now r3 contains the return type */
335 /* so use it to look up in a table */
336 /* so we know how to deal with each type */
338 /* look up the proper starting point in table */
339 /* by using return type as offset */
340 lwz r4, LC..60(2) /* get address of jump table */
341 slwi r3, r3, 4 /* now multiply return type by 4 */
342 lwz r0, 176+8(r1) /* load return address */
343 add r3, r3, r4 /* add contents of table to table address */
345 bctr /* jump to it */
347 /* Each fragment must be exactly 16 bytes long (4 instructions).
348 Align to 16 byte boundary for cache and dispatch efficiency. */
352 /* case FFI_TYPE_VOID */
358 /* case FFI_TYPE_INT */
364 /* case FFI_TYPE_FLOAT */
370 /* case FFI_TYPE_DOUBLE */
376 /* case FFI_TYPE_LONGDOUBLE */
382 /* case FFI_TYPE_UINT8 */
388 /* case FFI_TYPE_SINT8 */
394 /* case FFI_TYPE_UINT16 */
400 /* case FFI_TYPE_SINT16 */
406 /* case FFI_TYPE_UINT32 */
412 /* case FFI_TYPE_SINT32 */
418 /* case FFI_TYPE_UINT64 */
424 /* case FFI_TYPE_SINT64 */
430 /* case FFI_TYPE_STRUCT */
436 /* case FFI_TYPE_POINTER */
443 /* END(ffi_closure_ASM) */