1/* ----------------------------------------------------------------------- 2 aix_closure.S - Copyright (c) 2002 2003 Free Software Foundation, Inc. 3 based on darwin_closure.S 4 5 PowerPC Assembly glue. 6 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: 14 15 The above copyright notice and this permission notice shall be included 16 in all copies or substantial portions of the Software. 17 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 ----------------------------------------------------------------------- */ 26 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 81 82#define LIBFFI_ASM 83#define JUMPTARGET(name) name 84#define L(x) x 85 .file "aix_closure.S" 86 .toc 87LC..60: 88 .tc L..60[TC],L..60 89 .csect .text[PR] 90 .align 2 91 92.csect .text[PR] 93 .align 2 94 .globl ffi_closure_ASM 95 .globl .ffi_closure_ASM 96.csect ffi_closure_ASM[DS] 97 98ffi_closure_ASM: 99 .long .ffi_closure_ASM, TOC[tc0], 0 100 .csect .text[PR] 101.ffi_closure_ASM: 102 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 */ 114 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) 128 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) 143 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 153 154 /* now load up the pointer to the saved fpr registers */ 155 addi r6,r1,56 156 157 /* make the call */ 158 bl .ffi_closure_helper_DARWIN 159 nop 160 161 /* now r3 contains the return type */ 162 /* so use it to look up in a table */ 163 /* so we know how to deal with each type */ 164 165 /* look up the proper starting point in table */ 166 /* by using return type as offset */ 167 addi r5,r1,160 /* get pointer to results area */ 168 lwz r4,LC..60(2) /* get address of jump table */ 169 slwi r3,r3,2 /* now multiply return type by 4 */ 170 lwzx r3,r4,r3 /* get the contents of that table value */ 171 add r3,r3,r4 /* add contents of table to table address */ 172 mtctr r3 173 bctr /* jump to it */ 174 175L..60: 176 .long L..44-L..60 /* FFI_TYPE_VOID */ 177 .long L..50-L..60 /* FFI_TYPE_INT */ 178 .long L..47-L..60 /* FFI_TYPE_FLOAT */ 179 .long L..46-L..60 /* FFI_TYPE_DOUBLE */ 180 .long L..46-L..60 /* FFI_TYPE_LONGDOUBLE */ 181 .long L..56-L..60 /* FFI_TYPE_UINT8 */ 182 .long L..55-L..60 /* FFI_TYPE_SINT8 */ 183 .long L..58-L..60 /* FFI_TYPE_UINT16 */ 184 .long L..57-L..60 /* FFI_TYPE_SINT16 */ 185 .long L..50-L..60 /* FFI_TYPE_UINT32 */ 186 .long L..50-L..60 /* FFI_TYPE_SINT32 */ 187 .long L..48-L..60 /* FFI_TYPE_UINT64 */ 188 .long L..48-L..60 /* FFI_TYPE_SINT64 */ 189 .long L..44-L..60 /* FFI_TYPE_STRUCT */ 190 .long L..50-L..60 /* FFI_TYPE_POINTER */ 191 192 193/* case double */ 194L..46: 195 lfd f1,0(r5) 196 b L..44 197 198/* case float */ 199L..47: 200 lfs f1,0(r5) 201 b L..44 202 203/* case long long */ 204L..48: 205 lwz r3,0(r5) 206 lwz r4,4(r5) 207 b L..44 208 209/* case default / int32 / pointer */ 210L..50: 211 lwz r3,0(r5) 212 b L..44 213 214/* case signed int8 */ 215L..55: 216 addi r5,r5,3 217 lbz r3,0(r5) 218 slwi r3,r3,24 219 srawi r3,r3,24 220 b L..44 221 222/* case unsigned int8 */ 223L..56: 224 addi r5,r5,3 225 lbz r3,0(r5) 226 b L..44 227 228/* case signed int16 */ 229L..57: 230 addi r5,r5,2 231 lhz r3,0(r5) 232 extsh r3,r3 233 b L..44 234 235/* case unsigned int16 */ 236L..58: 237 addi r5,r5,2 238 lhz r3,0(r5) 239 240/* case void / done */ 241L..44: 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