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

http://unladen-swallow.googlecode.com/ · Assembly · 121 lines · 57 code · 18 blank · 46 comment · 0 complexity · fde1f5cb81ab7ce114af861c94c368c0 MD5 · raw file

  1. /* -----------------------------------------------------------------------
  2. sysv.S - Copyright (c) 2004 Renesas Technology
  3. M32R 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, EXPRESS
  14. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  16. IN NO EVENT SHALL RENESAS TECHNOLOGY BE LIABLE FOR ANY CLAIM, DAMAGES OR
  17. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  18. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  19. OTHER DEALINGS IN THE SOFTWARE.
  20. ----------------------------------------------------------------------- */
  21. #define LIBFFI_ASM
  22. #include <fficonfig.h>
  23. #include <ffi.h>
  24. #ifdef HAVE_MACHINE_ASM_H
  25. #include <machine/asm.h>
  26. #else
  27. /* XXX these lose for some platforms, I'm sure. */
  28. #define CNAME(x) x
  29. #define ENTRY(x) .globl CNAME(x)! .type CNAME(x),%function! CNAME(x):
  30. #endif
  31. .text
  32. /* R0: ffi_prep_args */
  33. /* R1: &ecif */
  34. /* R2: cif->bytes */
  35. /* R3: fig->flags */
  36. /* sp+0: ecif.rvalue */
  37. /* sp+4: fn */
  38. /* This assumes we are using gas. */
  39. ENTRY(ffi_call_SYSV)
  40. /* Save registers. */
  41. push fp
  42. push lr
  43. push r3
  44. push r2
  45. push r1
  46. push r0
  47. mv fp, sp
  48. /* Make room for all of the new args. */
  49. sub sp, r2
  50. /* Place all of the ffi_prep_args in position. */
  51. mv lr, r0
  52. mv r0, sp
  53. /* R1 already set. */
  54. /* And call. */
  55. jl lr
  56. /* Move first 4 parameters in registers... */
  57. ld r0, @(0,sp)
  58. ld r1, @(4,sp)
  59. ld r2, @(8,sp)
  60. ld r3, @(12,sp)
  61. /* ...and adjust the stack. */
  62. ld lr, @(8,fp)
  63. cmpi lr, #16
  64. bc adjust_stack
  65. ldi lr, #16
  66. adjust_stack:
  67. add sp, lr
  68. /* Call the function. */
  69. ld lr, @(28,fp)
  70. jl lr
  71. /* Remove the space we pushed for the args. */
  72. mv sp, fp
  73. /* Load R2 with the pointer to storage for the return value. */
  74. ld r2, @(24,sp)
  75. /* Load R3 with the return type code. */
  76. ld r3, @(12,sp)
  77. /* If the return value pointer is NULL, assume no return value. */
  78. beqz r2, epilogue
  79. /* Return INT. */
  80. ldi r4, #FFI_TYPE_INT
  81. bne r3, r4, return_double
  82. st r0, @r2
  83. bra epilogue
  84. return_double:
  85. /* Return DOUBLE or LONGDOUBLE. */
  86. ldi r4, #FFI_TYPE_DOUBLE
  87. bne r3, r4, epilogue
  88. st r0, @r2
  89. st r1, @(4,r2)
  90. epilogue:
  91. pop r0
  92. pop r1
  93. pop r2
  94. pop r3
  95. pop lr
  96. pop fp
  97. jmp lr
  98. .ffi_call_SYSV_end:
  99. .size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)