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

http://unladen-swallow.googlecode.com/ · Assembly · 230 lines · 174 code · 16 blank · 40 comment · 5 complexity · 889b214acb97d36fa25441c00a9a0ea1 MD5 · raw file

  1. /* -----------------------------------------------------------------------
  2. sysv.S - Copyright (c) 1998 Geoffrey Keating
  3. Copyright (C) 2007 Free Software Foundation, Inc
  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,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. DEALINGS IN THE SOFTWARE.
  22. ----------------------------------------------------------------------- */
  23. #define LIBFFI_ASM
  24. #include <fficonfig.h>
  25. #include <ffi.h>
  26. #include <powerpc/asm.h>
  27. #ifndef __powerpc64__
  28. .globl ffi_prep_args_SYSV
  29. ENTRY(ffi_call_SYSV)
  30. .LFB1:
  31. /* Save the old stack pointer as AP. */
  32. mr %r8,%r1
  33. .LCFI0:
  34. /* Allocate the stack space we need. */
  35. stwux %r1,%r1,%r4
  36. /* Save registers we use. */
  37. mflr %r9
  38. stw %r28,-16(%r8)
  39. .LCFI1:
  40. stw %r29,-12(%r8)
  41. .LCFI2:
  42. stw %r30, -8(%r8)
  43. .LCFI3:
  44. stw %r31, -4(%r8)
  45. .LCFI4:
  46. stw %r9, 4(%r8)
  47. .LCFI5:
  48. /* Save arguments over call... */
  49. mr %r31,%r5 /* flags, */
  50. mr %r30,%r6 /* rvalue, */
  51. mr %r29,%r7 /* function address, */
  52. mr %r28,%r8 /* our AP. */
  53. .LCFI6:
  54. /* Call ffi_prep_args_SYSV. */
  55. mr %r4,%r1
  56. bl ffi_prep_args_SYSV@local
  57. /* Now do the call. */
  58. /* Set up cr1 with bits 4-7 of the flags. */
  59. mtcrf 0x40,%r31
  60. /* Get the address to call into CTR. */
  61. mtctr %r29
  62. /* Load all those argument registers. */
  63. lwz %r3,-16-(8*4)(%r28)
  64. lwz %r4,-16-(7*4)(%r28)
  65. lwz %r5,-16-(6*4)(%r28)
  66. lwz %r6,-16-(5*4)(%r28)
  67. bf- 5,1f
  68. nop
  69. lwz %r7,-16-(4*4)(%r28)
  70. lwz %r8,-16-(3*4)(%r28)
  71. lwz %r9,-16-(2*4)(%r28)
  72. lwz %r10,-16-(1*4)(%r28)
  73. nop
  74. 1:
  75. /* Load all the FP registers. */
  76. bf- 6,2f
  77. lfd %f1,-16-(8*4)-(8*8)(%r28)
  78. lfd %f2,-16-(8*4)-(7*8)(%r28)
  79. lfd %f3,-16-(8*4)-(6*8)(%r28)
  80. lfd %f4,-16-(8*4)-(5*8)(%r28)
  81. nop
  82. lfd %f5,-16-(8*4)-(4*8)(%r28)
  83. lfd %f6,-16-(8*4)-(3*8)(%r28)
  84. lfd %f7,-16-(8*4)-(2*8)(%r28)
  85. lfd %f8,-16-(8*4)-(1*8)(%r28)
  86. 2:
  87. /* Make the call. */
  88. bctrl
  89. /* Now, deal with the return value. */
  90. mtcrf 0x01,%r31 /* cr7 */
  91. bt- 31,L(small_struct_return_value)
  92. bt- 30,L(done_return_value)
  93. bt- 29,L(fp_return_value)
  94. stw %r3,0(%r30)
  95. bf+ 28,L(done_return_value)
  96. stw %r4,4(%r30)
  97. mtcrf 0x02,%r31 /* cr6 */
  98. bf 27,L(done_return_value)
  99. stw %r5,8(%r30)
  100. stw %r6,12(%r30)
  101. /* Fall through... */
  102. L(done_return_value):
  103. /* Restore the registers we used and return. */
  104. lwz %r9, 4(%r28)
  105. lwz %r31, -4(%r28)
  106. mtlr %r9
  107. lwz %r30, -8(%r28)
  108. lwz %r29,-12(%r28)
  109. lwz %r28,-16(%r28)
  110. lwz %r1,0(%r1)
  111. blr
  112. L(fp_return_value):
  113. bf 28,L(float_return_value)
  114. stfd %f1,0(%r30)
  115. mtcrf 0x02,%r31 /* cr6 */
  116. bf 27,L(done_return_value)
  117. stfd %f2,8(%r30)
  118. b L(done_return_value)
  119. L(float_return_value):
  120. stfs %f1,0(%r30)
  121. b L(done_return_value)
  122. L(small_struct_return_value):
  123. mtcrf 0x10,%r31 /* cr3 */
  124. bt- 15,L(smst_one_register)
  125. mtcrf 0x08,%r31 /* cr4 */
  126. bt- 16,L(smst_two_register)
  127. b L(done_return_value)
  128. L(smst_one_register):
  129. rlwinm %r5,%r31,5+23,32-5,31 /* Extract the value to shift. */
  130. slw %r3,%r3,%r5
  131. stw %r3,0(%r30)
  132. b L(done_return_value)
  133. L(smst_two_register):
  134. rlwinm %r5,%r31,5+23,32-5,31 /* Extract the value to shift. */
  135. cmpwi %r5,0
  136. subfic %r9,%r5,32
  137. slw %r29,%r3,%r5
  138. srw %r9,%r4,%r9
  139. beq- L(smst_8byte)
  140. or %r3,%r9,%r29
  141. slw %r4,%r4,%r5
  142. L(smst_8byte):
  143. stw %r3,0(%r30)
  144. stw %r4,4(%r30)
  145. b L(done_return_value)
  146. .LFE1:
  147. END(ffi_call_SYSV)
  148. .section ".eh_frame",EH_FRAME_FLAGS,@progbits
  149. .Lframe1:
  150. .4byte .LECIE1-.LSCIE1 /* Length of Common Information Entry */
  151. .LSCIE1:
  152. .4byte 0x0 /* CIE Identifier Tag */
  153. .byte 0x1 /* CIE Version */
  154. #if defined _RELOCATABLE || defined __PIC__
  155. .ascii "zR\0" /* CIE Augmentation */
  156. #else
  157. .ascii "\0" /* CIE Augmentation */
  158. #endif
  159. .uleb128 0x1 /* CIE Code Alignment Factor */
  160. .sleb128 -4 /* CIE Data Alignment Factor */
  161. .byte 0x41 /* CIE RA Column */
  162. #if defined _RELOCATABLE || defined __PIC__
  163. .uleb128 0x1 /* Augmentation size */
  164. .byte 0x1b /* FDE Encoding (pcrel sdata4) */
  165. #endif
  166. .byte 0xc /* DW_CFA_def_cfa */
  167. .uleb128 0x1
  168. .uleb128 0x0
  169. .align 2
  170. .LECIE1:
  171. .LSFDE1:
  172. .4byte .LEFDE1-.LASFDE1 /* FDE Length */
  173. .LASFDE1:
  174. .4byte .LASFDE1-.Lframe1 /* FDE CIE offset */
  175. #if defined _RELOCATABLE || defined __PIC__
  176. .4byte .LFB1-. /* FDE initial location */
  177. #else
  178. .4byte .LFB1 /* FDE initial location */
  179. #endif
  180. .4byte .LFE1-.LFB1 /* FDE address range */
  181. #if defined _RELOCATABLE || defined __PIC__
  182. .uleb128 0x0 /* Augmentation size */
  183. #endif
  184. .byte 0x4 /* DW_CFA_advance_loc4 */
  185. .4byte .LCFI0-.LFB1
  186. .byte 0xd /* DW_CFA_def_cfa_register */
  187. .uleb128 0x08
  188. .byte 0x4 /* DW_CFA_advance_loc4 */
  189. .4byte .LCFI5-.LCFI0
  190. .byte 0x11 /* DW_CFA_offset_extended_sf */
  191. .uleb128 0x41
  192. .sleb128 -1
  193. .byte 0x9f /* DW_CFA_offset, column 0x1f */
  194. .uleb128 0x1
  195. .byte 0x9e /* DW_CFA_offset, column 0x1e */
  196. .uleb128 0x2
  197. .byte 0x9d /* DW_CFA_offset, column 0x1d */
  198. .uleb128 0x3
  199. .byte 0x9c /* DW_CFA_offset, column 0x1c */
  200. .uleb128 0x4
  201. .byte 0x4 /* DW_CFA_advance_loc4 */
  202. .4byte .LCFI6-.LCFI5
  203. .byte 0xd /* DW_CFA_def_cfa_register */
  204. .uleb128 0x1c
  205. .align 2
  206. .LEFDE1:
  207. #endif
  208. #if defined __ELF__ && defined __linux__
  209. .section .note.GNU-stack,"",@progbits
  210. #endif