/js/src/ctypes/libffi/src/powerpc/sysv.S

http://github.com/zpao/v8monkey · Assembly · 219 lines · 163 code · 15 blank · 41 comment · 5 complexity · 53da07be3982ee6cf80c7938c77e8ef7 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. extrwi %r6,%r31,2,19 /* number of bytes padding = shift/8 */
  124. mtcrf 0x02,%r31 /* copy flags to cr[24:27] (cr6) */
  125. extrwi %r5,%r31,5,19 /* r5 <- number of bits of padding */
  126. subfic %r6,%r6,4 /* r6 <- number of useful bytes in r3 */
  127. bf- 25,L(done_return_value) /* struct in r3 ? if not, done. */
  128. /* smst_one_register: */
  129. slw %r3,%r3,%r5 /* Left-justify value in r3 */
  130. mtxer %r6 /* move byte count to XER ... */
  131. stswx %r3,0,%r30 /* ... and store that many bytes */
  132. bf+ 26,L(done_return_value) /* struct in r3:r4 ? */
  133. add %r6,%r6,%r30 /* adjust pointer */
  134. stswi %r4,%r6,4 /* store last four bytes */
  135. b L(done_return_value)
  136. .LFE1:
  137. END(ffi_call_SYSV)
  138. .section ".eh_frame",EH_FRAME_FLAGS,@progbits
  139. .Lframe1:
  140. .4byte .LECIE1-.LSCIE1 /* Length of Common Information Entry */
  141. .LSCIE1:
  142. .4byte 0x0 /* CIE Identifier Tag */
  143. .byte 0x1 /* CIE Version */
  144. #if defined _RELOCATABLE || defined __PIC__
  145. .ascii "zR\0" /* CIE Augmentation */
  146. #else
  147. .ascii "\0" /* CIE Augmentation */
  148. #endif
  149. .uleb128 0x1 /* CIE Code Alignment Factor */
  150. .sleb128 -4 /* CIE Data Alignment Factor */
  151. .byte 0x41 /* CIE RA Column */
  152. #if defined _RELOCATABLE || defined __PIC__
  153. .uleb128 0x1 /* Augmentation size */
  154. .byte 0x1b /* FDE Encoding (pcrel sdata4) */
  155. #endif
  156. .byte 0xc /* DW_CFA_def_cfa */
  157. .uleb128 0x1
  158. .uleb128 0x0
  159. .align 2
  160. .LECIE1:
  161. .LSFDE1:
  162. .4byte .LEFDE1-.LASFDE1 /* FDE Length */
  163. .LASFDE1:
  164. .4byte .LASFDE1-.Lframe1 /* FDE CIE offset */
  165. #if defined _RELOCATABLE || defined __PIC__
  166. .4byte .LFB1-. /* FDE initial location */
  167. #else
  168. .4byte .LFB1 /* FDE initial location */
  169. #endif
  170. .4byte .LFE1-.LFB1 /* FDE address range */
  171. #if defined _RELOCATABLE || defined __PIC__
  172. .uleb128 0x0 /* Augmentation size */
  173. #endif
  174. .byte 0x4 /* DW_CFA_advance_loc4 */
  175. .4byte .LCFI0-.LFB1
  176. .byte 0xd /* DW_CFA_def_cfa_register */
  177. .uleb128 0x08
  178. .byte 0x4 /* DW_CFA_advance_loc4 */
  179. .4byte .LCFI5-.LCFI0
  180. .byte 0x11 /* DW_CFA_offset_extended_sf */
  181. .uleb128 0x41
  182. .sleb128 -1
  183. .byte 0x9f /* DW_CFA_offset, column 0x1f */
  184. .uleb128 0x1
  185. .byte 0x9e /* DW_CFA_offset, column 0x1e */
  186. .uleb128 0x2
  187. .byte 0x9d /* DW_CFA_offset, column 0x1d */
  188. .uleb128 0x3
  189. .byte 0x9c /* DW_CFA_offset, column 0x1c */
  190. .uleb128 0x4
  191. .byte 0x4 /* DW_CFA_advance_loc4 */
  192. .4byte .LCFI6-.LCFI5
  193. .byte 0xd /* DW_CFA_def_cfa_register */
  194. .uleb128 0x1c
  195. .align 2
  196. .LEFDE1:
  197. #endif
  198. #if defined __ELF__ && defined __linux__
  199. .section .note.GNU-stack,"",@progbits
  200. #endif