1
0

931-fix-MIPS-softfloat-build-issue.patch 4.1 KB

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