/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S

http://unladen-swallow.googlecode.com/ · Assembly · 317 lines · 212 code · 38 blank · 67 comment · 0 complexity · 31cb78f1f10503180bd8dc1ea0076ad1 MD5 · raw file

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