1
0

931-libffi-fix-MIPS-softfloat-build-issue.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. From c0c62fa4256f805389f16ebfc4a60cf789129b50 Mon Sep 17 00:00:00 2001
  2. From: BangLang Huang <banglang.huang@foxmail.com>
  3. Date: Wed, 9 Nov 2016 10:36:49 +0800
  4. Subject: [PATCH] libffi: fix MIPS softfloat build issue
  5. Backported from github.com/libffi/libffi#272
  6. Signed-off-by: BangLang Huang <banglang.huang@foxmail.com>
  7. Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
  8. ---
  9. libffi/src/mips/n32.S | 17 +++++++++++++++++
  10. libffi/src/mips/o32.S | 17 +++++++++++++++++
  11. 2 files changed, 34 insertions(+)
  12. --- a/libffi/src/mips/n32.S
  13. +++ b/libffi/src/mips/n32.S
  14. @@ -107,6 +107,16 @@ loadregs:
  15. REG_L t6, 3*FFI_SIZEOF_ARG($fp) # load the flags word into t6.
  16. +#ifdef __mips_soft_float
  17. + REG_L a0, 0*FFI_SIZEOF_ARG(t9)
  18. + REG_L a1, 1*FFI_SIZEOF_ARG(t9)
  19. + REG_L a2, 2*FFI_SIZEOF_ARG(t9)
  20. + REG_L a3, 3*FFI_SIZEOF_ARG(t9)
  21. + REG_L a4, 4*FFI_SIZEOF_ARG(t9)
  22. + REG_L a5, 5*FFI_SIZEOF_ARG(t9)
  23. + REG_L a6, 6*FFI_SIZEOF_ARG(t9)
  24. + REG_L a7, 7*FFI_SIZEOF_ARG(t9)
  25. +#else
  26. and t4, t6, ((1<<FFI_FLAG_BITS)-1)
  27. REG_L a0, 0*FFI_SIZEOF_ARG(t9)
  28. beqz t4, arg1_next
  29. @@ -193,6 +203,7 @@ arg7_next:
  30. arg8_doublep:
  31. l.d $f19, 7*FFI_SIZEOF_ARG(t9)
  32. arg8_next:
  33. +#endif
  34. callit:
  35. # Load the function pointer
  36. @@ -214,6 +225,7 @@ retint:
  37. b epilogue
  38. retfloat:
  39. +#ifndef __mips_soft_float
  40. bne t6, FFI_TYPE_FLOAT, retdouble
  41. jal t9
  42. REG_L t4, 4*FFI_SIZEOF_ARG($fp)
  43. @@ -272,6 +284,7 @@ retstruct_f_d:
  44. s.s $f0, 0(t4)
  45. s.d $f2, 8(t4)
  46. b epilogue
  47. +#endif
  48. retstruct_d_soft:
  49. bne t6, FFI_TYPE_STRUCT_D_SOFT, retstruct_f_soft
  50. @@ -429,6 +442,7 @@ ffi_closure_N32:
  51. REG_S a6, A6_OFF2($sp)
  52. REG_S a7, A7_OFF2($sp)
  53. +#ifndef __mips_soft_float
  54. # Store all possible float/double registers.
  55. s.d $f12, F12_OFF2($sp)
  56. s.d $f13, F13_OFF2($sp)
  57. @@ -438,6 +452,7 @@ ffi_closure_N32:
  58. s.d $f17, F17_OFF2($sp)
  59. s.d $f18, F18_OFF2($sp)
  60. s.d $f19, F19_OFF2($sp)
  61. +#endif
  62. # Call ffi_closure_mips_inner_N32 to do the real work.
  63. LA t9, ffi_closure_mips_inner_N32
  64. @@ -458,6 +473,7 @@ cls_retint:
  65. b cls_epilogue
  66. cls_retfloat:
  67. +#ifndef __mips_soft_float
  68. bne v0, FFI_TYPE_FLOAT, cls_retdouble
  69. l.s $f0, V0_OFF2($sp)
  70. b cls_epilogue
  71. @@ -500,6 +516,7 @@ cls_retstruct_f_d:
  72. l.s $f0, V0_OFF2($sp)
  73. l.d $f2, V1_OFF2($sp)
  74. b cls_epilogue
  75. +#endif
  76. cls_retstruct_small2:
  77. REG_L v0, V0_OFF2($sp)
  78. --- a/libffi/src/mips/o32.S
  79. +++ b/libffi/src/mips/o32.S
  80. @@ -82,13 +82,16 @@ sixteen:
  81. ADDU $sp, 4 * FFI_SIZEOF_ARG # adjust $sp to new args
  82. +#ifndef __mips_soft_float
  83. bnez t0, pass_d # make it quick for int
  84. +#endif
  85. REG_L a0, 0*FFI_SIZEOF_ARG($sp) # just go ahead and load the
  86. REG_L a1, 1*FFI_SIZEOF_ARG($sp) # four regs.
  87. REG_L a2, 2*FFI_SIZEOF_ARG($sp)
  88. REG_L a3, 3*FFI_SIZEOF_ARG($sp)
  89. b call_it
  90. +#ifndef __mips_soft_float
  91. pass_d:
  92. bne t0, FFI_ARGS_D, pass_f
  93. l.d $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
  94. @@ -130,6 +133,7 @@ pass_f_d:
  95. # bne t0, FFI_ARGS_F_D, call_it
  96. l.s $f12, 0*FFI_SIZEOF_ARG($sp) # load $fp regs from args
  97. l.d $f14, 2*FFI_SIZEOF_ARG($sp) # passing double and float
  98. +#endif
  99. call_it:
  100. # Load the function pointer
  101. @@ -158,14 +162,23 @@ retfloat:
  102. bne t2, FFI_TYPE_FLOAT, retdouble
  103. jalr t9
  104. REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
  105. +#ifndef __mips_soft_float
  106. s.s $f0, 0(t0)
  107. +#else
  108. + REG_S v0, 0(t0)
  109. +#endif
  110. b epilogue
  111. retdouble:
  112. bne t2, FFI_TYPE_DOUBLE, noretval
  113. jalr t9
  114. REG_L t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
  115. +#ifndef __mips_soft_float
  116. s.d $f0, 0(t0)
  117. +#else
  118. + REG_S v1, 4(t0)
  119. + REG_S v0, 0(t0)
  120. +#endif
  121. b epilogue
  122. noretval:
  123. @@ -261,9 +274,11 @@ $LCFI7:
  124. li $13, 1 # FFI_O32
  125. bne $16, $13, 1f # Skip fp save if FFI_O32_SOFT_FLOAT
  126. +#ifndef __mips_soft_float
  127. # Store all possible float/double registers.
  128. s.d $f12, FA_0_0_OFF2($fp)
  129. s.d $f14, FA_1_0_OFF2($fp)
  130. +#endif
  131. 1:
  132. # Call ffi_closure_mips_inner_O32 to do the work.
  133. la t9, ffi_closure_mips_inner_O32
  134. @@ -281,6 +296,7 @@ $LCFI7:
  135. li $13, 1 # FFI_O32
  136. bne $16, $13, 1f # Skip fp restore if FFI_O32_SOFT_FLOAT
  137. +#ifndef __mips_soft_float
  138. li $9, FFI_TYPE_FLOAT
  139. l.s $f0, V0_OFF2($fp)
  140. beq $8, $9, closure_done
  141. @@ -288,6 +304,7 @@ $LCFI7:
  142. li $9, FFI_TYPE_DOUBLE
  143. l.d $f0, V0_OFF2($fp)
  144. beq $8, $9, closure_done
  145. +#endif
  146. 1:
  147. REG_L $3, V1_OFF2($fp)
  148. REG_L $2, V0_OFF2($fp)