/Modules/_ctypes/libffi/src/alpha/osf.S

http://unladen-swallow.googlecode.com/ · Assembly · 366 lines · 289 code · 42 blank · 35 comment · 25 complexity · 1c2284340e3ec316407056831adf7780 MD5 · raw file

  1. /* -----------------------------------------------------------------------
  2. osf.S - Copyright (c) 1998, 2001, 2007, 2008 Red Hat
  3. Alpha/OSF 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. .arch ev6
  26. .text
  27. /* ffi_call_osf (void *args, unsigned long bytes, unsigned flags,
  28. void *raddr, void (*fnaddr)(void));
  29. Bit o trickiness here -- ARGS+BYTES is the base of the stack frame
  30. for this function. This has been allocated by ffi_call. We also
  31. deallocate some of the stack that has been alloca'd. */
  32. .align 3
  33. .globl ffi_call_osf
  34. .ent ffi_call_osf
  35. FFI_HIDDEN(ffi_call_osf)
  36. ffi_call_osf:
  37. .frame $15, 32, $26, 0
  38. .mask 0x4008000, -32
  39. $LFB1:
  40. addq $16,$17,$1
  41. mov $16, $30
  42. stq $26, 0($1)
  43. stq $15, 8($1)
  44. stq $18, 16($1)
  45. mov $1, $15
  46. $LCFI1:
  47. .prologue 0
  48. stq $19, 24($1)
  49. mov $20, $27
  50. # Load up all of the (potential) argument registers.
  51. ldq $16, 0($30)
  52. ldt $f16, 0($30)
  53. ldt $f17, 8($30)
  54. ldq $17, 8($30)
  55. ldt $f18, 16($30)
  56. ldq $18, 16($30)
  57. ldt $f19, 24($30)
  58. ldq $19, 24($30)
  59. ldt $f20, 32($30)
  60. ldq $20, 32($30)
  61. ldt $f21, 40($30)
  62. ldq $21, 40($30)
  63. # Deallocate the register argument area.
  64. lda $30, 48($30)
  65. jsr $26, ($27), 0
  66. ldgp $29, 0($26)
  67. # If the return value pointer is NULL, assume no return value.
  68. ldq $19, 24($15)
  69. ldq $18, 16($15)
  70. ldq $26, 0($15)
  71. $LCFI2:
  72. beq $19, $noretval
  73. # Store the return value out in the proper type.
  74. cmpeq $18, FFI_TYPE_INT, $1
  75. bne $1, $retint
  76. cmpeq $18, FFI_TYPE_FLOAT, $2
  77. bne $2, $retfloat
  78. cmpeq $18, FFI_TYPE_DOUBLE, $3
  79. bne $3, $retdouble
  80. .align 3
  81. $noretval:
  82. ldq $15, 8($15)
  83. ret
  84. .align 4
  85. $retint:
  86. stq $0, 0($19)
  87. nop
  88. ldq $15, 8($15)
  89. ret
  90. .align 4
  91. $retfloat:
  92. sts $f0, 0($19)
  93. nop
  94. ldq $15, 8($15)
  95. ret
  96. .align 4
  97. $retdouble:
  98. stt $f0, 0($19)
  99. nop
  100. ldq $15, 8($15)
  101. ret
  102. $LFE1:
  103. .end ffi_call_osf
  104. /* ffi_closure_osf(...)
  105. Receives the closure argument in $1. */
  106. .align 3
  107. .globl ffi_closure_osf
  108. .ent ffi_closure_osf
  109. FFI_HIDDEN(ffi_closure_osf)
  110. ffi_closure_osf:
  111. .frame $30, 16*8, $26, 0
  112. .mask 0x4000000, -16*8
  113. $LFB2:
  114. ldgp $29, 0($27)
  115. subq $30, 16*8, $30
  116. $LCFI5:
  117. stq $26, 0($30)
  118. $LCFI6:
  119. .prologue 1
  120. # Store all of the potential argument registers in va_list format.
  121. stt $f16, 4*8($30)
  122. stt $f17, 5*8($30)
  123. stt $f18, 6*8($30)
  124. stt $f19, 7*8($30)
  125. stt $f20, 8*8($30)
  126. stt $f21, 9*8($30)
  127. stq $16, 10*8($30)
  128. stq $17, 11*8($30)
  129. stq $18, 12*8($30)
  130. stq $19, 13*8($30)
  131. stq $20, 14*8($30)
  132. stq $21, 15*8($30)
  133. # Call ffi_closure_osf_inner to do the bulk of the work.
  134. mov $1, $16
  135. lda $17, 2*8($30)
  136. lda $18, 10*8($30)
  137. jsr $26, ffi_closure_osf_inner
  138. ldgp $29, 0($26)
  139. ldq $26, 0($30)
  140. # Load up the return value in the proper type.
  141. lda $1, $load_table
  142. s4addq $0, $1, $1
  143. ldl $1, 0($1)
  144. addq $1, $29, $1
  145. jmp $31, ($1), $load_32
  146. .align 4
  147. $load_none:
  148. addq $30, 16*8, $30
  149. ret
  150. .align 4
  151. $load_float:
  152. lds $f0, 16($30)
  153. nop
  154. addq $30, 16*8, $30
  155. ret
  156. .align 4
  157. $load_double:
  158. ldt $f0, 16($30)
  159. nop
  160. addq $30, 16*8, $30
  161. ret
  162. .align 4
  163. $load_u8:
  164. #ifdef __alpha_bwx__
  165. ldbu $0, 16($30)
  166. nop
  167. #else
  168. ldq $0, 16($30)
  169. and $0, 255, $0
  170. #endif
  171. addq $30, 16*8, $30
  172. ret
  173. .align 4
  174. $load_s8:
  175. #ifdef __alpha_bwx__
  176. ldbu $0, 16($30)
  177. sextb $0, $0
  178. #else
  179. ldq $0, 16($30)
  180. sll $0, 56, $0
  181. sra $0, 56, $0
  182. #endif
  183. addq $30, 16*8, $30
  184. ret
  185. .align 4
  186. $load_u16:
  187. #ifdef __alpha_bwx__
  188. ldwu $0, 16($30)
  189. nop
  190. #else
  191. ldq $0, 16($30)
  192. zapnot $0, 3, $0
  193. #endif
  194. addq $30, 16*8, $30
  195. ret
  196. .align 4
  197. $load_s16:
  198. #ifdef __alpha_bwx__
  199. ldwu $0, 16($30)
  200. sextw $0, $0
  201. #else
  202. ldq $0, 16($30)
  203. sll $0, 48, $0
  204. sra $0, 48, $0
  205. #endif
  206. addq $30, 16*8, $30
  207. ret
  208. .align 4
  209. $load_32:
  210. ldl $0, 16($30)
  211. nop
  212. addq $30, 16*8, $30
  213. ret
  214. .align 4
  215. $load_64:
  216. ldq $0, 16($30)
  217. nop
  218. addq $30, 16*8, $30
  219. ret
  220. $LFE2:
  221. .end ffi_closure_osf
  222. #ifdef __ELF__
  223. .section .rodata
  224. #else
  225. .rdata
  226. #endif
  227. $load_table:
  228. .gprel32 $load_none # FFI_TYPE_VOID
  229. .gprel32 $load_32 # FFI_TYPE_INT
  230. .gprel32 $load_float # FFI_TYPE_FLOAT
  231. .gprel32 $load_double # FFI_TYPE_DOUBLE
  232. .gprel32 $load_none # FFI_TYPE_LONGDOUBLE
  233. .gprel32 $load_u8 # FFI_TYPE_UINT8
  234. .gprel32 $load_s8 # FFI_TYPE_SINT8
  235. .gprel32 $load_u16 # FFI_TYPE_UINT16
  236. .gprel32 $load_s16 # FFI_TYPE_SINT16
  237. .gprel32 $load_32 # FFI_TYPE_UINT32
  238. .gprel32 $load_32 # FFI_TYPE_SINT32
  239. .gprel32 $load_64 # FFI_TYPE_UINT64
  240. .gprel32 $load_64 # FFI_TYPE_SINT64
  241. .gprel32 $load_none # FFI_TYPE_STRUCT
  242. .gprel32 $load_64 # FFI_TYPE_POINTER
  243. /* Assert that the table above is in sync with ffi.h. */
  244. #if FFI_TYPE_FLOAT != 2 \
  245. || FFI_TYPE_DOUBLE != 3 \
  246. || FFI_TYPE_UINT8 != 5 \
  247. || FFI_TYPE_SINT8 != 6 \
  248. || FFI_TYPE_UINT16 != 7 \
  249. || FFI_TYPE_SINT16 != 8 \
  250. || FFI_TYPE_UINT32 != 9 \
  251. || FFI_TYPE_SINT32 != 10 \
  252. || FFI_TYPE_UINT64 != 11 \
  253. || FFI_TYPE_SINT64 != 12 \
  254. || FFI_TYPE_STRUCT != 13 \
  255. || FFI_TYPE_POINTER != 14 \
  256. || FFI_TYPE_LAST != 14
  257. #error "osf.S out of sync with ffi.h"
  258. #endif
  259. #ifdef __ELF__
  260. .section .eh_frame,EH_FRAME_FLAGS,@progbits
  261. __FRAME_BEGIN__:
  262. .4byte $LECIE1-$LSCIE1 # Length of Common Information Entry
  263. $LSCIE1:
  264. .4byte 0x0 # CIE Identifier Tag
  265. .byte 0x1 # CIE Version
  266. .ascii "zR\0" # CIE Augmentation
  267. .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
  268. .byte 0x78 # sleb128 -8; CIE Data Alignment Factor
  269. .byte 26 # CIE RA Column
  270. .byte 0x1 # uleb128 0x1; Augmentation size
  271. .byte 0x1b # FDE Encoding (pcrel sdata4)
  272. .byte 0xc # DW_CFA_def_cfa
  273. .byte 30 # uleb128 column 30
  274. .byte 0 # uleb128 offset 0
  275. .align 3
  276. $LECIE1:
  277. $LSFDE1:
  278. .4byte $LEFDE1-$LASFDE1 # FDE Length
  279. $LASFDE1:
  280. .4byte $LASFDE1-__FRAME_BEGIN__ # FDE CIE offset
  281. .4byte $LFB1-. # FDE initial location
  282. .4byte $LFE1-$LFB1 # FDE address range
  283. .byte 0x0 # uleb128 0x0; Augmentation size
  284. .byte 0x4 # DW_CFA_advance_loc4
  285. .4byte $LCFI1-$LFB1
  286. .byte 0x9a # DW_CFA_offset, column 26
  287. .byte 4 # uleb128 4*-8
  288. .byte 0x8f # DW_CFA_offset, column 15
  289. .byte 0x3 # uleb128 3*-8
  290. .byte 0xc # DW_CFA_def_cfa
  291. .byte 15 # uleb128 column 15
  292. .byte 32 # uleb128 offset 32
  293. .byte 0x4 # DW_CFA_advance_loc4
  294. .4byte $LCFI2-$LCFI1
  295. .byte 0xda # DW_CFA_restore, column 26
  296. .align 3
  297. $LEFDE1:
  298. $LSFDE3:
  299. .4byte $LEFDE3-$LASFDE3 # FDE Length
  300. $LASFDE3:
  301. .4byte $LASFDE3-__FRAME_BEGIN__ # FDE CIE offset
  302. .4byte $LFB2-. # FDE initial location
  303. .4byte $LFE2-$LFB2 # FDE address range
  304. .byte 0x0 # uleb128 0x0; Augmentation size
  305. .byte 0x4 # DW_CFA_advance_loc4
  306. .4byte $LCFI5-$LFB2
  307. .byte 0xe # DW_CFA_def_cfa_offset
  308. .byte 0x80,0x1 # uleb128 128
  309. .byte 0x4 # DW_CFA_advance_loc4
  310. .4byte $LCFI6-$LCFI5
  311. .byte 0x9a # DW_CFA_offset, column 26
  312. .byte 16 # uleb128 offset 16*-8
  313. .align 3
  314. $LEFDE3:
  315. #ifdef __linux__
  316. .section .note.GNU-stack,"",@progbits
  317. #endif
  318. #endif