restore.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //===-- restore.S - restore up to 12 callee-save registers ----------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Multiple entry points depending on number of registers to restore
  10. //
  11. //===----------------------------------------------------------------------===//
  12. // All of the entry points are in the same section since we rely on many of
  13. // them falling through into each other and don't want the linker to
  14. // accidentally split them up, garbage collect, or reorder them.
  15. //
  16. // The entry points are grouped up into 2s for rv64 and 4s for rv32 since this
  17. // is the minimum grouping which will maintain the required 16-byte stack
  18. // alignment.
  19. .text
  20. #if __riscv_xlen == 32
  21. #ifndef __riscv_abi_rve
  22. .globl __riscv_restore_12
  23. .type __riscv_restore_12,@function
  24. __riscv_restore_12:
  25. lw s11, 12(sp)
  26. addi sp, sp, 16
  27. // fallthrough into __riscv_restore_11/10/9/8
  28. .globl __riscv_restore_11
  29. .type __riscv_restore_11,@function
  30. .globl __riscv_restore_10
  31. .type __riscv_restore_10,@function
  32. .globl __riscv_restore_9
  33. .type __riscv_restore_9,@function
  34. .globl __riscv_restore_8
  35. .type __riscv_restore_8,@function
  36. __riscv_restore_11:
  37. __riscv_restore_10:
  38. __riscv_restore_9:
  39. __riscv_restore_8:
  40. lw s10, 0(sp)
  41. lw s9, 4(sp)
  42. lw s8, 8(sp)
  43. lw s7, 12(sp)
  44. addi sp, sp, 16
  45. // fallthrough into __riscv_restore_7/6/5/4
  46. .globl __riscv_restore_7
  47. .type __riscv_restore_7,@function
  48. .globl __riscv_restore_6
  49. .type __riscv_restore_6,@function
  50. .globl __riscv_restore_5
  51. .type __riscv_restore_5,@function
  52. .globl __riscv_restore_4
  53. .type __riscv_restore_4,@function
  54. __riscv_restore_7:
  55. __riscv_restore_6:
  56. __riscv_restore_5:
  57. __riscv_restore_4:
  58. lw s6, 0(sp)
  59. lw s5, 4(sp)
  60. lw s4, 8(sp)
  61. lw s3, 12(sp)
  62. addi sp, sp, 16
  63. // fallthrough into __riscv_restore_3/2/1/0
  64. .globl __riscv_restore_3
  65. .type __riscv_restore_3,@function
  66. .globl __riscv_restore_2
  67. .type __riscv_restore_2,@function
  68. .globl __riscv_restore_1
  69. .type __riscv_restore_1,@function
  70. .globl __riscv_restore_0
  71. .type __riscv_restore_0,@function
  72. __riscv_restore_3:
  73. __riscv_restore_2:
  74. __riscv_restore_1:
  75. __riscv_restore_0:
  76. lw s2, 0(sp)
  77. lw s1, 4(sp)
  78. lw s0, 8(sp)
  79. lw ra, 12(sp)
  80. addi sp, sp, 16
  81. ret
  82. #else
  83. .globl __riscv_restore_2
  84. .type __riscv_restore_2,@function
  85. .globl __riscv_restore_1
  86. .type __riscv_restore_1,@function
  87. .globl __riscv_restore_0
  88. .type __riscv_restore_0,@function
  89. __riscv_restore_2:
  90. __riscv_restore_1:
  91. __riscv_restore_0:
  92. lw s1, 0(sp)
  93. lw s0, 4(sp)
  94. lw ra, 8(sp)
  95. addi sp, sp, 12
  96. ret
  97. #endif
  98. #elif __riscv_xlen == 64
  99. #ifndef __riscv_abi_rve
  100. .globl __riscv_restore_12
  101. .type __riscv_restore_12,@function
  102. __riscv_restore_12:
  103. ld s11, 8(sp)
  104. addi sp, sp, 16
  105. // fallthrough into __riscv_restore_11/10
  106. .globl __riscv_restore_11
  107. .type __riscv_restore_11,@function
  108. .globl __riscv_restore_10
  109. .type __riscv_restore_10,@function
  110. __riscv_restore_11:
  111. __riscv_restore_10:
  112. ld s10, 0(sp)
  113. ld s9, 8(sp)
  114. addi sp, sp, 16
  115. // fallthrough into __riscv_restore_9/8
  116. .globl __riscv_restore_9
  117. .type __riscv_restore_9,@function
  118. .globl __riscv_restore_8
  119. .type __riscv_restore_8,@function
  120. __riscv_restore_9:
  121. __riscv_restore_8:
  122. ld s8, 0(sp)
  123. ld s7, 8(sp)
  124. addi sp, sp, 16
  125. // fallthrough into __riscv_restore_7/6
  126. .globl __riscv_restore_7
  127. .type __riscv_restore_7,@function
  128. .globl __riscv_restore_6
  129. .type __riscv_restore_6,@function
  130. __riscv_restore_7:
  131. __riscv_restore_6:
  132. ld s6, 0(sp)
  133. ld s5, 8(sp)
  134. addi sp, sp, 16
  135. // fallthrough into __riscv_restore_5/4
  136. .globl __riscv_restore_5
  137. .type __riscv_restore_5,@function
  138. .globl __riscv_restore_4
  139. .type __riscv_restore_4,@function
  140. __riscv_restore_5:
  141. __riscv_restore_4:
  142. ld s4, 0(sp)
  143. ld s3, 8(sp)
  144. addi sp, sp, 16
  145. // fallthrough into __riscv_restore_3/2
  146. .globl __riscv_restore_3
  147. .type __riscv_restore_3,@function
  148. .globl __riscv_restore_2
  149. .type __riscv_restore_2,@function
  150. __riscv_restore_3:
  151. __riscv_restore_2:
  152. ld s2, 0(sp)
  153. ld s1, 8(sp)
  154. addi sp, sp, 16
  155. // fallthrough into __riscv_restore_1/0
  156. .globl __riscv_restore_1
  157. .type __riscv_restore_1,@function
  158. .globl __riscv_restore_0
  159. .type __riscv_restore_0,@function
  160. __riscv_restore_1:
  161. __riscv_restore_0:
  162. ld s0, 0(sp)
  163. ld ra, 8(sp)
  164. addi sp, sp, 16
  165. ret
  166. #else
  167. .globl __riscv_restore_2
  168. .type __riscv_restore_2,@function
  169. .globl __riscv_restore_1
  170. .type __riscv_restore_1,@function
  171. .globl __riscv_restore_0
  172. .type __riscv_restore_0,@function
  173. __riscv_restore_2:
  174. __riscv_restore_1:
  175. __riscv_restore_0:
  176. ld s1, 0(sp)
  177. ld s0, 8(sp)
  178. ld ra, 16(sp)
  179. addi sp, sp, 24
  180. ret
  181. #endif
  182. #else
  183. # error "xlen must be 32 or 64 for save-restore implementation
  184. #endif