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

http://unladen-swallow.googlecode.com/ · Assembly · 215 lines · 105 code · 38 blank · 72 comment · 0 complexity · b17e59bf6ba716c77cd9ca7a4e39e672 MD5 · raw file

  1. /* -----------------------------------------------------------------------
  2. sysv.S - Copyright (c) 2004 Simon Posnjak
  3. Copyright (c) 2005 Axis Communications AB
  4. CRIS 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 SIMON POSNJAK 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. #define LIBFFI_ASM
  23. #include <ffi.h>
  24. #define CONCAT(x,y) x ## y
  25. #define XCONCAT(x,y) CONCAT (x, y)
  26. #define L(x) XCONCAT (__USER_LABEL_PREFIX__, x)
  27. .text
  28. ;; OK, when we get called we should have this (according to
  29. ;; AXIS ETRAX 100LX Programmer's Manual chapter 6.3).
  30. ;;
  31. ;; R10: ffi_prep_args (func. pointer)
  32. ;; R11: &ecif
  33. ;; R12: cif->bytes
  34. ;; R13: fig->flags
  35. ;; sp+0: ecif.rvalue
  36. ;; sp+4: fn (function pointer to the function that we need to call)
  37. .globl L(ffi_call_SYSV)
  38. .type L(ffi_call_SYSV),@function
  39. .hidden L(ffi_call_SYSV)
  40. L(ffi_call_SYSV):
  41. ;; Save the regs to the stack.
  42. push $srp
  43. ;; Used for stack pointer saving.
  44. push $r6
  45. ;; Used for function address pointer.
  46. push $r7
  47. ;; Used for stack pointer saving.
  48. push $r8
  49. ;; We save fig->flags to stack we will need them after we
  50. ;; call The Function.
  51. push $r13
  52. ;; Saving current stack pointer.
  53. move.d $sp,$r8
  54. move.d $sp,$r6
  55. ;; Move address of ffi_prep_args to r13.
  56. move.d $r10,$r13
  57. ;; Make room on the stack for the args of fn.
  58. sub.d $r12,$sp
  59. ;; Function void ffi_prep_args(char *stack, extended_cif *ecif) parameters are:
  60. ;; r10 <-- stack pointer
  61. ;; r11 <-- &ecif (already there)
  62. move.d $sp,$r10
  63. ;; Call the function.
  64. jsr $r13
  65. ;; Save the size of the structures which are passed on stack.
  66. move.d $r10,$r7
  67. ;; Move first four args in to r10..r13.
  68. move.d [$sp+0],$r10
  69. move.d [$sp+4],$r11
  70. move.d [$sp+8],$r12
  71. move.d [$sp+12],$r13
  72. ;; Adjust the stack and check if any parameters are given on stack.
  73. addq 16,$sp
  74. sub.d $r7,$r6
  75. cmp.d $sp,$r6
  76. bpl go_on
  77. nop
  78. go_on_no_params_on_stack:
  79. move.d $r6,$sp
  80. go_on:
  81. ;; Discover if we need to put rval address in to r9.
  82. move.d [$r8+0],$r7
  83. cmpq FFI_TYPE_STRUCT,$r7
  84. bne call_now
  85. nop
  86. ;; Move rval address to $r9.
  87. move.d [$r8+20],$r9
  88. call_now:
  89. ;; Move address of The Function in to r7.
  90. move.d [$r8+24],$r7
  91. ;; Call The Function.
  92. jsr $r7
  93. ;; Reset stack.
  94. move.d $r8,$sp
  95. ;; Load rval type (fig->flags) in to r13.
  96. pop $r13
  97. ;; Detect rval type.
  98. cmpq FFI_TYPE_VOID,$r13
  99. beq epilogue
  100. cmpq FFI_TYPE_STRUCT,$r13
  101. beq epilogue
  102. cmpq FFI_TYPE_DOUBLE,$r13
  103. beq return_double_or_longlong
  104. cmpq FFI_TYPE_UINT64,$r13
  105. beq return_double_or_longlong
  106. cmpq FFI_TYPE_SINT64,$r13
  107. beq return_double_or_longlong
  108. nop
  109. ;; Just return the 32 bit value.
  110. ba return
  111. nop
  112. return_double_or_longlong:
  113. ;; Load half of the rval to r10 and the other half to r11.
  114. move.d [$sp+16],$r13
  115. move.d $r10,[$r13]
  116. addq 4,$r13
  117. move.d $r11,[$r13]
  118. ba epilogue
  119. nop
  120. return:
  121. ;; Load the rval to r10.
  122. move.d [$sp+16],$r13
  123. move.d $r10,[$r13]
  124. epilogue:
  125. pop $r8
  126. pop $r7
  127. pop $r6
  128. Jump [$sp+]
  129. .size ffi_call_SYSV,.-ffi_call_SYSV
  130. /* Save R10..R13 into an array, somewhat like varargs. Copy the next
  131. argument too, to simplify handling of any straddling parameter.
  132. Save R9 and SP after those. Jump to function handling the rest.
  133. Since this is a template, copied and the main function filled in by
  134. the user. */
  135. .globl L(ffi_cris_trampoline_template)
  136. .type L(ffi_cris_trampoline_template),@function
  137. .hidden L(ffi_cris_trampoline_template)
  138. L(ffi_cris_trampoline_template):
  139. 0:
  140. /* The value we get for "PC" is right after the prefix instruction,
  141. two bytes from the beginning, i.e. 0b+2. */
  142. move.d $r10,[$pc+2f-(0b+2)]
  143. move.d $pc,$r10
  144. 1:
  145. addq 2f-1b+4,$r10
  146. move.d $r11,[$r10+]
  147. move.d $r12,[$r10+]
  148. move.d $r13,[$r10+]
  149. move.d [$sp],$r11
  150. move.d $r11,[$r10+]
  151. move.d $r9,[$r10+]
  152. move.d $sp,[$r10+]
  153. subq FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE,$r10
  154. move.d 0,$r11
  155. 3:
  156. jump 0
  157. 2:
  158. .size ffi_cris_trampoline_template,.-0b
  159. /* This macro create a constant usable as "extern const int \name" in
  160. C from within libffi, when \name has no prefix decoration. */
  161. .macro const name,value
  162. .globl \name
  163. .type \name,@object
  164. .hidden \name
  165. \name:
  166. .dword \value
  167. .size \name,4
  168. .endm
  169. /* Constants for offsets within the trampoline. We could do this with
  170. just symbols, avoiding memory contents and memory accesses, but the
  171. C usage code would look a bit stranger. */
  172. const L(ffi_cris_trampoline_fn_offset),2b-4-0b
  173. const L(ffi_cris_trampoline_closure_offset),3b-4-0b