/Modules/_ctypes/libffi_osx/x86/x86-darwin.S

http://unladen-swallow.googlecode.com/ · Assembly · 418 lines · 333 code · 40 blank · 45 comment · 0 complexity · a14fafa0e7722d388cc39d15db9182fc MD5 · raw file

  1. #ifdef __i386__
  2. /* -----------------------------------------------------------------------
  3. darwin.S - Copyright (c) 1996, 1998, 2001, 2002, 2003 Red Hat, Inc.
  4. X86 Foreign Function Interface
  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 CYGNUS SOLUTIONS 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. /*
  23. * This file is based on sysv.S and then hacked up by Ronald who hasn't done
  24. * assembly programming in 8 years.
  25. */
  26. #ifndef __x86_64__
  27. #define LIBFFI_ASM
  28. #include <fficonfig.h>
  29. #include <ffi.h>
  30. #ifdef PyObjC_STRICT_DEBUGGING
  31. /* XXX: Debugging of stack alignment, to be removed */
  32. #define ASSERT_STACK_ALIGNED movdqa -16(%esp), %xmm0
  33. #else
  34. #define ASSERT_STACK_ALIGNED
  35. #endif
  36. .text
  37. .globl _ffi_prep_args
  38. .align 4
  39. .globl _ffi_call_SYSV
  40. _ffi_call_SYSV:
  41. LFB1:
  42. pushl %ebp
  43. LCFI0:
  44. movl %esp,%ebp
  45. LCFI1:
  46. subl $8,%esp
  47. /* Make room for all of the new args. */
  48. movl 16(%ebp),%ecx
  49. subl %ecx,%esp
  50. movl %esp,%eax
  51. /* Place all of the ffi_prep_args in position */
  52. subl $8,%esp
  53. pushl 12(%ebp)
  54. pushl %eax
  55. call *8(%ebp)
  56. /* Return stack to previous state and call the function */
  57. addl $16,%esp
  58. call *28(%ebp)
  59. /* Remove the space we pushed for the args */
  60. movl 16(%ebp),%ecx
  61. addl %ecx,%esp
  62. /* Load %ecx with the return type code */
  63. movl 20(%ebp),%ecx
  64. /* If the return value pointer is NULL, assume no return value. */
  65. cmpl $0,24(%ebp)
  66. jne Lretint
  67. /* Even if there is no space for the return value, we are
  68. obliged to handle floating-point values. */
  69. cmpl $FFI_TYPE_FLOAT,%ecx
  70. jne Lnoretval
  71. fstp %st(0)
  72. jmp Lepilogue
  73. Lretint:
  74. cmpl $FFI_TYPE_INT,%ecx
  75. jne Lretfloat
  76. /* Load %ecx with the pointer to storage for the return value */
  77. movl 24(%ebp),%ecx
  78. movl %eax,0(%ecx)
  79. jmp Lepilogue
  80. Lretfloat:
  81. cmpl $FFI_TYPE_FLOAT,%ecx
  82. jne Lretdouble
  83. /* Load %ecx with the pointer to storage for the return value */
  84. movl 24(%ebp),%ecx
  85. fstps (%ecx)
  86. jmp Lepilogue
  87. Lretdouble:
  88. cmpl $FFI_TYPE_DOUBLE,%ecx
  89. jne Lretlongdouble
  90. /* Load %ecx with the pointer to storage for the return value */
  91. movl 24(%ebp),%ecx
  92. fstpl (%ecx)
  93. jmp Lepilogue
  94. Lretlongdouble:
  95. cmpl $FFI_TYPE_LONGDOUBLE,%ecx
  96. jne Lretint64
  97. /* Load %ecx with the pointer to storage for the return value */
  98. movl 24(%ebp),%ecx
  99. fstpt (%ecx)
  100. jmp Lepilogue
  101. Lretint64:
  102. cmpl $FFI_TYPE_SINT64,%ecx
  103. jne Lretstruct1b
  104. /* Load %ecx with the pointer to storage for the return value */
  105. movl 24(%ebp),%ecx
  106. movl %eax,0(%ecx)
  107. movl %edx,4(%ecx)
  108. jmp Lepilogue
  109. Lretstruct1b:
  110. cmpl $FFI_TYPE_SINT8,%ecx
  111. jne Lretstruct2b
  112. /* Load %ecx with the pointer to storage for the return value */
  113. movl 24(%ebp),%ecx
  114. movb %al,0(%ecx)
  115. jmp Lepilogue
  116. Lretstruct2b:
  117. cmpl $FFI_TYPE_SINT16,%ecx
  118. jne Lretstruct
  119. /* Load %ecx with the pointer to storage for the return value */
  120. movl 24(%ebp),%ecx
  121. movw %ax,0(%ecx)
  122. jmp Lepilogue
  123. Lretstruct:
  124. cmpl $FFI_TYPE_STRUCT,%ecx
  125. jne Lnoretval
  126. /* Nothing to do! */
  127. addl $4,%esp
  128. popl %ebp
  129. ret
  130. Lnoretval:
  131. Lepilogue:
  132. addl $8,%esp
  133. movl %ebp,%esp
  134. popl %ebp
  135. ret
  136. LFE1:
  137. .ffi_call_SYSV_end:
  138. .align 4
  139. FFI_HIDDEN (ffi_closure_SYSV)
  140. .globl _ffi_closure_SYSV
  141. _ffi_closure_SYSV:
  142. LFB2:
  143. pushl %ebp
  144. LCFI2:
  145. movl %esp, %ebp
  146. LCFI3:
  147. subl $56, %esp
  148. leal -40(%ebp), %edx
  149. movl %edx, -12(%ebp) /* resp */
  150. leal 8(%ebp), %edx
  151. movl %edx, 4(%esp) /* args = __builtin_dwarf_cfa () */
  152. leal -12(%ebp), %edx
  153. movl %edx, (%esp) /* &resp */
  154. movl %ebx, 8(%esp)
  155. LCFI7:
  156. call L_ffi_closure_SYSV_inner$stub
  157. movl 8(%esp), %ebx
  158. movl -12(%ebp), %ecx
  159. cmpl $FFI_TYPE_INT, %eax
  160. je Lcls_retint
  161. cmpl $FFI_TYPE_FLOAT, %eax
  162. je Lcls_retfloat
  163. cmpl $FFI_TYPE_DOUBLE, %eax
  164. je Lcls_retdouble
  165. cmpl $FFI_TYPE_LONGDOUBLE, %eax
  166. je Lcls_retldouble
  167. cmpl $FFI_TYPE_SINT64, %eax
  168. je Lcls_retllong
  169. cmpl $FFI_TYPE_SINT8, %eax
  170. je Lcls_retstruct1
  171. cmpl $FFI_TYPE_SINT16, %eax
  172. je Lcls_retstruct2
  173. cmpl $FFI_TYPE_STRUCT, %eax
  174. je Lcls_retstruct
  175. Lcls_epilogue:
  176. movl %ebp, %esp
  177. popl %ebp
  178. ret
  179. Lcls_retint:
  180. movl (%ecx), %eax
  181. jmp Lcls_epilogue
  182. Lcls_retfloat:
  183. flds (%ecx)
  184. jmp Lcls_epilogue
  185. Lcls_retdouble:
  186. fldl (%ecx)
  187. jmp Lcls_epilogue
  188. Lcls_retldouble:
  189. fldt (%ecx)
  190. jmp Lcls_epilogue
  191. Lcls_retllong:
  192. movl (%ecx), %eax
  193. movl 4(%ecx), %edx
  194. jmp Lcls_epilogue
  195. Lcls_retstruct1:
  196. movsbl (%ecx), %eax
  197. jmp Lcls_epilogue
  198. Lcls_retstruct2:
  199. movswl (%ecx), %eax
  200. jmp Lcls_epilogue
  201. Lcls_retstruct:
  202. lea -8(%ebp),%esp
  203. movl %ebp, %esp
  204. popl %ebp
  205. ret $4
  206. LFE2:
  207. #if !FFI_NO_RAW_API
  208. #define RAW_CLOSURE_CIF_OFFSET ((FFI_TRAMPOLINE_SIZE + 3) & ~3)
  209. #define RAW_CLOSURE_FUN_OFFSET (RAW_CLOSURE_CIF_OFFSET + 4)
  210. #define RAW_CLOSURE_USER_DATA_OFFSET (RAW_CLOSURE_FUN_OFFSET + 4)
  211. #define CIF_FLAGS_OFFSET 20
  212. .align 4
  213. FFI_HIDDEN (ffi_closure_raw_SYSV)
  214. .globl _ffi_closure_raw_SYSV
  215. _ffi_closure_raw_SYSV:
  216. LFB3:
  217. pushl %ebp
  218. LCFI4:
  219. movl %esp, %ebp
  220. LCFI5:
  221. pushl %esi
  222. LCFI6:
  223. subl $36, %esp
  224. movl RAW_CLOSURE_CIF_OFFSET(%eax), %esi /* closure->cif */
  225. movl RAW_CLOSURE_USER_DATA_OFFSET(%eax), %edx /* closure->user_data */
  226. movl %edx, 12(%esp) /* user_data */
  227. leal 8(%ebp), %edx /* __builtin_dwarf_cfa () */
  228. movl %edx, 8(%esp) /* raw_args */
  229. leal -24(%ebp), %edx
  230. movl %edx, 4(%esp) /* &res */
  231. movl %esi, (%esp) /* cif */
  232. call *RAW_CLOSURE_FUN_OFFSET(%eax) /* closure->fun */
  233. movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
  234. cmpl $FFI_TYPE_INT, %eax
  235. je Lrcls_retint
  236. cmpl $FFI_TYPE_FLOAT, %eax
  237. je Lrcls_retfloat
  238. cmpl $FFI_TYPE_DOUBLE, %eax
  239. je Lrcls_retdouble
  240. cmpl $FFI_TYPE_LONGDOUBLE, %eax
  241. je Lrcls_retldouble
  242. cmpl $FFI_TYPE_SINT64, %eax
  243. je Lrcls_retllong
  244. Lrcls_epilogue:
  245. addl $36, %esp
  246. popl %esi
  247. popl %ebp
  248. ret
  249. Lrcls_retint:
  250. movl -24(%ebp), %eax
  251. jmp Lrcls_epilogue
  252. Lrcls_retfloat:
  253. flds -24(%ebp)
  254. jmp Lrcls_epilogue
  255. Lrcls_retdouble:
  256. fldl -24(%ebp)
  257. jmp Lrcls_epilogue
  258. Lrcls_retldouble:
  259. fldt -24(%ebp)
  260. jmp Lrcls_epilogue
  261. Lrcls_retllong:
  262. movl -24(%ebp), %eax
  263. movl -20(%ebp), %edx
  264. jmp Lrcls_epilogue
  265. LFE3:
  266. #endif
  267. .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
  268. L_ffi_closure_SYSV_inner$stub:
  269. .indirect_symbol _ffi_closure_SYSV_inner
  270. hlt ; hlt ; hlt ; hlt ; hlt
  271. .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
  272. EH_frame1:
  273. .set L$set$0,LECIE1-LSCIE1
  274. .long L$set$0
  275. LSCIE1:
  276. .long 0x0
  277. .byte 0x1
  278. .ascii "zR\0"
  279. .byte 0x1
  280. .byte 0x7c
  281. .byte 0x8
  282. .byte 0x1
  283. .byte 0x10
  284. .byte 0xc
  285. .byte 0x5
  286. .byte 0x4
  287. .byte 0x88
  288. .byte 0x1
  289. .align 2
  290. LECIE1:
  291. .globl _ffi_call_SYSV.eh
  292. _ffi_call_SYSV.eh:
  293. LSFDE1:
  294. .set L$set$1,LEFDE1-LASFDE1
  295. .long L$set$1
  296. LASFDE1:
  297. .long LASFDE1-EH_frame1
  298. .long LFB1-.
  299. .set L$set$2,LFE1-LFB1
  300. .long L$set$2
  301. .byte 0x0
  302. .byte 0x4
  303. .set L$set$3,LCFI0-LFB1
  304. .long L$set$3
  305. .byte 0xe
  306. .byte 0x8
  307. .byte 0x84
  308. .byte 0x2
  309. .byte 0x4
  310. .set L$set$4,LCFI1-LCFI0
  311. .long L$set$4
  312. .byte 0xd
  313. .byte 0x4
  314. .align 2
  315. LEFDE1:
  316. .globl _ffi_closure_SYSV.eh
  317. _ffi_closure_SYSV.eh:
  318. LSFDE2:
  319. .set L$set$5,LEFDE2-LASFDE2
  320. .long L$set$5
  321. LASFDE2:
  322. .long LASFDE2-EH_frame1
  323. .long LFB2-.
  324. .set L$set$6,LFE2-LFB2
  325. .long L$set$6
  326. .byte 0x0
  327. .byte 0x4
  328. .set L$set$7,LCFI2-LFB2
  329. .long L$set$7
  330. .byte 0xe
  331. .byte 0x8
  332. .byte 0x84
  333. .byte 0x2
  334. .byte 0x4
  335. .set L$set$8,LCFI3-LCFI2
  336. .long L$set$8
  337. .byte 0xd
  338. .byte 0x4
  339. .align 2
  340. LEFDE2:
  341. #if !FFI_NO_RAW_API
  342. .globl _ffi_closure_raw_SYSV.eh
  343. _ffi_closure_raw_SYSV.eh:
  344. LSFDE3:
  345. .set L$set$10,LEFDE3-LASFDE3
  346. .long L$set$10
  347. LASFDE3:
  348. .long LASFDE3-EH_frame1
  349. .long LFB3-.
  350. .set L$set$11,LFE3-LFB3
  351. .long L$set$11
  352. .byte 0x0
  353. .byte 0x4
  354. .set L$set$12,LCFI4-LFB3
  355. .long L$set$12
  356. .byte 0xe
  357. .byte 0x8
  358. .byte 0x84
  359. .byte 0x2
  360. .byte 0x4
  361. .set L$set$13,LCFI5-LCFI4
  362. .long L$set$13
  363. .byte 0xd
  364. .byte 0x4
  365. .byte 0x4
  366. .set L$set$14,LCFI6-LCFI5
  367. .long L$set$14
  368. .byte 0x85
  369. .byte 0x3
  370. .align 2
  371. LEFDE3:
  372. #endif
  373. #endif /* ifndef __x86_64__ */
  374. #endif /* defined __i386__ */