/js/src/ctypes/libffi/src/moxie/eabi.S

http://github.com/zpao/v8monkey · Assembly · 128 lines · 69 code · 18 blank · 41 comment · 0 complexity · b9ecce87980cf9448d35f168d0b12575 MD5 · raw file

  1. /* -----------------------------------------------------------------------
  2. eabi.S - Copyright (c) 2004 Anthony Green
  3. FR-V Assembly glue.
  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 THE AUTHOR 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. .globl ffi_prep_args_EABI
  25. .text
  26. .p2align 4
  27. .globl ffi_call_EABI
  28. .type ffi_call_EABI, @function
  29. # gr8 : ffi_prep_args
  30. # gr9 : &ecif
  31. # gr10: cif->bytes
  32. # gr11: fig->flags
  33. # gr12: ecif.rvalue
  34. # gr13: fn
  35. ffi_call_EABI:
  36. addi sp, #-80, sp
  37. sti fp, @(sp, #24)
  38. addi sp, #24, fp
  39. movsg lr, gr5
  40. /* Make room for the new arguments. */
  41. /* subi sp, fp, gr10 */
  42. /* Store return address and incoming args on stack. */
  43. sti gr5, @(fp, #8)
  44. sti gr8, @(fp, #-4)
  45. sti gr9, @(fp, #-8)
  46. sti gr10, @(fp, #-12)
  47. sti gr11, @(fp, #-16)
  48. sti gr12, @(fp, #-20)
  49. sti gr13, @(fp, #-24)
  50. sub sp, gr10, sp
  51. /* Call ffi_prep_args. */
  52. ldi @(fp, #-4), gr4
  53. addi sp, #0, gr8
  54. ldi @(fp, #-8), gr9
  55. #ifdef __FRV_FDPIC__
  56. ldd @(gr4, gr0), gr14
  57. calll @(gr14, gr0)
  58. #else
  59. calll @(gr4, gr0)
  60. #endif
  61. /* ffi_prep_args returns the new stack pointer. */
  62. mov gr8, gr4
  63. ldi @(sp, #0), gr8
  64. ldi @(sp, #4), gr9
  65. ldi @(sp, #8), gr10
  66. ldi @(sp, #12), gr11
  67. ldi @(sp, #16), gr12
  68. ldi @(sp, #20), gr13
  69. /* Always copy the return value pointer into the hidden
  70. parameter register. This is only strictly necessary
  71. when we're returning an aggregate type, but it doesn't
  72. hurt to do this all the time, and it saves a branch. */
  73. ldi @(fp, #-20), gr3
  74. /* Use the ffi_prep_args return value for the new sp. */
  75. mov gr4, sp
  76. /* Call the target function. */
  77. ldi @(fp, -24), gr4
  78. #ifdef __FRV_FDPIC__
  79. ldd @(gr4, gr0), gr14
  80. calll @(gr14, gr0)
  81. #else
  82. calll @(gr4, gr0)
  83. #endif
  84. /* Store the result. */
  85. ldi @(fp, #-16), gr10 /* fig->flags */
  86. ldi @(fp, #-20), gr4 /* ecif.rvalue */
  87. /* Is the return value stored in two registers? */
  88. cmpi gr10, #8, icc0
  89. bne icc0, 0, .L2
  90. /* Yes, save them. */
  91. sti gr8, @(gr4, #0)
  92. sti gr9, @(gr4, #4)
  93. bra .L3
  94. .L2:
  95. /* Is the return value a structure? */
  96. cmpi gr10, #-1, icc0
  97. beq icc0, 0, .L3
  98. /* No, save a 4 byte return value. */
  99. sti gr8, @(gr4, #0)
  100. .L3:
  101. /* Restore the stack, and return. */
  102. ldi @(fp, 8), gr5
  103. ld @(fp, gr0), fp
  104. addi sp,#80,sp
  105. jmpl @(gr5,gr0)
  106. .size ffi_call_EABI, .-ffi_call_EABI