/Modules/_ctypes/libffi_osx/powerpc/ppc-darwin_closure.S

http://unladen-swallow.googlecode.com/ · Assembly · 308 lines · 204 code · 41 blank · 63 comment · 3 complexity · dd6d3c34edb793cf41996baa19d94394 MD5 · raw file

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