1 /* -----------------------------------------------------------------------
2 darwin_closure.S - Copyright (c) 2002, 2003, 2004, Free Software Foundation,
3 Inc. based on ppc_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 ----------------------------------------------------------------------- */
30 #if defined(__ppc64__)
31 #define MODE_CHOICE(x, y) y
33 #define MODE_CHOICE(x, y) x
36 #define lgu MODE_CHOICE(lwzu, ldu)
38 #define g_long MODE_CHOICE(long, quad) /* usage is ".g_long" */
40 #define LOG2_GPR_BYTES MODE_CHOICE(2,3) /* log2(GPR_BYTES) */
42 .file "darwin_closure.S"
45 .globl _ffi_closure_ASM
51 mflr r0 /* extract return address */
52 stw r0,8(r1) /* save the return address */
54 /* 24 Bytes (Linkage Area)
55 32 Bytes (outgoing parameter area, always reserved)
56 104 Bytes (13*8 from FPR)
60 stwu r1,-176(r1) /* skip over caller save area
61 keep stack aligned to 16. */
63 /* We want to build up an area for the parameters passed
64 in registers. (both floating point and integer) */
66 /* We store gpr 3 to gpr 10 (aligned to 4)
67 in the parents outgoing area. */
77 /* We save fpr 1 to fpr 13. (aligned to 8) */
92 /* Set up registers for the routine that actually does the work
93 get the context pointer from the trampoline. */
96 /* Now load up the pointer to the result storage. */
99 /* Now load up the pointer to the saved gpr registers. */
102 /* Now load up the pointer to the saved fpr registers. */
106 bl Lffi_closure_helper_DARWIN$stub
108 /* Now r3 contains the return type
109 so use it to look up in a table
110 so we know how to deal with each type. */
112 /* Look up the proper starting point in table
113 by using return type as offset. */
114 addi r5,r1,160 /* Get pointer to results area. */
115 bl Lget_ret_type0_addr /* Get pointer to Lret_type0 into LR. */
116 mflr r4 /* Move to r4. */
117 slwi r3,r3,4 /* Now multiply return type by 16. */
118 add r3,r3,r4 /* Add contents of table to table address. */
120 bctr /* Jump to it. */
122 /* Each of the ret_typeX code fragments has to be exactly 16 bytes long
123 (4 instructions). For cache effectiveness we align to a 16 byte boundary
134 /* case FFI_TYPE_VOID */
141 /* case FFI_TYPE_INT */
148 /* case FFI_TYPE_FLOAT */
155 /* case FFI_TYPE_DOUBLE */
162 /* case FFI_TYPE_LONGDOUBLE */
169 /* case FFI_TYPE_UINT8 */
176 /* case FFI_TYPE_SINT8 */
183 /* case FFI_TYPE_UINT16 */
190 /* case FFI_TYPE_SINT16 */
197 /* case FFI_TYPE_UINT32 */
204 /* case FFI_TYPE_SINT32 */
211 /* case FFI_TYPE_UINT64 */
218 /* case FFI_TYPE_SINT64 */
225 /* case FFI_TYPE_STRUCT */
232 /* case FFI_TYPE_POINTER */
241 addi r1,r1,176 /* Restore stack pointer. */
242 lwz r0,8(r1) /* Get return address. */
243 mtlr r0 /* Reset link register. */
246 /* END(ffi_closure_ASM) */
249 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
251 .set L$set$0,LECIE1-LSCIE1
252 .long L$set$0 ; Length of Common Information Entry
254 .long 0x0 ; CIE Identifier Tag
255 .byte 0x1 ; CIE Version
256 .ascii "zR\0" ; CIE Augmentation
257 .byte 0x1 ; uleb128 0x1; CIE Code Alignment Factor
258 .byte 0x7c ; sleb128 -4; CIE Data Alignment Factor
259 .byte 0x41 ; CIE RA Column
260 .byte 0x1 ; uleb128 0x1; Augmentation size
261 .byte 0x90 ; FDE Encoding (indirect pcrel)
262 .byte 0xc ; DW_CFA_def_cfa
263 .byte 0x1 ; uleb128 0x1
264 .byte 0x0 ; uleb128 0x0
265 .align LOG2_GPR_BYTES
267 .globl _ffi_closure_ASM.eh
270 .set L$set$1,LEFDE1-LASFDE1
271 .long L$set$1 ; FDE Length
274 .long LASFDE1-EH_frame1 ; FDE CIE offset
275 .g_long LLFB1$non_lazy_ptr-. ; FDE initial location
276 .set L$set$3,LFE1-LFB1
277 .g_long L$set$3 ; FDE address range
278 .byte 0x0 ; uleb128 0x0; Augmentation size
279 .byte 0x4 ; DW_CFA_advance_loc4
280 .set L$set$3,LCFI1-LCFI0
282 .byte 0xe ; DW_CFA_def_cfa_offset
283 .byte 176,1 ; uleb128 176
284 .byte 0x4 ; DW_CFA_advance_loc4
285 .set L$set$4,LCFI0-LFB1
287 .byte 0x11 ; DW_CFA_offset_extended_sf
288 .byte 0x41 ; uleb128 0x41
289 .byte 0x7e ; sleb128 -2
290 .align LOG2_GPR_BYTES
293 .align LOG2_GPR_BYTES
295 .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
296 .align LOG2_GPR_BYTES
297 Lffi_closure_helper_DARWIN$stub:
299 .indirect_symbol _ffi_closure_helper_DARWIN
301 bcl 20,31,LO$ffi_closure_helper_DARWIN
302 LO$ffi_closure_helper_DARWIN:
304 addis r11,r11,ha16(L_ffi_closure_helper_DARWIN$lazy_ptr - LO$ffi_closure_helper_DARWIN)
306 lgu r12,lo16(L_ffi_closure_helper_DARWIN$lazy_ptr - LO$ffi_closure_helper_DARWIN)(r11)
310 L_ffi_closure_helper_DARWIN$lazy_ptr:
311 .indirect_symbol _ffi_closure_helper_DARWIN
312 .g_long dyld_stub_binding_helper
315 .align LOG2_GPR_BYTES