1#ifdef __ppc__ 2/* ----------------------------------------------------------------------- 3 darwin_closure.S - Copyright (c) 2002, 2003, 2004, Free Software Foundation, 4 Inc. based on ppc_closure.S 5 6 PowerPC Assembly glue. 7 8 Permission is hereby granted, free of charge, to any person obtaining 9 a copy of this software and associated documentation files (the 10 ``Software''), to deal in the Software without restriction, including 11 without limitation the rights to use, copy, modify, merge, publish, 12 distribute, sublicense, and/or sell copies of the Software, and to 13 permit persons to whom the Software is furnished to do so, subject to 14 the following conditions: 15 16 The above copyright notice and this permission notice shall be included 17 in all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR 23 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 OTHER DEALINGS IN THE SOFTWARE. 26 ----------------------------------------------------------------------- */ 27 28#define LIBFFI_ASM 29#define L(x) x 30 31#if defined(__ppc64__) 32#define MODE_CHOICE(x, y) y 33#else 34#define MODE_CHOICE(x, y) x 35#endif 36 37#define lgu MODE_CHOICE(lwzu, ldu) 38 39#define g_long MODE_CHOICE(long, quad) /* usage is ".g_long" */ 40 41#define LOG2_GPR_BYTES MODE_CHOICE(2,3) /* log2(GPR_BYTES) */ 42 43 .file "darwin_closure.S" 44.text 45 .align LOG2_GPR_BYTES 46.globl _ffi_closure_ASM 47 48.text 49 .align LOG2_GPR_BYTES 50_ffi_closure_ASM: 51LFB1: 52 mflr r0 /* extract return address */ 53 stw r0,8(r1) /* save the return address */ 54LCFI0: 55 /* 24 Bytes (Linkage Area) 56 32 Bytes (outgoing parameter area, always reserved) 57 104 Bytes (13*8 from FPR) 58 16 Bytes (result) 59 176 Bytes */ 60 61 stwu r1,-176(r1) /* skip over caller save area 62 keep stack aligned to 16. */ 63LCFI1: 64 /* We want to build up an area for the parameters passed 65 in registers. (both floating point and integer) */ 66 67 /* We store gpr 3 to gpr 10 (aligned to 4) 68 in the parents outgoing area. */ 69 stw r3,200(r1) 70 stw r4,204(r1) 71 stw r5,208(r1) 72 stw r6,212(r1) 73 stw r7,216(r1) 74 stw r8,220(r1) 75 stw r9,224(r1) 76 stw r10,228(r1) 77 78 /* We save fpr 1 to fpr 13. (aligned to 8) */ 79 stfd f1,56(r1) 80 stfd f2,64(r1) 81 stfd f3,72(r1) 82 stfd f4,80(r1) 83 stfd f5,88(r1) 84 stfd f6,96(r1) 85 stfd f7,104(r1) 86 stfd f8,112(r1) 87 stfd f9,120(r1) 88 stfd f10,128(r1) 89 stfd f11,136(r1) 90 stfd f12,144(r1) 91 stfd f13,152(r1) 92 93 /* Set up registers for the routine that actually does the work 94 get the context pointer from the trampoline. */ 95 mr r3,r11 96 97 /* Now load up the pointer to the result storage. */ 98 addi r4,r1,160 99 100 /* Now load up the pointer to the saved gpr registers. */ 101 addi r5,r1,200 102 103 /* Now load up the pointer to the saved fpr registers. */ 104 addi r6,r1,56 105 106 /* Make the call. */ 107 bl Lffi_closure_helper_DARWIN$stub 108 109 /* Now r3 contains the return type 110 so use it to look up in a table 111 so we know how to deal with each type. */ 112 113 /* Look up the proper starting point in table 114 by using return type as offset. */ 115 addi r5,r1,160 /* Get pointer to results area. */ 116 bl Lget_ret_type0_addr /* Get pointer to Lret_type0 into LR. */ 117 mflr r4 /* Move to r4. */ 118 slwi r3,r3,4 /* Now multiply return type by 16. */ 119 add r3,r3,r4 /* Add contents of table to table address. */ 120 mtctr r3 121 bctr /* Jump to it. */ 122LFE1: 123/* Each of the ret_typeX code fragments has to be exactly 16 bytes long 124 (4 instructions). For cache effectiveness we align to a 16 byte boundary 125 first. */ 126 127 .align 4 128 129 nop 130 nop 131 nop 132Lget_ret_type0_addr: 133 blrl 134 135/* case FFI_TYPE_VOID */ 136Lret_type0: 137 b Lfinish 138 nop 139 nop 140 nop 141 142/* case FFI_TYPE_INT */ 143Lret_type1: 144 lwz r3,0(r5) 145 b Lfinish 146 nop 147 nop 148 149/* case FFI_TYPE_FLOAT */ 150Lret_type2: 151 lfs f1,0(r5) 152 b Lfinish 153 nop 154 nop 155 156/* case FFI_TYPE_DOUBLE */ 157Lret_type3: 158 lfd f1,0(r5) 159 b Lfinish 160 nop 161 nop 162 163/* case FFI_TYPE_LONGDOUBLE */ 164Lret_type4: 165 lfd f1,0(r5) 166 lfd f2,8(r5) 167 b Lfinish 168 nop 169 170/* case FFI_TYPE_UINT8 */ 171Lret_type5: 172 lbz r3,3(r5) 173 b Lfinish 174 nop 175 nop 176 177/* case FFI_TYPE_SINT8 */ 178Lret_type6: 179 lbz r3,3(r5) 180 extsb r3,r3 181 b Lfinish 182 nop 183 184/* case FFI_TYPE_UINT16 */ 185Lret_type7: 186 lhz r3,2(r5) 187 b Lfinish 188 nop 189 nop 190 191/* case FFI_TYPE_SINT16 */ 192Lret_type8: 193 lha r3,2(r5) 194 b Lfinish 195 nop 196 nop 197 198/* case FFI_TYPE_UINT32 */ 199Lret_type9: 200 lwz r3,0(r5) 201 b Lfinish 202 nop 203 nop 204 205/* case FFI_TYPE_SINT32 */ 206Lret_type10: 207 lwz r3,0(r5) 208 b Lfinish 209 nop 210 nop 211 212/* case FFI_TYPE_UINT64 */ 213Lret_type11: 214 lwz r3,0(r5) 215 lwz r4,4(r5) 216 b Lfinish 217 nop 218 219/* case FFI_TYPE_SINT64 */ 220Lret_type12: 221 lwz r3,0(r5) 222 lwz r4,4(r5) 223 b Lfinish 224 nop 225 226/* case FFI_TYPE_STRUCT */ 227Lret_type13: 228 b Lfinish 229 nop 230 nop 231 nop 232 233/* case FFI_TYPE_POINTER */ 234Lret_type14: 235 lwz r3,0(r5) 236 b Lfinish 237 nop 238 nop 239 240/* case done */ 241Lfinish: 242 addi r1,r1,176 /* Restore stack pointer. */ 243 lwz r0,8(r1) /* Get return address. */ 244 mtlr r0 /* Reset link register. */ 245 blr 246 247/* END(ffi_closure_ASM) */ 248 249.data 250.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms 251EH_frame1: 252 .set L$set$0,LECIE1-LSCIE1 253 .long L$set$0 ; Length of Common Information Entry 254LSCIE1: 255 .long 0x0 ; CIE Identifier Tag 256 .byte 0x1 ; CIE Version 257 .ascii "zR\0" ; CIE Augmentation 258 .byte 0x1 ; uleb128 0x1; CIE Code Alignment Factor 259 .byte 0x7c ; sleb128 -4; CIE Data Alignment Factor 260 .byte 0x41 ; CIE RA Column 261 .byte 0x1 ; uleb128 0x1; Augmentation size 262 .byte 0x90 ; FDE Encoding (indirect pcrel) 263 .byte 0xc ; DW_CFA_def_cfa 264 .byte 0x1 ; uleb128 0x1 265 .byte 0x0 ; uleb128 0x0 266 .align LOG2_GPR_BYTES 267LECIE1: 268.globl _ffi_closure_ASM.eh 269_ffi_closure_ASM.eh: 270LSFDE1: 271 .set L$set$1,LEFDE1-LASFDE1 272 .long L$set$1 ; FDE Length 273 274LASFDE1: 275 .long LASFDE1-EH_frame1 ; FDE CIE offset 276 .g_long LLFB1$non_lazy_ptr-. ; FDE initial location 277 .set L$set$3,LFE1-LFB1 278 .g_long L$set$3 ; FDE address range 279 .byte 0x0 ; uleb128 0x0; Augmentation size 280 .byte 0x4 ; DW_CFA_advance_loc4 281 .set L$set$3,LCFI1-LCFI0 282 .long L$set$3 283 .byte 0xe ; DW_CFA_def_cfa_offset 284 .byte 176,1 ; uleb128 176 285 .byte 0x4 ; DW_CFA_advance_loc4 286 .set L$set$4,LCFI0-LFB1 287 .long L$set$4 288 .byte 0x11 ; DW_CFA_offset_extended_sf 289 .byte 0x41 ; uleb128 0x41 290 .byte 0x7e ; sleb128 -2 291 .align LOG2_GPR_BYTES 292LEFDE1: 293.data 294 .align LOG2_GPR_BYTES 295LDFCM0: 296.section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32 297 .align LOG2_GPR_BYTES 298Lffi_closure_helper_DARWIN$stub: 299#if 1 300 .indirect_symbol _ffi_closure_helper_DARWIN 301 mflr r0 302 bcl 20,31,LO$ffi_closure_helper_DARWIN 303LO$ffi_closure_helper_DARWIN: 304 mflr r11 305 addis r11,r11,ha16(L_ffi_closure_helper_DARWIN$lazy_ptr - LO$ffi_closure_helper_DARWIN) 306 mtlr r0 307 lgu r12,lo16(L_ffi_closure_helper_DARWIN$lazy_ptr - LO$ffi_closure_helper_DARWIN)(r11) 308 mtctr r12 309 bctr 310.lazy_symbol_pointer 311L_ffi_closure_helper_DARWIN$lazy_ptr: 312 .indirect_symbol _ffi_closure_helper_DARWIN 313 .g_long dyld_stub_binding_helper 314#endif 315.data 316 .align LOG2_GPR_BYTES 317LLFB1$non_lazy_ptr: 318 .g_long LFB1 319 320#endif /* __ppc__ */ 321