/js/src/ctypes/libffi/src/sparc/v9.S

http://github.com/zpao/v8monkey · Assembly · 307 lines · 236 code · 38 blank · 33 comment · 5 complexity · cbae30a5242be298ba2710482e8737de MD5 · raw file

  1. /* -----------------------------------------------------------------------
  2. v9.S - Copyright (c) 2000, 2003, 2004, 2008 Red Hat, Inc.
  3. SPARC 64-bit Foreign Function Interface
  4. Permission is hereby granted, free of charge, to any person obtaining
  5. a copy of this software and associated documentation files (the
  6. ``Software''), to deal in the Software without restriction, including
  7. without limitation the rights to use, copy, modify, merge, publish,
  8. distribute, sublicense, and/or sell copies of the Software, and to
  9. permit persons to whom the Software is furnished to do so, subject to
  10. the following conditions:
  11. The above copyright notice and this permission notice shall be included
  12. in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. DEALINGS IN THE SOFTWARE.
  21. ----------------------------------------------------------------------- */
  22. #define LIBFFI_ASM
  23. #include <fficonfig.h>
  24. #include <ffi.h>
  25. #ifdef SPARC64
  26. /* Only compile this in for 64bit builds, because otherwise the object file
  27. will have inproper architecture due to used instructions. */
  28. #define STACKFRAME 128 /* Minimum stack framesize for SPARC */
  29. #define STACK_BIAS 2047
  30. #define ARGS (128) /* Offset of register area in frame */
  31. .text
  32. .align 8
  33. .globl ffi_call_v9
  34. .globl _ffi_call_v9
  35. ffi_call_v9:
  36. _ffi_call_v9:
  37. .LLFB1:
  38. save %sp, -STACKFRAME, %sp
  39. .LLCFI0:
  40. sub %sp, %i2, %sp ! alloca() space in stack for frame to set up
  41. add %sp, STACKFRAME+STACK_BIAS, %l0 ! %l0 has start of
  42. ! frame to set up
  43. mov %l0, %o0 ! call routine to set up frame
  44. call %i0
  45. mov %i1, %o1 ! (delay)
  46. brz,pt %o0, 1f
  47. ldx [%l0+ARGS], %o0 ! call foreign function
  48. ldd [%l0+ARGS], %f0
  49. ldd [%l0+ARGS+8], %f2
  50. ldd [%l0+ARGS+16], %f4
  51. ldd [%l0+ARGS+24], %f6
  52. ldd [%l0+ARGS+32], %f8
  53. ldd [%l0+ARGS+40], %f10
  54. ldd [%l0+ARGS+48], %f12
  55. ldd [%l0+ARGS+56], %f14
  56. ldd [%l0+ARGS+64], %f16
  57. ldd [%l0+ARGS+72], %f18
  58. ldd [%l0+ARGS+80], %f20
  59. ldd [%l0+ARGS+88], %f22
  60. ldd [%l0+ARGS+96], %f24
  61. ldd [%l0+ARGS+104], %f26
  62. ldd [%l0+ARGS+112], %f28
  63. ldd [%l0+ARGS+120], %f30
  64. 1: ldx [%l0+ARGS+8], %o1
  65. ldx [%l0+ARGS+16], %o2
  66. ldx [%l0+ARGS+24], %o3
  67. ldx [%l0+ARGS+32], %o4
  68. ldx [%l0+ARGS+40], %o5
  69. call %i5
  70. sub %l0, STACK_BIAS, %sp ! (delay) switch to frame
  71. ! If the return value pointer is NULL, assume no return value.
  72. brz,pn %i4, done
  73. nop
  74. cmp %i3, FFI_TYPE_INT
  75. be,a,pt %icc, done
  76. stx %o0, [%i4+0] ! (delay)
  77. cmp %i3, FFI_TYPE_FLOAT
  78. be,a,pn %icc, done
  79. st %f0, [%i4+0] ! (delay)
  80. cmp %i3, FFI_TYPE_DOUBLE
  81. be,a,pn %icc, done
  82. std %f0, [%i4+0] ! (delay)
  83. cmp %i3, FFI_TYPE_STRUCT
  84. be,pn %icc, dostruct
  85. cmp %i3, FFI_TYPE_LONGDOUBLE
  86. bne,pt %icc, done
  87. nop
  88. std %f0, [%i4+0]
  89. std %f2, [%i4+8]
  90. done: ret
  91. restore
  92. dostruct:
  93. /* This will not work correctly for unions. */
  94. stx %o0, [%i4+0]
  95. stx %o1, [%i4+8]
  96. stx %o2, [%i4+16]
  97. stx %o3, [%i4+24]
  98. std %f0, [%i4+32]
  99. std %f2, [%i4+40]
  100. std %f4, [%i4+48]
  101. std %f6, [%i4+56]
  102. ret
  103. restore
  104. .LLFE1:
  105. .ffi_call_v9_end:
  106. .size ffi_call_v9,.ffi_call_v9_end-ffi_call_v9
  107. #undef STACKFRAME
  108. #define STACKFRAME 336 /* 16*8 register window +
  109. 6*8 args backing store +
  110. 20*8 locals */
  111. #define FP %fp+STACK_BIAS
  112. /* ffi_closure_v9(...)
  113. Receives the closure argument in %g1. */
  114. .text
  115. .align 8
  116. .globl ffi_closure_v9
  117. ffi_closure_v9:
  118. .LLFB2:
  119. save %sp, -STACKFRAME, %sp
  120. .LLCFI1:
  121. ! Store all of the potential argument registers in va_list format.
  122. stx %i0, [FP+128+0]
  123. stx %i1, [FP+128+8]
  124. stx %i2, [FP+128+16]
  125. stx %i3, [FP+128+24]
  126. stx %i4, [FP+128+32]
  127. stx %i5, [FP+128+40]
  128. ! Store possible floating point argument registers too.
  129. std %f0, [FP-128]
  130. std %f2, [FP-120]
  131. std %f4, [FP-112]
  132. std %f6, [FP-104]
  133. std %f8, [FP-96]
  134. std %f10, [FP-88]
  135. std %f12, [FP-80]
  136. std %f14, [FP-72]
  137. std %f16, [FP-64]
  138. std %f18, [FP-56]
  139. std %f20, [FP-48]
  140. std %f22, [FP-40]
  141. std %f24, [FP-32]
  142. std %f26, [FP-24]
  143. std %f28, [FP-16]
  144. std %f30, [FP-8]
  145. ! Call ffi_closure_sparc_inner to do the bulk of the work.
  146. mov %g1, %o0
  147. add %fp, STACK_BIAS-160, %o1
  148. add %fp, STACK_BIAS+128, %o2
  149. call ffi_closure_sparc_inner_v9
  150. add %fp, STACK_BIAS-128, %o3
  151. ! Load up the return value in the proper type.
  152. ! See ffi_prep_cif_machdep for the list of cases.
  153. cmp %o0, FFI_TYPE_VOID
  154. be,pn %icc, done1
  155. cmp %o0, FFI_TYPE_INT
  156. be,pn %icc, integer
  157. cmp %o0, FFI_TYPE_FLOAT
  158. be,a,pn %icc, done1
  159. ld [FP-160], %f0
  160. cmp %o0, FFI_TYPE_DOUBLE
  161. be,a,pn %icc, done1
  162. ldd [FP-160], %f0
  163. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  164. cmp %o0, FFI_TYPE_LONGDOUBLE
  165. be,a,pn %icc, longdouble1
  166. ldd [FP-160], %f0
  167. #endif
  168. ! FFI_TYPE_STRUCT
  169. ldx [FP-152], %i1
  170. ldx [FP-144], %i2
  171. ldx [FP-136], %i3
  172. ldd [FP-160], %f0
  173. ldd [FP-152], %f2
  174. ldd [FP-144], %f4
  175. ldd [FP-136], %f6
  176. integer:
  177. ldx [FP-160], %i0
  178. done1:
  179. ret
  180. restore
  181. #if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
  182. longdouble1:
  183. ldd [FP-152], %f2
  184. ret
  185. restore
  186. #endif
  187. .LLFE2:
  188. .ffi_closure_v9_end:
  189. .size ffi_closure_v9,.ffi_closure_v9_end-ffi_closure_v9
  190. #ifdef HAVE_RO_EH_FRAME
  191. .section ".eh_frame",#alloc
  192. #else
  193. .section ".eh_frame",#alloc,#write
  194. #endif
  195. .LLframe1:
  196. .uaword .LLECIE1-.LLSCIE1 ! Length of Common Information Entry
  197. .LLSCIE1:
  198. .uaword 0x0 ! CIE Identifier Tag
  199. .byte 0x1 ! CIE Version
  200. .ascii "zR\0" ! CIE Augmentation
  201. .byte 0x1 ! uleb128 0x1; CIE Code Alignment Factor
  202. .byte 0x78 ! sleb128 -8; CIE Data Alignment Factor
  203. .byte 0xf ! CIE RA Column
  204. .byte 0x1 ! uleb128 0x1; Augmentation size
  205. #ifdef HAVE_AS_SPARC_UA_PCREL
  206. .byte 0x1b ! FDE Encoding (pcrel sdata4)
  207. #else
  208. .byte 0x50 ! FDE Encoding (aligned absolute)
  209. #endif
  210. .byte 0xc ! DW_CFA_def_cfa
  211. .byte 0xe ! uleb128 0xe
  212. .byte 0xff,0xf ! uleb128 0x7ff
  213. .align 8
  214. .LLECIE1:
  215. .LLSFDE1:
  216. .uaword .LLEFDE1-.LLASFDE1 ! FDE Length
  217. .LLASFDE1:
  218. .uaword .LLASFDE1-.LLframe1 ! FDE CIE offset
  219. #ifdef HAVE_AS_SPARC_UA_PCREL
  220. .uaword %r_disp32(.LLFB1)
  221. .uaword .LLFE1-.LLFB1 ! FDE address range
  222. #else
  223. .align 8
  224. .xword .LLFB1
  225. .uaxword .LLFE1-.LLFB1 ! FDE address range
  226. #endif
  227. .byte 0x0 ! uleb128 0x0; Augmentation size
  228. .byte 0x4 ! DW_CFA_advance_loc4
  229. .uaword .LLCFI0-.LLFB1
  230. .byte 0xd ! DW_CFA_def_cfa_register
  231. .byte 0x1e ! uleb128 0x1e
  232. .byte 0x2d ! DW_CFA_GNU_window_save
  233. .byte 0x9 ! DW_CFA_register
  234. .byte 0xf ! uleb128 0xf
  235. .byte 0x1f ! uleb128 0x1f
  236. .align 8
  237. .LLEFDE1:
  238. .LLSFDE2:
  239. .uaword .LLEFDE2-.LLASFDE2 ! FDE Length
  240. .LLASFDE2:
  241. .uaword .LLASFDE2-.LLframe1 ! FDE CIE offset
  242. #ifdef HAVE_AS_SPARC_UA_PCREL
  243. .uaword %r_disp32(.LLFB2)
  244. .uaword .LLFE2-.LLFB2 ! FDE address range
  245. #else
  246. .align 8
  247. .xword .LLFB2
  248. .uaxword .LLFE2-.LLFB2 ! FDE address range
  249. #endif
  250. .byte 0x0 ! uleb128 0x0; Augmentation size
  251. .byte 0x4 ! DW_CFA_advance_loc4
  252. .uaword .LLCFI1-.LLFB2
  253. .byte 0xd ! DW_CFA_def_cfa_register
  254. .byte 0x1e ! uleb128 0x1e
  255. .byte 0x2d ! DW_CFA_GNU_window_save
  256. .byte 0x9 ! DW_CFA_register
  257. .byte 0xf ! uleb128 0xf
  258. .byte 0x1f ! uleb128 0x1f
  259. .align 8
  260. .LLEFDE2:
  261. #endif
  262. #ifdef __linux__
  263. .section .note.GNU-stack,"",@progbits
  264. #endif