save.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //===-- save.S - save up to 12 callee-saved 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 save
  10. //
  11. //===----------------------------------------------------------------------===//
  12. // The entry points are grouped up into 2s for rv64 and 4s for rv32 since this
  13. // is the minimum grouping which will maintain the required 16-byte stack
  14. // alignment.
  15. .text
  16. #if __riscv_xlen == 32
  17. #ifndef __riscv_abi_rve
  18. .globl __riscv_save_12
  19. .type __riscv_save_12,@function
  20. __riscv_save_12:
  21. addi sp, sp, -64
  22. mv t1, zero
  23. sw s11, 12(sp)
  24. j .Lriscv_save_11_8
  25. .globl __riscv_save_11
  26. .type __riscv_save_11,@function
  27. .globl __riscv_save_10
  28. .type __riscv_save_10,@function
  29. .globl __riscv_save_9
  30. .type __riscv_save_9,@function
  31. .globl __riscv_save_8
  32. .type __riscv_save_8,@function
  33. __riscv_save_11:
  34. __riscv_save_10:
  35. __riscv_save_9:
  36. __riscv_save_8:
  37. addi sp, sp, -64
  38. li t1, 16
  39. .Lriscv_save_11_8:
  40. sw s10, 16(sp)
  41. sw s9, 20(sp)
  42. sw s8, 24(sp)
  43. sw s7, 28(sp)
  44. j .Lriscv_save_7_4
  45. .globl __riscv_save_7
  46. .type __riscv_save_7,@function
  47. .globl __riscv_save_6
  48. .type __riscv_save_6,@function
  49. .globl __riscv_save_5
  50. .type __riscv_save_5,@function
  51. .globl __riscv_save_4
  52. .type __riscv_save_4,@function
  53. __riscv_save_7:
  54. __riscv_save_6:
  55. __riscv_save_5:
  56. __riscv_save_4:
  57. addi sp, sp, -64
  58. li t1, 32
  59. .Lriscv_save_7_4:
  60. sw s6, 32(sp)
  61. sw s5, 36(sp)
  62. sw s4, 40(sp)
  63. sw s3, 44(sp)
  64. sw s2, 48(sp)
  65. sw s1, 52(sp)
  66. sw s0, 56(sp)
  67. sw ra, 60(sp)
  68. add sp, sp, t1
  69. jr t0
  70. .globl __riscv_save_3
  71. .type __riscv_save_3,@function
  72. .globl __riscv_save_2
  73. .type __riscv_save_2,@function
  74. .globl __riscv_save_1
  75. .type __riscv_save_1,@function
  76. .globl __riscv_save_0
  77. .type __riscv_save_0,@function
  78. __riscv_save_3:
  79. __riscv_save_2:
  80. __riscv_save_1:
  81. __riscv_save_0:
  82. addi sp, sp, -16
  83. sw s2, 0(sp)
  84. sw s1, 4(sp)
  85. sw s0, 8(sp)
  86. sw ra, 12(sp)
  87. jr t0
  88. #else
  89. .globl __riscv_save_2
  90. .type __riscv_save_2,@function
  91. .globl __riscv_save_1
  92. .type __riscv_save_1,@function
  93. .globl __riscv_save_0
  94. .type __riscv_save_0,@function
  95. __riscv_save_2:
  96. __riscv_save_1:
  97. __riscv_save_0:
  98. addi sp, sp, -12
  99. sw s1, 0(sp)
  100. sw s0, 4(sp)
  101. sw ra, 8(sp)
  102. jr t0
  103. #endif
  104. #elif __riscv_xlen == 64
  105. #ifndef __riscv_abi_rve
  106. .globl __riscv_save_12
  107. .type __riscv_save_12,@function
  108. __riscv_save_12:
  109. addi sp, sp, -112
  110. mv t1, zero
  111. sd s11, 8(sp)
  112. j .Lriscv_save_11_10
  113. .globl __riscv_save_11
  114. .type __riscv_save_11,@function
  115. .globl __riscv_save_10
  116. .type __riscv_save_10,@function
  117. __riscv_save_11:
  118. __riscv_save_10:
  119. addi sp, sp, -112
  120. li t1, 16
  121. .Lriscv_save_11_10:
  122. sd s10, 16(sp)
  123. sd s9, 24(sp)
  124. j .Lriscv_save_9_8
  125. .globl __riscv_save_9
  126. .type __riscv_save_9,@function
  127. .globl __riscv_save_8
  128. .type __riscv_save_8,@function
  129. __riscv_save_9:
  130. __riscv_save_8:
  131. addi sp, sp, -112
  132. li t1, 32
  133. .Lriscv_save_9_8:
  134. sd s8, 32(sp)
  135. sd s7, 40(sp)
  136. j .Lriscv_save_7_6
  137. .globl __riscv_save_7
  138. .type __riscv_save_7,@function
  139. .globl __riscv_save_6
  140. .type __riscv_save_6,@function
  141. __riscv_save_7:
  142. __riscv_save_6:
  143. addi sp, sp, -112
  144. li t1, 48
  145. .Lriscv_save_7_6:
  146. sd s6, 48(sp)
  147. sd s5, 56(sp)
  148. j .Lriscv_save_5_4
  149. .globl __riscv_save_5
  150. .type __riscv_save_5,@function
  151. .globl __riscv_save_4
  152. .type __riscv_save_4,@function
  153. __riscv_save_5:
  154. __riscv_save_4:
  155. addi sp, sp, -112
  156. li t1, 64
  157. .Lriscv_save_5_4:
  158. sd s4, 64(sp)
  159. sd s3, 72(sp)
  160. j .Lriscv_save_3_2
  161. .globl __riscv_save_3
  162. .type __riscv_save_3,@function
  163. .globl __riscv_save_2
  164. .type __riscv_save_2,@function
  165. __riscv_save_3:
  166. __riscv_save_2:
  167. addi sp, sp, -112
  168. li t1, 80
  169. .Lriscv_save_3_2:
  170. sd s2, 80(sp)
  171. sd s1, 88(sp)
  172. sd s0, 96(sp)
  173. sd ra, 104(sp)
  174. add sp, sp, t1
  175. jr t0
  176. .globl __riscv_save_1
  177. .type __riscv_save_1,@function
  178. .globl __riscv_save_0
  179. .type __riscv_save_0,@function
  180. __riscv_save_1:
  181. __riscv_save_0:
  182. addi sp, sp, -16
  183. sd s0, 0(sp)
  184. sd ra, 8(sp)
  185. jr t0
  186. #else
  187. .globl __riscv_save_2
  188. .type __riscv_save_2,@function
  189. .globl __riscv_save_1
  190. .type __riscv_save_1,@function
  191. .globl __riscv_save_0
  192. .type __riscv_save_0,@function
  193. __riscv_save_2:
  194. __riscv_save_1:
  195. __riscv_save_0:
  196. addi sp, sp, -24
  197. sd s1, 0(sp)
  198. sd s0, 8(sp)
  199. sd ra, 16(sp)
  200. jr t0
  201. #endif
  202. #else
  203. # error "xlen must be 32 or 64 for save-restore implementation
  204. #endif